Get ready for your next interview with our comprehensive question library
There are several methods to include Bootstrap:
CDN (Content Delivery Network):
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
Package Managers:
npm install bootstrapyarn add bootstrapDownload and Host Locally: Download compiled CSS and JS files from the official website
Source Files: Download Sass source files for custom builds
Bootstrap provides three main container classes:
.container: Fixed-width container with responsive breakpoints
.container-fluid: Full-width container
.container-{breakpoint} (Bootstrap 4+): Responsive containers
.container-sm, .container-md, .container-lg, .container-xl, .container-xxl.containerThe Bootstrap grid system is a flexbox-based layout system that uses containers, rows, and columns to create responsive layouts.
Key concepts:
Basic structure:
<div class="container">
<div class="row">
<div class="col-md-6">Column 1</div>
<div class="col-md-6">Column 2</div>
</div>
</div>
Use column classes with breakpoint prefixes to create responsive layouts:
<div class="row">
<div class="col-12 col-sm-6 col-md-4 col-lg-3">
<!-- 100% on xs, 50% on sm, 33.33% on md, 25% on lg and xl -->
</div>
</div>
Column behavior:
Bootstrap provides several ways to create equal-width columns:
Basic equal columns:
<div class="row">
<div class="col">Column 1</div>
<div class="col">Column 2</div>
<div class="col">Column 3</div>
</div>
Equal columns with breakpoints:
<div class="row">
<div class="col-md">Column 1</div>
<div class="col-md">Column 2</div>
</div>
Equal-width multi-row:
<div class="row">
<div class="col">Column</div>
<div class="w-100"></div> <!-- Force next columns to new line -->
<div class="col">Column</div>
</div>
Bootstrap provides various button styles and states:
Basic button types:
<button class="btn btn-primary">Primary</button>
<button class="btn btn-secondary">Secondary</button>
<button class="btn btn-success">Success</button>
<button class="btn btn-danger">Danger</button>
<button class="btn btn-warning">Warning</button>
<button class="btn btn-info">Info</button>
<button class="btn btn-light">Light</button>
<button class="btn btn-dark">Dark</button>
Button variants:
btn-outline-primarybtn-sm, btn-lgd-grid wrapper or w-100 classactive, disabledBootstrap provides table classes for styling and responsive behavior:
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="table-dark">
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John Doe</td>
<td>john@example.com</td>
</tr>
</tbody>
</table>
</div>
Table classes:
table-striped: Alternate row colorstable-hover: Hover effect on rowstable-bordered: Add borderstable-responsive: Horizontal scrolling on small screenstable-{color}: Contextual background colorsDropdowns are toggleable overlays for displaying lists of links:
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
Dropdown button
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
</div>
Dropdown variations:
dropup, dropend, dropstart: Direction modifiersdropdown-menu-end: Right-aligned menudropdown-item-text: Non-interactive textdropdown-header: Section headersAlerts provide contextual feedback messages:
<!-- Basic alert -->
<div class="alert alert-warning" role="alert">
This is a warning alert!
</div>
<!-- Dismissible alert -->
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Error!</strong> Something went wrong.
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<!-- Alert with additional content -->
<div class="alert alert-success" role="alert">
<h4 class="alert-heading">Well done!</h4>
<p class="mb-0">Success message with <a href="#" class="alert-link">a link</a>.</p>
</div>
Alert types: alert-primary, alert-secondary, alert-success, alert-danger, alert-warning, alert-info, alert-light, alert-dark.
Bootstrap provides text and background color utilities based on the theme colors:
<!-- Text colors -->
<p class="text-primary">Primary text</p>
<p class="text-success">Success text</p>
<p class="text-danger">Danger text</p>
<p class="text-muted">Muted text</p>
<!-- Background colors -->
<div class="bg-primary text-white">Primary background</div>
<div class="bg-light text-dark">Light background</div>
<!-- Contextual colors -->
<span class="badge bg-warning text-dark">Warning badge</span>
Available colors: primary, secondary, success, danger, warning, info, light, dark, body, muted, white, black-50, white-50.
Border utilities provide control over element borders:
<!-- Add borders -->
<div class="border">All borders</div>
<div class="border-top border-start">Top and left borders</div>
<!-- Remove borders -->
<div class="border border-top-0">All except top border</div>
<!-- Border colors -->
<div class="border border-primary">Primary border color</div>
<!-- Border radius -->
<div class="rounded">Rounded corners</div>
<div class="rounded-circle">Circular border</div>
<div class="rounded-pill">Pill-shaped border</div>
Border sides: border-top, border-end, border-bottom, border-start.
Border radius: rounded-top, rounded-end, rounded-bottom, rounded-start, rounded-circle, rounded-pill.
Text utilities control text styling, alignment, and behavior:
<!-- Text alignment -->
<p class="text-start">Left aligned text</p>
<p class="text-center">Center aligned text</p>
<p class="text-end">Right aligned text</p>
<!-- Text transformation -->
<p class="text-lowercase">LOWERCASE TEXT</p>
<p class="text-uppercase">uppercase text</p>
<p class="text-capitalize">capitalize each word</p>
<!-- Font weight and style -->
<p class="fw-bold">Bold text</p>
<p class="fw-normal">Normal weight</p>
<p class="fst-italic">Italic text</p>
<!-- Text decoration -->
<p class="text-decoration-underline">Underlined text</p>
<p class="text-decoration-none">No decoration</p>
Bootstrap provides classes for responsive image behavior:
<!-- Responsive image that scales with parent width -->
<img src="image.jpg" class="img-responsive" alt="Responsive image">
<!-- Bootstrap 4+ uses img-fluid -->
<img src="image.jpg" class="img-fluid" alt="Responsive image">
<!-- Image shapes -->
<img src="image.jpg" class="img-thumbnail" alt="Thumbnail">
<img src="image.jpg" class="rounded" alt="Rounded corners">
<img src="image.jpg" class="rounded-circle" alt="Circular image">
<!-- Figure with caption -->
<figure class="figure">
<img src="image.jpg" class="figure-img img-fluid rounded" alt="Figure">
<figcaption class="figure-caption">Image caption</figcaption>
</figure>
The img-fluid class applies max-width: 100% and height: auto for responsive scaling.
These are the three main container types in Bootstrap:
.container:
.container-fluid:
.container-{breakpoint}:
.container with fixed max-width.container-sm, .container-md, .container-lg, .container-xl, .container-xxl<div class="container">Fixed-width responsive container</div>
<div class="container-fluid">Full-width container</div>
<div class="container-md">Fluid until medium breakpoint, then fixed</div>
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess all premium content - interview questions, and other learning resources
We regularly update our features and content, to ensure you get the most relevant and updated premium content.
1000 monthly credits
Cancel anytime