Complete guide from beginner to advanced. Learn to build responsive, beautiful websites with Bootstrap 5.
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/
bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet">
<div class="container">
<div class="row">
<div class="col-md-6">
<h1>Hello Bootstrap!</h1>
<button class="btn btn-primary">
Click Me
</button>
</div>
</div>
</div>
The world's most popular front-end framework
Bootstrap is a free, open-source front-end framework for creating websites and web applications. It contains HTML- and CSS-based design templates for typography, forms, buttons, navigation, and other interface components.
Bootstrap makes front-end web development faster and easier. It's made for folks of all skill levels, devices of all shapes, and projects of all sizes.
Bootstrap Key Features:
1. Responsive Grid System
- 12-column grid
- Flexbox support
- Responsive breakpoints
2. Pre-built Components
- Navigation bars
- Cards, modals, carousels
- Forms, buttons, alerts
3. Utilities
- Spacing, colors, typography
- Flexbox, positioning
- Borders, shadows
4. JavaScript Plugins
- Interactive components
- No jQuery dependency
- Vanilla JS implementation
5. Customization
- Sass variables
- Modular imports
- Build tools support
Bootstrap Advantages:
✓ Time-Saving
- Pre-built components
- Rapid prototyping
- Less CSS writing
✓ Consistency
- Unified design language
- Professional appearance
- Brand consistency
✓ Responsive
- Mobile-first approach
- Flexible grid system
- Breakpoint control
✓ Cross-browser
- Works on all browsers
- No vendor prefixes needed
- Tested compatibility
✓ Community
- Large user base
- Extensive documentation
- Third-party resources
✓ Customizable
- Sass variables
- Modular structure
- Theme support
Mobile Ready
Beautiful UI
Customizable
Bootstrap Use Cases:
🌐 Websites
- Corporate sites
- Portfolio websites
- Landing pages
- Blogs
🛒 E-commerce
- Product pages
- Shopping carts
- Checkout flows
- Admin dashboards
📱 Web Applications
- SaaS platforms
- Admin panels
- Dashboards
- Analytics tools
🎨 Prototypes
- Quick mockups
- MVP development
- Design systems
- Component libraries
📧 Email Templates
- Responsive emails
- Marketing campaigns
- Newsletters
🔧 Admin Templates
- Backend interfaces
- Control panels
- Management systems
Multiple ways to include Bootstrap in your project
Quickest way to get started - just add links to your HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap CDN</title>
<!-- Bootstrap CSS CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css"
rel="stylesheet">
<!-- Bootstrap Icons CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
</head>
<body>
<div class="container">
<h1>Hello, Bootstrap!</h1>
<button class="btn btn-primary">Click Me</button>
</div>
<!-- Bootstrap JS Bundle CDN -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Download compiled CSS and JS files for offline use
Project Structure:
my-project/
├── css/
│ ├── bootstrap.min.css
│ └── bootstrap.min.css.map
├── js/
│ ├── bootstrap.bundle.min.js
│ └── bootstrap.bundle.min.js.map
└── index.html
HTML Usage:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap Local</title>
<!-- Local Bootstrap CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>Local Bootstrap</h1>
</div>
<!-- Local Bootstrap JS -->
<script src="js/bootstrap.bundle.min.js"></script>
</body>
</html>
Install Bootstrap using npm, yarn, or other package managers
# Install Bootstrap via npm
npm install bootstrap@5.3.0
# Install Bootstrap via yarn
yarn add bootstrap@5.3.0
# Install Bootstrap via Composer
composer require twbs/bootstrap:5.3.0
# Project Structure after npm install:
node_modules/
└── bootstrap/
├── dist/
│ ├── css/
│ └── js/
├── scss/
└── js/
# Import in your SCSS file:
@import "../node_modules/bootstrap/scss/bootstrap";
# Import in your JavaScript file:
import 'bootstrap';
# Or import specific components:
import { Tooltip, Toast, Popover } from 'bootstrap';
Easy version management
Simple update process
Download source files for customization with Sass
// Custom Bootstrap Build
// Import required Bootstrap files
// 1. Functions
@import "bootstrap/functions";
// 2. Variables (override default variables)
$primary: #667eea;
$secondary: #764ba2;
$success: #84fab0;
$info: #30cfd0;
$warning: #fee140;
$danger: #f5576c;
// 3. Maps
@import "bootstrap/variables";
@import "bootstrap/variables-dark";
// 4. Mixins
@import "bootstrap/mixins";
// 5. Utilities
@import "bootstrap/utilities";
// 6. Components (import only what you need)
@import "bootstrap/root";
@import "bootstrap/reboot";
@import "bootstrap/type";
@import "bootstrap/images";
@import "bootstrap/containers";
@import "bootstrap/grid";
@import "bootstrap/buttons";
@import "bootstrap/card";
// Compile with Sass:
// sass --watch input.scss output.css
Personalize Bootstrap with custom colors, fonts, and styles
Override Bootstrap's default color scheme
// _custom-variables.scss
// Override default theme colors
$primary: #667eea;
$secondary: #764ba2;
$success: #84fab0;
$info: #30cfd0;
$warning: #fee140;
$danger: #f5576c;
$light: #f8f9fa;
$dark: #0f0f23;
// Create custom colors
$custom-colors: (
"purple": #6f42c1,
"indigo": #6610f2,
"pink": #d63384,
"teal": #20c997,
"orange": #fd7e14
);
// Merge with default theme colors
$theme-colors: map-merge($theme-colors, $custom-colors);
// Override gradient colors
$gradient: linear-gradient(180deg, rgba($primary, .15), rgba($primary, 0));
// Import Bootstrap
@import "bootstrap/scss/bootstrap";
Customize typography and fonts
// Font Customization
// Import Google Fonts
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
// Font family
$font-family-sans-serif: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
$font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
// Font sizes
$font-size-base: 1rem;
$font-sizes: (
1: $font-size-base * 2.5,
2: $font-size-base * 2,
3: $font-size-base * 1.75,
4: $font-size-base * 1.5,
5: $font-size-base * 1.25,
6: $font-size-base
);
// Font weights
$font-weight-lighter: lighter;
$font-weight-light: 300;
$font-weight-normal: 400;
$font-weight-medium: 500;
$font-weight-semibold: 600;
$font-weight-bold: 700;
$font-weight-bolder: bolder;
// Line heights
$line-height-base: 1.5;
$line-height-sm: 1.25;
$line-height-lg: 2;
// Import Bootstrap after customization
@import "bootstrap/scss/bootstrap";
Paragraph with custom font family and improved readability.
Customize individual Bootstrap components
// Component Customization
// Buttons
$btn-padding-y: .75rem;
$btn-padding-x: 1.5rem;
$btn-font-weight: 500;
$btn-border-radius: 50px;
$btn-border-width: 2px;
// Custom button styles
.btn-gradient {
background: linear-gradient(135deg, $primary 0%, $secondary 100%);
border: none;
color: white;
font-weight: 600;
padding: $btn-padding-y $btn-padding-x;
border-radius: $btn-border-radius;
transition: all 0.3s ease;
&:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px rgba($primary, 0.3);
}
}
// Cards
$card-spacer-y: 1.5rem;
$card-spacer-x: 1.5rem;
$card-border-radius: 1rem;
$card-box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
.card-hover {
transition: all 0.3s ease;
&:hover {
transform: translateY(-10px);
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}
}
// Modals
$modal-content-border-radius: 1rem;
$modal-header-border-width: 0;
$modal-footer-border-width: 0;
Hover over me to see the effect
Implement dark mode with Bootstrap
// Dark Mode Variables
$body-bg: $dark;
$body-color: $gray-100;
// Dark mode colors
$dark-colors: (
"primary": #667eea,
"secondary": #764ba2,
"success": #84fab0,
"info": #30cfd0,
"warning": #fee140,
"danger": #f5576c,
"light": #212529,
"dark": #ffffff
);
// Dark mode component overrides
[data-bs-theme="dark"] {
.card {
background-color: $gray-800;
border-color: $gray-700;
}
.btn-light {
background-color: $gray-700;
border-color: $gray-600;
color: $white;
}
.form-control {
background-color: $gray-700;
border-color: $gray-600;
color: $white;
&:focus {
background-color: $gray-600;
border-color: $primary;
color: $white;
}
}
}
// Theme toggle functionality
.theme-toggle {
position: fixed;
top: 20px;
right: 20px;
z-index: 1000;
}
This card will change in dark mode
Learn to use Bootstrap's extensive component library
Bootstrap's powerful 12-column grid system
<!-- Equal Width Columns -->
<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>
<!-- Column Widths -->
<div class="container">
<div class="row">
<div class="col-4">
Column with width 4
</div>
<div class="col-8">
Column with width 8
</div>
</div>
</div>
<!-- Variable Width Content -->
<div class="container">
<div class="row justify-content-md-center">
<div class="col col-lg-2">
1 of 3
</div>
<div class="col-md-auto">
Variable width content
</div>
<div class="col col-lg-2">
3 of 3
</div>
</div>
</div>
Build responsive layouts with breakpoint-specific columns
<!-- Responsive Grid -->
<div class="container">
<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
<div class="col-12 col-md-8">.col-12 .col-md-8</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<div class="row">
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
<div class="col-6 col-md-4">.col-6 .col-md-4</div>
</div>
<!-- Columns are always 50% wide, on mobile and desktop -->
<div class="row">
<div class="col-6">.col-6</div>
<div class="col-6">.col-6</div>
</div>
</div>
<!-- Breakpoints: -->
<!-- xs: <576px -->
<!-- sm: ≥576px -->
<!-- md: ≥768px -->
<!-- lg: ≥992px -->
<!-- xl: ≥1200px -->
<!-- xxl: ≥1400px -->
Control column positioning and alignment
<!-- Offset Columns -->
<div class="container">
<div class="row">
<div class="col-md-4">.col-md-4</div>
<div class="col-md-4 offset-md-4">.col-md-4 .offset-md-4</div>
</div>
<div class="row">
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
<div class="col-md-3 offset-md-3">.col-md-3 .offset-md-3</div>
</div>
</div>
<!-- Row Alignment -->
<div class="container">
<!-- Vertical Alignment -->
<div class="row align-items-start">
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
<div class="col">
One of three columns
</div>
</div>
<!-- Horizontal Alignment -->
<div class="row justify-content-center">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
</div>
Nest grids and control column order
<!-- Nested Grids -->
<div class="container">
<div class="row">
<div class="col-sm-9">
Level 1: .col-sm-9
<div class="row">
<div class="col-8 col-sm-6">
Level 2: .col-8 .col-sm-6
</div>
<div class="col-4 col-sm-6">
Level 2: .col-4 .col-sm-6
</div>
</div>
</div>
</div>
</div>
<!-- Column Ordering -->
<div class="container">
<div class="row">
<div class="col">
First in DOM, no order applied
</div>
<div class="col order-5">
Second in DOM, with a larger order
</div>
<div class="col order-1">
Third in DOM, with an order of 1
</div>
</div>
</div>
<!-- Responsive Ordering -->
<div class="container">
<div class="row">
<div class="col order-last order-md-first">
First, but last on medium and up
</div>
<div class="col">
Second, but unchanged
</div>
<div class="col order-first order-md-last">
Third, but first on medium and up
</div>
</div>
</div>
Flexible and extensible content container
<!-- Basic Card -->
<div class="card" style="width: 18rem;">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
<!-- Card with List Group -->
<div class="card" style="width: 18rem;">
<div class="card-header">Featured</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">An item</li>
<li class="list-group-item">A second item</li>
<li class="list-group-item">A third item</li>
</ul>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins ago</small>
</div>
</div>
<!-- Card with Header and Footer -->
<div class="card">
<div class="card-header">
Quote
</div>
<div class="card-body">
<blockquote class="blockquote mb-0">
<p>A well-known quote, contained in a blockquote element.</p>
<footer class="blockquote-footer">Someone famous in <cite title="Source Title">Source Title</cite></footer>
</blockquote>
</div>
</div>
Various card layout options
<!-- Grid Cards -->
<div class="row">
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card">
<div class="card-body">
<h5 class="card-title">Special title treatment</h5>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
</div>
<!-- Horizontal Card -->
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4">
<img src="..." class="img-fluid rounded-start" alt="...">
</div>
<div class="col-md-8">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
Group cards together with equal height and width
<!-- Card Group -->
<div class="card-group">
<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">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</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">This card has supporting text below as a natural lead-in to additional content.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</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">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
This is a wider card with supporting text.
Last updated 3 mins ago
This card has supporting text below.
Last updated 3 mins ago
Cards with hover effects and interactions
<!-- Hover Card -->
<div class="card hover-lift">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Hover Card</h5>
<p class="card-text">Hover over this card to see the lift effect.</p>
<a href="#" class="btn btn-primary">Learn More</a>
</div>
</div>
<!-- Card with Overlay -->
<div class="card bg-dark text-white">
<img src="..." class="card-img" alt="...">
<div class="card-img-overlay">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<a href="#" class="btn btn-primary">Learn More</a>
</div>
</div>
<!-- Custom Styles -->
<style>
.hover-lift {
transition: all 0.3s ease;
}
.hover-lift:hover {
transform: translateY(-10px);
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}
</style>
Slideshow component for cycling through elements
<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 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>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Carousel example featuring indicators and control buttons for navigation.
<div id="carouselWithControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselWithControls" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselWithControls" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselWithControls" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="Slide 1">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="Slide 2">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="Slide 3">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselWithControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselWithControls" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Carousel example featuring captions that overlay each slide with text descriptions.
<div id="carouselWithCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselWithCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselWithCaptions" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselWithCaptions" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="Slide 1">
<div class="carousel-caption d-none d-md-block">
<h5>First Slide Label</h5>
<p>Some representative placeholder content for the first slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="Slide 2">
<div class="carousel-caption d-none d-md-block">
<h5>Second Slide Label</h5>
<p>Some representative placeholder content for the second slide.</p>
</div>
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="Slide 3">
<div class="carousel-caption d-none d-md-block">
<h5>Third Slide Label</h5>
<p>Some representative placeholder content for the third slide.</p>
</div>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselWithCaptions" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselWithCaptions" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Example showing two independent carousels functioning separately on the same page.
<!-- First Carousel -->
<div id="carouselOne" class="carousel slide mb-4" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="Slide 1">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="Slide 2">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselOne" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselOne" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<!-- Second Carousel -->
<div id="carouselTwo" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="..." class="d-block w-100" alt="Slide 1">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="Slide 2">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselTwo" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselTwo" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
Modals are streamlined, but flexible dialog prompts
<!-- 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" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</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>
Example modal containing a simple form layout for user input.
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#formModal">
Launch Form Modal
</button>
<!-- Modal with Form -->
<div class="modal fade" id="formModal" tabindex="-1" aria-labelledby="formModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="formModalLabel">Sign Up Form</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form>
<div class="modal-body">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" placeholder="Enter your name">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" placeholder="Enter your email">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" placeholder="Enter your password">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
Different modal sizes using Bootstrap’s .modal-sm, .modal-lg, and
.modal-xl classes.
<!-- Small Modal -->
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#smallModal">
Small Modal
</button>
<div class="modal fade" id="smallModal" tabindex="-1" aria-labelledby="smallModalLabel" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="smallModalLabel">Small Modal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
This is a small modal.
</div>
</div>
</div>
</div>
<!-- Large Modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#largeModal">
Large Modal
</button>
<div class="modal fade" id="largeModal" tabindex="-1" aria-labelledby="largeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="largeModalLabel">Large Modal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
This is a large modal with more space for content.
</div>
</div>
</div>
</div>
<!-- Extra Large Modal -->
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#extraLargeModal">
Extra Large Modal
</button>
<div class="modal fade" id="extraLargeModal" tabindex="-1" aria-labelledby="extraLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="extraLargeModalLabel">Extra Large Modal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
This is an extra-large modal for displaying wide content.
</div>
</div>
</div>
</div>
A modal that does not close when clicking outside or pressing the Esc key.
<!-- Button trigger modal -->
<button type="button" class="btn btn-warning" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
Launch static backdrop modal
</button>
<!-- Modal with Static Backdrop -->
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="staticBackdropLabel">Static Backdrop Modal</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
You cannot close this modal by clicking outside or pressing ESC.
</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">Understood</button>
</div>
</div>
</div>
</div>
Add animations to Bootstrap components
<!-- Include Animate.css --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/> <!-- Animated Elements --> <h1 class="animate__animated animate__bounce">An animated element</h1> <div class="card animate__animated animate__fadeInUp"> Card content </div> <button class="btn btn-primary animate__animated animate__pulse animate__infinite"> Pulsing Button </button> <!-- JavaScript for dynamic animations --> <script> const element = document.querySelector('.my-element'); element.classList.add('animate__animated', 'animate__bounceOutLeft'); element.addEventListener('animationend', () => { // do something after animation ends }); </script>
This card fades in from below.
Use Bootstrap’s transition utilities to add smooth interactive effects to components.
<!-- Bootstrap Transition Example -->
<div class="transition p-3 bg-light border rounded" id="fadeBox">
Hover to see transition effect
</div>
<style>
.transition {
transition: all 0.4s ease-in-out;
}
.transition:hover {
background-color: #0d6efd;
color: #fff;
transform: scale(1.05);
}
</style>
Use Bootstrap’s scrollspy and fade utilities to animate sections as you scroll through content.
<!-- Bootstrap Scroll Animation (Fade In) -->
<div data-bs-spy="scroll" data-bs-target="#scrollspy" data-bs-offset="0" tabindex="0" class="scroll-container border rounded p-3" style="height: 200px; overflow-y: scroll;">
<div class="fade show p-3 mb-3 bg-light border">Section 1</div>
<div class="fade show p-3 mb-3 bg-light border">Section 2</div>
<div class="fade show p-3 mb-3 bg-light border">Section 3</div>
<div class="fade show p-3 mb-3 bg-light border">Section 4</div>
</div>
<!-- Script to toggle fade effect when scrolling -->
<script>
document.querySelector('.scroll-container').addEventListener('scroll', e => {
document.querySelectorAll('.fade').forEach(el => {
const rect = el.getBoundingClientRect();
if (rect.top < window.innerHeight - 50) {
el.classList.add('show');
} else {
el.classList.remove('show');
}
});
});
</script>
Use Bootstrap spinners to indicate loading states in your interface.
<!-- Bootstrap Spinners -->
<div class="d-flex justify-content-center align-items-center gap-3">
<div class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-grow text-success" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div class="spinner-border text-danger" style="width: 2rem; height: 2rem;" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<!-- Buttons with Spinners -->
<button class="btn btn-primary mt-3" type="button" disabled>
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
Loading...
</button>
<button class="btn btn-success mt-3" type="button" disabled>
<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
Processing
</button>
Quick reference for Bootstrap classes and utilities
| Breakpoint | Class infix | Dimensions |
|---|---|---|
| Extra small | none |
<576px |
| Small | sm |
≥576px |
| Medium | md |
≥768px |
| Large | lg |
≥992px |
| Extra large | xl |
≥1200px |
| Extra extra large | xxl |
≥1400px |