Master Bootstrap - the most popular CSS framework for building responsive, mobile-first websites
Bootstrap is a free and open-source CSS framework directed at responsive, mobile-first front-end web development. It contains CSS and JavaScript design templates for typography, forms, buttons, navigation, and other interface components.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Example</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1 class="text-primary">Hello, Bootstrap!</h1>
<button class="btn btn-success">Click Me</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Include Bootstrap in your project via CDN or download the files:
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- JavaScript Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
Bootstrap's grid system uses a series of containers, rows, and columns to layout and align content. It's built with flexbox and is fully responsive.
<div class="container">
<div class="row">
<div class="col">Column 1</div>
<div class="col">Column 2</div>
<div class="col">Column 3</div>
</div>
</div>
Bootstrap's grid includes six tiers of predefined classes for building complex responsive layouts.
Breakpoint | Class Prefix | Dimensions |
---|---|---|
Extra small | .col- |
<576px |
Small | .col-sm- |
≥576px |
Medium | .col-md- |
≥768px |
Large | .col-lg- |
≥992px |
Extra large | .col-xl- |
≥1200px |
Extra extra large | .col-xxl- |
≥1400px |
Bootstrap comes with nearly two dozen components that are ready to use right out of the box.
<div class="alert alert-primary" role="alert">Primary alert</div>
<div class="alert alert-success" role="alert">Success alert</div>
<span class="badge bg-primary">Primary</span>
<span class="badge bg-secondary">Secondary</span>
<span class="badge bg-success">Success</span>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a href="#">Library</a></li>
<li class="breadcrumb-item active" aria-current="page">Data</li>
</ol>
</nav>
Bootstrap includes dozens of utilities—classes with a single purpose to reduce the frequency of highly repetitive declarations.
Utility | Example | Description |
---|---|---|
Spacing | .mt-3 , .px-4 |
Margin and padding utilities |
Text | .text-center , .fw-bold |
Text alignment and styling |
Colors | .bg-primary , .text-danger |
Background and text colors |
Display | .d-none , .d-md-block |
Display property utilities |
Flex | .d-flex , .justify-content-between |
Flexbox utilities |
Position | .position-relative , .fixed-top |
Positioning utilities |
<!-- Margin top 3 -->
<div class="mt-3">Content</div>
<!-- Padding x-axis 4 -->
<div class="px-4">Content</div>
<!-- Margin bottom 5 -->
<div class="mb-5">Content</div>
Bootstrap sets basic global display, typography, and link styles.
This is a lead paragraph. It stands out from regular paragraphs.
Regular paragraph with highlighted text and small text.
<h1>h1. Bootstrap heading</h1>
<h2>h2. Bootstrap heading</h2>
<p class="lead">This is a lead paragraph.</p>
<p>Regular paragraph with <mark>highlighted</mark> text.</p>
Start aligned text
Center aligned text
End aligned text
Uppercase text
Lowercase text
capitalized text
Bold text
Italic text
<p class="text-center">Center aligned text</p>
<p class="text-uppercase">Uppercase text</p>
<p class="fw-bold">Bold text</p>
Bootstrap provides several form control styles, layout options, and custom components for creating a wide variety of forms.
<form>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<input type="text" class="form-control" placeholder="Text input">
<textarea class="form-control" placeholder="Textarea"></textarea>
<select class="form-select">
<option selected>Open this select menu</option>
<option value="1">One</option>
</select>
A card is a flexible and extensible content container. It includes options for headers and footers, a wide variety of content, contextual background colors, and powerful display options.
Some quick example text to build on the card title and make up the bulk of the card's content.
Go somewhere<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
<div class="card">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some text.</p>
</div>
</div>
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
Modal body text
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
A slideshow component for cycling through elements—images or slides of text—like a carousel.
<div id="carouselExample" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExample" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
</button>
</div>
Bootstrap Icons is an open source SVG icon library featuring over 1,800 glyphs, with more added every release.
<i class="bi bi-alarm"></i>
<i class="bi bi-arrow-right-circle-fill"></i>
<i class="bi bi-bell"></i>
<!-- Include Bootstrap Icons CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
Bootstrap can be customized to fit your design needs. Here are the main approaches:
/* Override primary color */
.btn-primary {
background-color: #ff5722;
border-color: #ff5722;
}
/* Custom navbar */
.navbar-custom {
background-color: #6200ea;
}
Create a custom.scss file to modify Bootstrap's source Sass variables:
// Custom.scss
// Option A: Include all of Bootstrap
// Override default variables
$primary: #00ff88;
$enable-shadows: true;
// Include all Bootstrap
@import "../node_modules/bootstrap/scss/bootstrap";
Bootstrap 5 includes many CSS variables that can be overridden:
:root {
--bs-primary: #00ff88;
--bs-body-font-family: 'Inter', sans-serif;
}