What Is Bootstrap?
What Is Bootstrap?
What Is Bootstrap?
Bootstrap 5 Example
<div class="container-fluid p-5 bg-primary text-white text-center">
<h1>My First Bootstrap Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>
<div class="container mt-5">
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris...</p>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris...</p>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris...</p>
</div>
</div>
</div>
Why Use Bootstrap?
Advantages of Bootstrap:
Easy to use: Anybody with just basic knowledge of HTML and CSS can
start using Bootstrap
Responsive features: Bootstrap's responsive CSS adjusts to phones,
tablets, and desktops
Mobile-first approach: In Bootstrap, mobile-first styles are part of the
core framework
Browser compatibility: Bootstrap 5 is compatible with all modern
browsers (Chrome, Firefox, Edge, Safari, and Opera). Note that if you
need support for IE11 and down, you must use either BS4 or BS3.
Bootstrap 5 CDN
If you don't want to download and host Bootstrap 5 yourself, you can include it
from a CDN (Content Delivery Network).
MaxCDN:
<!-- Latest compiled and minified CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstra
p.min.css" rel="stylesheet">
JavaScript?
Bootstrap 5 uses JavaScript for different components (like modals, tooltips,
popovers etc). However, if you just use the CSS part of Bootstrap, you don't
need them.
Create Your First Web Page With Bootstrap
1. Add the HTML5 doctype
Bootstrap 5 uses HTML elements and CSS properties that require the HTML5
doctype.
Always include the HTML5 doctype at the beginning of the page, along with the
lang attribute and the correct title and character set:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 5 Example</title>
<meta charset="utf-8">
</head>
</html>
2. Bootstrap 5 is mobile-first
The width=device-width part sets the width of the page to follow the screen-width
of the device (which will vary depending on the device). The initial-scale=1 part
sets the initial zoom level when the page is first loaded by the browser.
3. Containers
Bootstrap 5 also requires a containing element to wrap site contents. There are
two container classes to choose from:
.container
.container-fluid
Container Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootst
rap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootst
rap.bundle.min.js"></script>
</head>
<body>
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This part is inside a .container class.</p>
<p>The .container class provides a responsive fixed width container.</p>
</div>
</body>
</html>
Container Fluid Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootst
rap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootst
rap.bundle.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This part is inside a .container-fluid class.</p>
<p>The .container-fluid class provides a full width container, spanning
the entire width of the viewport.</p>
</div>
</body>
</html>
Bootstrap 5 Container
You learned from the previous chapter that Bootstrap requires a containing
element to wrap site contents. Containers are used to pad the content inside of
them, and there are two container classes available:
.container.container-fluid
Fixed Container
Use the .container class to create a responsive, fixed-width container.
Note that its width (max-width) will change on different screen sizes:
Open the example below and resize the browser window to see that the
container width will change at different breakpoints:
Example
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
Fluid Container
Use the .container-fluid class to create a full width container, that will always
span the entire width of the screen (width is always 100%):
Example
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div
Container Padding
By default, containers have left and right padding, with no top or bottom
padding. Therefore, we often use spacing utilities, such as extra padding and
margins to make them look even better. For example, .pt-5 means "add a
large top padding":
Example
<div class="container pt-5"></div>
Example
<div class="container p-5 my-5 border"></div>
Responsive Containers
You can also use the .container-sm|md|lg|xl classes to determine when the
container should be responsive. The max-width of the container will change on
different screen sizes/viewports:
Example
<div class="container-sm">.container-sm</div>
<div class="container-md">.container-md</div>
<div class="container-lg">.container-lg</div>
<div class="container-xl">.container-xl</div>
<div class="container-xxl">.container-xxl</div>
Bootstrap Grid System
Bootstrap's grid system is built with flexbox and allows up to 12 columns across
the page. If you do not want to use all 12 columns individually, you can group
the columns together to create wider columns:
span span span span span span span span span span span spa
1 1 1 1 1 1 1 1 1 1 1 n1
span 4 span 8
span 6 span 6
span 12
The grid system is responsive, and the columns will re-arrange automatically
depending on the screen size. Make sure that the sum adds up to 12 or fewer
(it is not required that you use all 12 available columns).
Grid Classes
The Bootstrap 5 grid system has six classes:
The classes above can be combined to create more dynamic and flexible
layouts.
Tip: Each class scales up, so if you want to set the same widths for sm and md,
you only need to specify sm.
Basic Structure of a Bootstrap Grid
The following is a basic structure of a Bootstrap 5 grid:
<!-- Control the column width, and how they should appear on different
devices -->
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<!-- Or let Bootstrap automatically handle the layout -->
<div class="row">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>
First example: create a row (<div class="row">). Then, add the desired
number of columns (tags with appropriate .col-*-* classes). The first star (*)
represents the responsiveness: sm, md, lg, xl or xxl, while the second star
represents a number, which should add up to 12 for each row. Second example:
instead of adding a number to each col, let bootstrap handle the layout, to
create equal width columns: two "col" elements = 50% width to each col, while
three cols = 33.33% width to each col. Four cols = 25% width, etc. You can
also use .col-sm|md|lg|xl|xxl to make the columns responsive. Below we
have collected some examples of basic Bootstrap 5 grid layouts.
The following example shows how to create three equal-width columns, on all
devices and screen widths:
Example
<div class="row">
<div class="col">.col</div>
<div class="col">.col</div>
<div class="col">.col</div>
</div>
Responsive Columns
.col-sm-3
.col-sm-3
.col-sm-3
.col-sm-3
The following example shows how to create four equal-width columns starting at
tablets and scaling to extra large desktops. On mobile phones or screens
that are less than 576px wide, the columns will automatically stack on
top of each other:
Example
<div class="row">
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
</div>
The following example shows how to get two various-width columns starting at
tablets and scaling to large extra desktops:
Example
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-8">.col-sm-8</div>
</div>
Bootstrap Text/Typography
Bootstrap 5 Default Settings
Bootstrap 5 uses a default font-size of 1rem (16px by default), and its line-
height is 1.5.
In addition, all <p> elements have margin-top: 0 and margin-bottom: 1rem (16px by
default).
<h1> - <h6>
Bootstrap 5 styles HTML headings (<h1> to <h6>) with a bolder font-weight and a
responsive font-size.
Example
<p class="h1">h1 Bootstrap heading</p>
<p class="h2">h2 Bootstrap heading</p>
<p class="h3">h3 Bootstrap heading</p>
<p class="h4">h4 Bootstrap heading</p>
<p class="h5">h5 Bootstrap heading</p>
<p class="h6">h6 Bootstrap heading</p>
Display Headings
Display headings are used to stand out more than normal headings (larger font-
size and lighter font-weight), and there are six classes to choose from: .display-
1 to .display-6:
Example
Display 1
Display 2
Display 3
Display 4
Display 5
Display 6
<small>
In Bootstrap 5 the HTML <small> element (and the .small class) is used to create
a smaller, secondary text in any heading:
<mark>
Bootstrap 5 will style <mark> and .mark with a yellow background color and some
padding:
Example
Use the mark element to highlight text.
<abbr>
Bootstrap 5 will style the HTML <abbr> element with a dotted border bottom and
a cursor with question mark on hove
Example
The WHO was founded in 1948.
<blockquote>
Add the .blockquote class to a <blockquote> when quoting blocks of content from
another source. And when naming a source, like "from WWF's website", use
the .blockquote-footer class:
<dl>
Bootstrap 5 will style the HTML <dl> element in the following way:
<code>
Bootstrap 5 will style the HTML <code> element in the following way:
<kbd>
Bootstrap 5 will style the HTML <kbd> element in the following way:
<pre>
Bootstrap 5 will style the HTML <pre> element in the following way:
Bootstrap Colors
Text Colors
Bootstrap 5 has some contextual classes that can be used to provide "meaning
through colors". The classes for text colors are: .text-muted, .text-primary, .text-
success, .text-info, .text-warning, .text-danger, .text-secondary, .text-white, .text-
dark, .text-body (default body color/often black) and .text-light:
Example
This text is muted.
Secondary text.
Body text.
Example
Black text with 50% opacity on white background
Example
This text is important.
Bootstrap Tables
Basic Table
A basic Bootstrap 5 table has a light padding and horizontal dividers.
Striped Rows
The .table-striped class adds zebra-stripes to a table:
Bordered Table
The .table-bordered class adds borders on all sides of the table and cells:
Hover Rows
The .table-hover class adds a hover effect (grey background color) on table
rows:
Black/Dark Table
The .table-dark class adds a black background to the table:
Borderless Table
The .table-borderless class removes borders from the table:
Contextual Classes
Contextual classes can be used to color the whole table (<table>), the table
rows (<tr>) or table cells (<td>).
Example
Default Defaultson def@somemail.com
Dark Bo bo@example.com
Class Description
.table-active Grey: Applies the hover color to the table row or table cell
Small table
The .table-sm class makes the table smaller by cutting cell padding in half:
Responsive Tables
The .table-responsive class adds a scrollbar to the table when needed (when it is
too big horizontally):
Example
<div class="table-responsive">
<table class="table">
...
</table>
</div>
You can also decide when the table should get a scrollbar, depending on the
screen width:
Class Screen
Bootstrap Images
Image Shapes
Rounded Corners:
Circle:
Thumbnail:
Rounded Corners
The .rounded class adds rounded corners to an image:
Example
<img src="cinqueterre.jpg" class="rounded" alt="Cinque Terre">
Circle
The .rounded-circle class shapes the image to a circle:
Example
<img src="cinqueterre.jpg" class="rounded-circle" alt="Cinque Terre">
Thumbnail
The .img-thumbnail class shapes the image to a thumbnail (bordered):
Example
<img src="cinqueterre.jpg" class="img-thumbnail" alt="Cinque Terre">
Aligning Images
Float an image to the left with the .float-start class or to the right with .float-
end:
Example
<img src="paris.jpg" class="float-start">
<img src="paris.jpg" class="float-end">
Centered Image
Center an image by adding the utility classes .mx-auto (margin:auto) and .d-
block (display:block) to the image:
Example
<img src="paris.jpg" class="mx-auto d-block">
Responsive Images
Images come in all sizes. So do screens. Responsive images automatically
adjust to fit the size of the screen. Create responsive images by adding an .img-
fluid class to the <img> tag. The image will then scale nicely to the parent
element. The .img-fluid class applies max-width: 100%; and height: auto; to the
image:
Example
<img class="img-fluid" src="ny.jpg" alt="New York">
Bootstrap Jumbotron
A jumbotron was introduced in Bootstrap 3 as a big padded box for
calling extra attention to some special content or information.
Jumbotron Example
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat..
Example
<div class="mt-4 p-5 bg-primary text-white rounded">
<h1>Jumbotron Example</h1>
<p>Lorem ipsum...</p>
</div>
Bootstrap Alerts
Alerts
Bootstrap 5 provides an easy way to create predefined alert messages:
Alerts are created with the .alert class, followed by one of the contextual
classes .alert-success, .alert-info, .alert-warning, .alert-danger, .alert-
primary, .alert-secondary, .alert-light or .alert-dark:
Example
<div class="alert alert-success">
<strong>Success!</strong> Indicates a successful or positive action.
</div>
Alert Links
Add the .alert-link class to any links inside the alert box to create "matching
colored links":
Example
<div class="alert alert-success">
<strong>Success!</strong> You should <a href="#" class="alert-link">read
this message</a>.
</div>
Closing Alerts
Success! This alert box could indicate a successful or positive action.
To close the alert message, add a .alert-dismissible class to the alert container.
Then add class="btn-close" and data-bs-dismiss="alert" to a link or a button
element (when you click on this the alert box will disappear).
Example
<div class="alert alert-success alert-dismissible">
<button type="button" class="btn-close" data-bs-
dismiss="alert"></button>
<strong>Success!</strong> This alert box could indicate a successful or
positive action.
</div>
Animated Alerts
The .fade and .show classes adds a fading effect when closing the alert message:
Example
<div class="alert alert-danger alert-dismissible fade show">
Bootstrap Buttons
Button Styles
Bootstrap 5 provides different styles of buttons:
Basic Primary Secondary Success Info Warning Danger Dark Light Link
Example
<button type="button" class="btn">Basic</button>
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-dark">Dark</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-link">Link</button>
Example
<a href="#" class="btn btn-success">Link Button</a>
<button type="button" class="btn btn-success">Button</button>
<input type="button" class="btn btn-success" value="Input Button">
<input type="submit" class="btn btn-success" value="Submit Button">
<input type="reset" class="btn btn-success" value="Reset Button">
Since we do not have any page to link it to, and we do not want to get a "404"
message, we put # as the link. In real life it should of course been a real URL to
the "Search" page.
Button Outline
Bootstrap 5 also provides eight outline/bordered buttons.
Example
<button type="button" class="btn btn-outline-primary">Primary</button>
<button type="button" class="btn btn-outline-secondary">Secondary</button>
<button type="button" class="btn btn-outline-success">Success</button>
<button type="button" class="btn btn-outline-info">Info</button>
<button type="button" class="btn btn-outline-warning">Warning</button>
<button type="button" class="btn btn-outline-danger">Danger</button>
<button type="button" class="btn btn-outline-dark">Dark</button>
<button type="button" class="btn btn-outline-light text-
dark">Light</button>
Button Sizes
Use the .btn-lg class for large buttons or .btn-sm class for small buttons:
Example
<button type="button" class="btn btn-primary btn-lg">Large</button>
<button type="button" class="btn btn-primary">Default</button>
<button type="button" class="btn btn-primary btn-sm">Small</button>
Full-Width Button
Example
<div class="d-grid">
<button type="button" class="btn btn-primary btn-block">Full-Width
Button</button>
</div>
If you have many block-level buttons, you can control the space between them
with the .gap-* class:
Example
<div class="d-grid gap-3">
<button type="button" class="btn btn-primary btn-block">Full-Width
Button</button>
<button type="button" class="btn btn-primary btn-block">Full-Width
Button</button>
<button type="button" class="btn btn-primary btn-block">Full-Width
Button</button>
</div>
Active/Disabled Buttons
A button can be set to an active (appear pressed) or a disabled (unclickable)
state: Active Primary Disabled Primary. The class .active makes a button appear
pressed, and the disabled attribute makes a button unclickable. Note that <a>
elements do not support the disabled attribute and must therefore use
the .disabled class to make it visually appear disabled.
Example
<button type="button" class="btn btn-primary active">Active
Primary</button>
<button type="button" class="btn btn-primary" disabled>Disabled
Primary</button>
<a href="#" class="btn btn-primary disabled">Disabled Link</a>
Spinner Buttons
You can also add "spinners" to a button, which you will learn more about in
our BS5 Spinners Tutorial:
Example
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
</button>
AppleSamsungSony
Tip: Instead of applying button sizes to every button in a group, use class .btn-
group-lg for a large button group or the .btn-group-sm for a small button group:
Large Buttons:
AppleSamsungSony
Default Buttons:
AppleSamsungSony
Small Buttons:
AppleSamsungSony
Example
<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
AppleSamsungSony
AppleSamsungSony
BMWMercedesVolvo
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary">BMW</button>
<button type="button" class="btn btn-primary">Mercedes</button>
<button type="button" class="btn btn-primary">Volvo</button>
</div>
Nesting Button Groups & Dropdown Menus
AppleSamsung
Sony
Nest button groups to create dropdown menus (you will learn more about
dropdowns in a later chapter):
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-
toggle="dropdown">Sony</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Tablet</a>
<a class="dropdown-item" href="#">Smartphone</a>
</div>
</div>
</div>
Bootstrap Badges
Badges
Badges are used to add additional information to any content:
Use the .badge class together with a contextual class (like .bg-secondary)
within <span> elements to create rectangular badges. Note that badges scale to
match the size of the parent element (if any):
Example
<h1>Example heading <span class="badge bg-secondary">New</span></h1>
<h2>Example heading <span class="badge bg-secondary">New</span></h2>
<h3>Example heading <span class="badge bg-secondary">New</span></h3>
<h4>Example heading <span class="badge bg-secondary">New</span></h4>
<h5>Example heading <span class="badge bg-secondary">New</span></h5>
<h6>Example heading <span class="badge bg-secondary">New</span></h6>
Use any of the contextual classes (.bg-*) to change the color of a badge:
Example
<span class="badge bg-primary">Primary</span>
<span class="badge bg-secondary">Secondary</span>
<span class="badge bg-success">Success</span>
<span class="badge bg-danger">Danger</span>
<span class="badge bg-warning">Warning</span>
<span class="badge bg-info">Info</span>
<span class="badge bg-light">Light</span>
<span class="badge bg-dark">Dark</span>
Pill Badges
Use the .rounded-pill class to make the badges more round:
Example
<span class="badge rounded-pill bg-primary">Primary</span>
<span class="badge rounded-pill bg-secondary">Secondary</span>
<span class="badge rounded-pill bg-success">Success</span>
<span class="badge rounded-pill bg-danger">Danger</span>
<span class="badge rounded-pill bg-warning">Warning</span>
<span class="badge rounded-pill bg-info">Info</span>
<span class="badge rounded-pill bg-light">Light</span>
<span class="badge rounded-pill bg-dark">Dark</span>
Messages 4
Example
<button type="button" class="btn btn-primary">
Messages <span class="badge bg-danger">4</span>
</button>
Example
<div class="progress">
<div class="progress-bar" style="width:70%"></div>
</div>
Progress Bar Height
The height of the progress bar is 1rem (usually 16px) by default. Use the
CSS height property to change it. Note that you must set the same height for
the progress container and the progress bar:
Example
<div class="progress" style="height:20px">
<div class="progress-bar" style="width:40%;height:20px"></div>
</div>
70%
Example
<div class="progress">
<div class="progress-bar" style="width:70%">70%</div>
</div>
Example
<div class="progress">
<div class="progress-bar progress-bar-striped" style="width:40%"></div>
</div>
Example
<div class="progress-bar progress-bar-striped progress-bar-
animated" style="width:40%"></div>
Free Space
Warning
Danger
Example
<div class="progress">
<div class="progress-bar bg-success" style="width:40%">
Free Space
</div>
<div class="progress-bar bg-warning" style="width:10%">
Warning
</div>
<div class="progress-bar bg-danger" style="width:20%">
Danger
</div>
</div>
Bootstrap Spinners
Spinners
To create a spinner/loader, use the .spinner-border class:
Loading..
Example
<div class="spinner-border"></div>
Colored Spinners
Use any text color utilites to add a color to the spinner:
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Example
<div class="spinner-border text-muted"></div>
<div class="spinner-border text-primary"></div>
<div class="spinner-border text-success"></div>
<div class="spinner-border text-info"></div>
<div class="spinner-border text-warning"></div>
<div class="spinner-border text-danger"></div>
<div class="spinner-border text-secondary"></div>
<div class="spinner-border text-dark"></div>
<div class="spinner-border text-light"></div>
Growing Spinners
Use the .spinner-grow class if you want the spinner/loader to grow instead of
"spin":
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Example
<div class="spinner-grow text-muted"></div>
<div class="spinner-grow text-primary"></div>
<div class="spinner-grow text-success"></div>
<div class="spinner-grow text-info"></div>
<div class="spinner-grow text-warning"></div>
<div class="spinner-grow text-danger"></div>
<div class="spinner-grow text-secondary"></div>
<div class="spinner-grow text-dark"></div>
<div class="spinner-grow text-light"></div>
Spinner Size
Use .spinner-border-sm or .spinner-grow-sm to create a smaller spinner:
Loading..
Loading..
Example
<div class="spinner-border spinner-border-sm"></div>
<div class="spinner-grow spinner-grow-sm"></div>
Spinner Buttons
You can also add spinners to a button, with or without text:
Example
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
</button>
Previous
1
2
3
Next
To create a basic pagination, add the .pagination class to an <ul> element. Then
add the .page-item to each <li> element and a .page-link class to each link
inside <li>:
Example
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
Active State
The .active class is used to "highlight" the current page:
Previous
1
2
3
Next
Example
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
Disabled State
The .disabled class is used for un-clickable links:
Previous
1
2
3
Next
Example
<ul class="pagination">
<li class="page-item disabled"><a class="page-
link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
Pagination Sizing
Pagination blocks can also be sized to a larger or a smaller size:
Previous
1
2
3
Next
Previous
1
2
3
Next
Add class .pagination-lg for larger blocks or .pagination-sm for smaller blocks:
Example
<ul class="pagination pagination-lg">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
Pagination Alignment
Use utility classes to change the alignment of the pagination:
Previous
1
2
3
Next
Previous
1
2
3
Next
Previous
1
2
3
Next
Example
<!-- Default (left-aligned) -->
<ul class="pagination" style="margin:20px 0">
<li class="page-item">...</li>
</ul>
Breadcrumbs
Another form for pagination, is breadcrumbs:
Photos
Summer 2017
Italy
Rome
The .breadcrumb and .breadcrumb-item classes indicates the current page's location
within a navigational hierarchy:
Example
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Photos</a></li>
<li class="breadcrumb-item"><a href="#">Summer 2017</a></li>
<li class="breadcrumb-item"><a href="#">Italy</a></li>
<li class="breadcrumb-item active">Rome</li>
</ul>
Bootstrap List Groups
Basic List Groups
The most basic list group is an unordered list with list items:
First item
Second item
Third item
To create a basic list group, use an <ul> element with class .list-group,
and <li> elements with class .list-group-item:
Example
<ul class="list-group">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
Active State
Active item
Second item
Third item
Example
<ul class="list-group">
<li class="list-group-item active">Active item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
List Group With Linked Items
First itemSecond itemThird item
Example
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">First
item</a>
<a href="#" class="list-group-item list-group-item-action">Second
item</a>
<a href="#" class="list-group-item list-group-item-action">Third
item</a>
</div>
Disabled Item
The .disabled class adds a lighter text color to the disabled item. And when
used on links, it will remove the hover effect:
Example
<div class="list-group">
<a href="#" class="list-group-item disabled">Disabled item</a>
<a href="#" class="list-group-item disabled">Disabled item</a>
<a href="#" class="list-group-item">Third item</a>
</div>
First item
Second item
Third item
Fourth item
Example
<ul class="list-group list-group-flush">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
<li class="list-group-item">Fourth item</li>
</ul>
First item
Second item
Third item
Example
<ol class="list-group list-group-numbered">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ol>
First item
Second item
Third item
Fourth item
Example
<ul class="list-group list-group-horizontal">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
<li class="list-group-item">Fourth item</li>
</ul>
Contextual Classes
Contextual classes can be used to add color to the list items:
Success item
Secondary item
Info item
Warning item
Danger item
Primary item
Dark item
Light item
Example
<ul class="list-group">
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-secondary">Secondary
item</li>
<li class="list-group-item list-group-item-info">Info item</li>
<li class="list-group-item list-group-item-warning">Warning item</li>
<li class="list-group-item list-group-item-danger">Danger item</li>
<li class="list-group-item list-group-item-primary">Primary item</li>
<li class="list-group-item list-group-item-dark">Dark item</li>
<li class="list-group-item list-group-item-light">Light item</li>
</ul>
Link items with Contextual Classes
Action itemSuccess itemSecondary itemInfo itemWarning itemDanger
itemPrimary itemDark itemLight item
Example
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">Action
item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-success">Success item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-secondary">Secondary item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-info">Info item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-warning">Warning item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-danger">Danger item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-primary">Primary item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-dark">Dark item</a>
<a href="#" class="list-group-item list-group-item-action list-group-
item-light">Light item</a>
</div>
Inbox12
Ads50
Junk99
Example
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-
center">
Inbox
<span class="badge bg-primary rounded-pill">12</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-
center">
Ads
<span class="badge bg-primary rounded-pill">50</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-
center">
Junk
<span class="badge bg-primary rounded-pill">99</span>
</li>
</ul>
Bootstrap Cards
Cards
A card in Bootstrap 5 is a bordered box with some padding around its content.
It includes options for headers, footers, content, colors, etc.
John Doe
Some example text some example text. John Doe is an architect and engineer
See Profile
Basic Card
A basic card is created with the .card class, and content inside the card has
a .card-body class:
Basic card
Example
<div class="card">
<div class="card-body">Basic card</div>
</div>
Content
Footer
The .card-header class adds a heading to the card and the .card-footer class adds
a footer to the card:
Example
<div class="card">
<div class="card-header">Header</div>
<div class="card-body">Content</div>
<div class="card-footer">Footer</div>
</div>
Contextual Cards
To add a background color the card, use contextual classes (.bg-primary, .bg-
success, .bg-info, .bg-warning, .bg-danger, .bg-secondary, .bg-dark and .bg-light.
Example
Basic card
Primary card
Success card
Info card
Warning card
Danger card
Secondary card
Dark card
Light card
Use .card-title to add card titles to any heading element. The .card-text class is
used to remove bottom margins for a <p> element if it is the last child (or the
only one) inside .card-body. The .card-link class adds a blue color to any link,
and a hover effect.
Example
<div class="card">
<div class="card-body">
<h4 class="card-title">Card title</h4>
<p class="card-text">Some example text. Some example text.</p>
<a href="#" class="card-link">Card link</a>
<a href="#" class="card-link">Another link</a>
</div>
</div>
Card Images
John Doe
Some example text some example text. John Doe is an architect and engineer
See Profile
Jane Doe
Some example text some example text. Jane Doe is an architect and engineer
See Profile
Example
<div class="card" style="width:400px">
<img class="card-img-top" src="img_avatar1.png" alt="Card image">
<div class="card-body">
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text.</p>
<a href="#" class="btn btn-primary">See Profile</a>
</div>
</div>
Card Image Overlays
John Doe
Some example text some example text. Some example text some example text.
Some example text some example text. Some example text some example text.
See Profile
Turn an image into a card background and use .card-img-overlay to add text on
top of the image:
Example
<div class="card" style="width:500px">
<img class="card-img-top" src="img_avatar1.png" alt="Card image">
<div class="card-img-overlay">
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text.</p>
<a href="#" class="btn btn-primary">See Profile</a>
</div>
</div>
Bootstrap Dropdowns
Basic Dropdown
A dropdown menu is a toggleable menu that allows the user to choose one
value from a predefined list:
Dropdown button
Example
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-
toggle="dropdown">
Dropdown button
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link 1</a></li>
<li><a class="dropdown-item" href="#">Link 2</a></li>
<li><a class="dropdown-item" href="#">Link 3</a></li>
</ul>
</div>
Example Explained
The .dropdown class indicates a dropdown menu. To open the dropdown menu,
use a button or a link with a class of .dropdown-toggle and the data-bs-
toggle="dropdown" attribute.
Add the .dropdown-menu class to a <div> element to actually build the dropdown
menu. Then add the .dropdown-item class to each element (links or buttons)
inside the dropdown menu.
Dropdown Divider
Dropdown button
The .dropdown-divider class is used to separate links inside the dropdown menu
with a thin horizontal border:
Example
<li><hr class="dropdown-divider"></hr></li>
Dropdown Header
Dropdown button
The .dropdown-header class is used to add headers inside the dropdown menu:
Example
<li><h5 class="dropdown-header">Dropdown header 1</h5></li>
Disable and Active items
Dropdown button
Highlight a specific dropdown item with the .active class (adds a blue
background color).
To disable an item in the dropdown menu, use the .disabled class (gets a light-
grey text color and a "no-parking-sign" icon on hover):
Example
<li><a class="dropdown-item" href="#">Normal</a></li>
<li><a class="dropdown-item active" href="#">Active</a></li>
<li><a class="dropdown-item disabled" href="#">Disabled</a></li>
Dropdown Position
Dropend
Dropstart
Dropright
<div class="dropdown dropend">
Dropleft
<div class="dropdown dropstart">
Dropup
Dropdown button
Example
<div class="dropup">
Dropdown Text
Dropdown button
Example
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link 1</a></li>
<li><a class="dropdown-item" href="#">Link 2</a></li>
<li><a class="dropdown-item" href="#">Link 3</a></li>
<li><a class="dropdown-item-text" href="#">Text Link</a></li>
<li><span class="dropdown-item-text">Just Text</span></li>
</ul>
Sony
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-
toggle="dropdown">Sony</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Tablet</a></li>
<li><a class="dropdown-item" href="#">Smartphone</a></li>
</ul>
</div>
</div>
Sony
Example
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-
toggle="dropdown">Sony</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Tablet</a></li>
<li><a class="dropdown-item" href="#">Smartphone</a></li>
</ul>
</div>
</div>
Bootstrap Collapse
Basic Collapsible
Collapsibles are useful when you want to hide and show large amount of
content:
Click Me
Example
<button data-bs-toggle="collapse" data-bs-
target="#demo">Collapsible</button>
Example Explained
The .collapse class indicates a collapsible element (a <div> in our example);
this is the content that will be shown or hidden with a click of a button.
Note: For <a> elements, you can use the href attribute instead of the data-bs-
target attribute:
Example
<a href="#demo" data-bs-toggle="collapse">Collapsible</a>
Example
<div id="demo" class="collapse show">
Lorem ipsum dolor text....
</div>
Accordion
Collapsible Group Item #1
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Note: Use the data-bs-parent attribute to make sure that all collapsible elements
under the specified parent will be closed when one of the collapsible item is
shown.
Example
<div id="accordion">
<div class="card">
<div class="card-header">
<a class="btn" data-bs-toggle="collapse" href="#collapseOne">
Collapsible Group Item #1
</a>
</div>
<div id="collapseOne" class="collapse show" data-bs-
parent="#accordion">
<div class="card-body">
Lorem ipsum..
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<a class="collapsed btn" data-bs-
toggle="collapse" href="#collapseTwo">
Collapsible Group Item #2
</a>
</div>
<div id="collapseTwo" class="collapse" data-bs-parent="#accordion">
<div class="card-body">
Lorem ipsum..
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<a class="collapsed btn" data-bs-
toggle="collapse" href="#collapseThree">
Collapsible Group Item #3
</a>
</div>
<div id="collapseThree" class="collapse" data-bs-parent="#accordion">
<div class="card-body">
Lorem ipsum..
</div>
</div>
</div>
</div>
Bootstrap Navs
Nav Menus
LinkLinkLinkDisabled
If you want to create a simple horizontal menu, add the .nav class to
a <ul> element, followed by .nav-item for each <li> and add the .nav-link class to
their links:
Example
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Aligned Nav
LinkLinkLinkDisabledLinkLinkLinkDisabled
Add the .justify-content-center class to center the nav, and the .justify-content-
end class to right-align the nav.
Example
<!-- Centered nav -->
<ul class="nav justify-content-center">
Example
<ul class="nav flex-column">
Tabs
ActiveLinkLinkDisabled
Turn the nav menu into navigation tabs with the .nav-tabs class. Add
the .active class to the active/current link. If you want the tabs to be togglable,
see the last example on this page.
Example
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Pills
ActiveLinkLinkDisabled
Turn the nav menu into navigation pills with the .nav-pills class. If you want the
pills to be togglable, see the last example on this page.
Example
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Justified Tabs/pills
Justify the tabs/pills with the .nav-justified class (equal width):
Active
Link
Link
Disabled
Active
Link
Link
Disabled
Example
<ul class="nav nav-pills nav-justified">..</ul>
<ul class="nav nav-tabs nav-justified">..</ul>
Pills with Dropdown
Active
Dropdown
Link
Disabled
Example
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-bs-
toggle="dropdown" href="#">Dropdown</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link 1</a></li>
<li><a class="dropdown-item" href="#">Link 2</a></li>
<li><a class="dropdown-item" href="#">Link 3</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
HOME
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
To make the tabs toggleable, add the data-toggle="tab" attribute to each link.
Then add a .tab-pane class with a unique ID for every tab and wrap them inside
a <div> element with class .tab-content.
If you want the tabs to fade in and out when clicking on them, add
the .fade class to .tab-pane:
Example
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="tab" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" href="#menu1">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="tab" href="#menu2">Menu 2</a>
</li>
</ul>
HOME
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
The same code applies to pills; only change the data-toggle attribute to data-
toggle="pill":
Example
<!-- Nav pills -->
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#menu1">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#menu2">Menu 2</a>
</li>
</ul>
Bootstrap Navbars
Navigation Bars
A navigation bar is a navigation header that is placed at the top of the page:
Logo
Link
Link
Link
Search
Basic Navbar
With Bootstrap, a navigation bar can extend or collapse, depending on the
screen size.
To add links inside the navbar, use either an <ul> element (or a <div>)
with class="navbar-nav". Then add <li> elements with a .nav-item class
followed by an <a> element with a .nav-link class:
Link 1
Link 2
Link 3
Example
<!-- A grey horizontal navbar that becomes vertical on small screens -->
<nav class="navbar navbar-expand-sm bg-light">
<div class="container-fluid">
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 3</a>
</li>
</ul>
</div>
</nav>
Vertical Navbar
Remove the .navbar-expand-* class to create a navigation bar that will always
be vertical:
Link 1
Link 2
Link 3
Example
<!-- A grey vertical navbar -->
<nav class="navbar bg-light">
...
</nav>
Centered Navbar
Add the .justify-content-center class to center the navigation bar:
Link 1
Link 2
Link 3
Example
<nav class="navbar navbar-expand-sm bg-light justify-content-center">
...
</nav>
Colored Navbar
Active
Link
Link
Disabled
Active
Link
Link
Disabled
Active
Link
Link
Disabled
Use any of the .bg-color classes to change the background color of the navbar
(.bg-primary, .bg-success, .bg-info, .bg-warning, .bg-danger, .bg-
secondary, .bg-dark and .bg-light)
Tip: Add a white text color to all links in the navbar with the .navbar-
dark class, or use the .navbar-light class to add a black text color.
Example
<!-- Grey with black text -->
<nav class="navbar navbar-expand-sm bg-light navbar-light">
<div class="container-fluid">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
Brand / Logo
The .navbar-brand class is used to highlight the brand/logo/project name of
your page:
Logo
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Logo</a>
</div>
</nav>
When using the .navbar-brand class with images, Bootstrap 5 will automatically
style the image to fit the navbar vertically.
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="logo.png" alt="Avatar
Logo" style="width:40px;" class="rounded-pill">
</a>
</div>
</nav>
Navbar Text
Navbar text
Use the .navbar-text class to vertical align any elements inside the navbar that
are not links (ensures proper padding and text color).
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<span class="navbar-text">Navbar text</span>
</div>
</nav>
LogoVery often, especially on small screens, you want to hide the navigation
links and replace them with a button that should reveal them when clicked on.
To create a collapsible navigation bar, use a button with class="navbar-
toggler", data-bs-toggle="collapse" and data-bs-target="#thetarget".
Then wrap the navbar content (links, etc) inside a <div> element
with class="collapse navbar-collapse", followed by an id that matches
the data-bs-target of the button: "thetarget".
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Logo</a>
<button class="navbar-toggler" type="button" data-bs-
toggle="collapse" data-bs-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>
</nav>
Tip: You can also remove the .navbar-expand-md class to ALWAYS hide navbar
links and display the toggler button.
Navbar With Dropdown
Link
Link
Link
Dropdown
Example
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-
toggle="dropdown">Dropdown</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link</a></li>
<li><a class="dropdown-item" href="#">Another link</a></li>
<li><a class="dropdown-item" href="#">A third link</a></li>
</ul>
</li>
Search
Example
<nav class="navbar navbar-expand-sm navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="javascript:void(0)">Logo</a>
<button class="navbar-toggler" type="button" data-bs-
toggle="collapse" data-bs-target="#mynavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mynavbar">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)">Link</a>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="text" placeholder="Search">
<button class="btn btn-primary" type="button">Search</button>
</form>
</div>
</div>
</nav>
The .fixed-top class makes the navigation bar fixed at the top:
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
...
</nav>
Use the .fixed-bottom class to make the navbar stay at the bottom of the
page:
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-bottom">
...
</nav>
Use the .sticky-top class to make the navbar fixed/stay at the top of the page
when you scroll past it. Note: This class does not work in IE11 and earlier (will
treat it as position:relative).
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
...
</nav>
Bootstrap Carousel
Carousel / Slideshow
The Carousel is a slideshow for cycling through elements:
How To Create a Carousel
The following example shows how to create a basic carousel with indicators and
controls:
Example
<!-- Carousel -->
<div id="demo" class="carousel slide" data-bs-ride="carousel">
<!-- Indicators/dots -->
<div class="carousel-indicators">
<button type="button" data-bs-target="#demo" data-bs-slide-
to="0" class="active"></button>
<button type="button" data-bs-target="#demo" data-bs-slide-
to="1"></button>
<button type="button" data-bs-target="#demo" data-bs-slide-
to="2"></button>
</div>
Class Description
.carousel- Adds indicators for the carousel. These are the little dots at
indicators the bottom of each slide (which indicates how many slides
there are in the carousel, and which slide the user are
currently viewing)
.carousel- Adds a right (next) button to the carousel, which allows the
control-next user to go forward between the slides
.slide Adds a CSS transition and animation effect when sliding from
one item to the next. Remove this class if you do not want
this effect
Example
<div class="carousel-item">
<img src="la.jpg" alt="Los Angeles">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>We had such a great time in LA!</p>
</div>
</div>
Bootstrap Modal
Modals
The Modal component is a dialog box/popup window that is displayed on top of
the current page:
Open modal
Example
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-
bs-target="#myModal">
Open modal
</button>
</div>
</div>
</div>
Add animation
Use the .fade class to add a fading effect when opening and closing the modal:
Example
<!-- Fading modal -->
<div class="modal fade"></div>
Modal Size
Change the size of the modal by adding the .modal-sm class for small modals
(max-width 300px), .modal-lg class for large modals (max-width 800px),
or .modal-xl for extra large modals (max-width 1140px). Default is 500px
max-width.
Add the size class to the <div> element with class .modal-dialog:
Small Modal
<div class="modal-dialog modal-sm">
Large Modal
<div class="modal-dialog modal-lg">
Fullscreen Modals
If you want the modal to span the whole width and height of the page, use
the .modal-fullscreen class:
Example
<div class="modal-dialog modal-fullscreen">
Class Description
Centered Modal
Center the modal vertically and horizontally within the page, with the .modal-
dialog-centered class:
Example
<div class="modal-dialog modal-dialog-centered">
Bootstrap Tooltip
Tooltips
The Tooltip component is small pop-up box that appears when the user moves
the mouse pointer over an element:
Use the title attribute to specify the text that should be displayed inside the
tooltip:
Positioning Tooltips
By default, the tooltip will appear on top of the element.
Use the data-bs-placement attribute to set the position of the tooltip on top,
bottom, left or the right side of the element:
Example
<a href="#" data-bs-toggle="tooltip" data-bs-
placement="top" title="Hooray!">Hover</a>
<a href="#" data-bs-toggle="tooltip" data-bs-
placement="bottom" title="Hooray!">Hover</a>
<a href="#" data-bs-toggle="tooltip" data-bs-
placement="left" title="Hooray!">Hover</a>
<a href="#" data-bs-toggle="tooltip" data-bs-
placement="right" title="Hooray!">Hover</a>
Bootstrap Popover
Popovers
The Popover component is similar to tooltips; it is a pop-up box that appears
when the user clicks on an element. The difference is that the popover can
contain much more content.
Toggle popover
How To Create a Popover
To create a popover, add the data-bs-toggle="popover" attribute to an element.
Use the title attribute to specify the header text of the popover, and use
the data-bs-content attribute to specify the text that should be displayed inside
the popover's body:
Example
<script>
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-
bs-toggle="popover"]'))
var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl)
})
</script>
Positioning Popovers
By default, the popover will appear on the right side of the element.
Use the data-bs-placement attribute to set the position of the popover on top,
bottom, left or the right side of the element:
Example
<a href="#" title="Header" data-bs-toggle="popover" data-bs-
placement="top" data-content="Content">Top</a>
<a href="#" title="Header" data-bs-toggle="popover" data-bs-
placement="bottom" data-content="Content">Bottom</a>
<a href="#" title="Header" data-bs-toggle="popover" data-bs-
placement="left" data-content="Content">Left</a>
<a href="#" title="Header" data-bs-toggle="popover" data-bs-
placement="right" data-content="Content">Right</a>
Note: The placement attributes do not work as you expect if it is not enough
room for them. For example: if you use the top placement at the top of a page
(where it is no room for it), it will instead display the popover below the
element or to the right (wherever it is room for it).
Closing Popovers
By default, the popover is closed when you click on the element again.
However, you can use the data-bs-trigger="focus" attribute which will close the
popover when clicking outside the element:
Example
<a href="#" title="Dismissible popover" data-bs-toggle="popover" data-bs-
trigger="focus" data-bs-content="Click anywhere in the document to close
this popover">Click me</a>
Hoverable Popover
Tip: If you want the popover to be displayed when you move the mouse pointer
over the element, use the data-bs-trigger attribute with a value of "hover":
Example
<a href="#" title="Header" data-bs-toggle="popover" data-bs-
trigger="hover" data-bs-content="Popover text">Hover over me</a>
Bootstrap Toasts
Toasts
The toast component is like an alert box that is only shown for a couple of
seconds when something happens (i.e. when the user clicks on a button,
submits a form, etc.).
Note: Toasts are hidden by default. Use the .show class if you want to display it.
To close it, use a <button> element and add data-bs-dismiss="toast":
Open a Toast
To show a toast with a click of a button, you must initialize it with JavaScript:
select the specified element and call the toast() method. The following code will
show all "toasts" in the document when you click on a button:
Example
<script>
document.getElementById("toastbtn").onclick = function() {
var toastElList = [].slice.call(document.querySelectorAll('.toast'))
var toastList = toastElList.map(function(toastEl) {
return new bootstrap.Toast(toastEl)
})
toastList.forEach(toast => toast.show())
}
</script>
Bootstrap Scrollspy
Scrollspy
Scrollspy is used to automatically update links in a navigation list based
on scroll position.
Example
<!-- The scrollable area -->
<body data-bs-spy="scroll" data-bs-target=".navbar" data-bs-offset="50">
<!-- The navbar - The <a> elements are used to jump to a section in the
scrollable area -->
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
...
<ul class="navbar-nav">
<li><a href="#section1">Section 1</a></li>
...
</nav>
</body>
Example Explained
Add data-bs-spy="scroll" to the element that should be used as the scrollable
area (often this is the <body> element).
Then add the data-bs-target attribute with a value of the id or the class name of
the navigation bar (.navbar). This is to make sure that the navbar is connected
with the scrollable area.
Note that scrollable elements must match the ID of the links inside the navbar's
list items (<div id="section1"> matches <a href="#section1">).
The optional data-bs-offset attribute specifies the number of pixels to offset from
top when calculating the position of scroll. This is useful when you feel that the
links inside the navbar changes the active state too soon or too early when
jumping to the scrollable elements. Default is 10 pixels.
Bootstrap Offcanvas
Offcanvas
Offcanvas is similar to modals (hidden by default and shown when activated),
except that is often used as a sidebar navigation menu.
Example
<!-- Offcanvas Sidebar -->
<div class="offcanvas offcanvas-start" id="demo">
<div class="offcanvas-header">
<h1 class="offcanvas-title">Heading</h1>
<button type="button" class="btn-close text-reset" data-bs-
dismiss="offcanvas"></button>
</div>
<div class="offcanvas-body">
<p>Some text lorem ipsum.</p>
<p>Some text lorem ipsum.</p>
<button class="btn btn-secondary" type="button">A Button</button>
</div>
</div>
Example Explained
The .offcanvas class creates the offcanvas sidebar.
The .offcanvas-start class positions the offcanvas, and makes it 400px wide.
See examples below for more positioning classes.
To open the offcanvas sidebar, you must use a <button> or an <a> element that
points to the id of the .offcanvas container (#demo in our example).
To open the offcanvas sidebar with an <a> element, you can point to #demo with
the href attribute, instead of data-bs-target attribute.
Offcanvas Position
Use the .offcanvas-start|end|top|bottom to position the offcanvas to the left,
right, top or bottom:
Right Example
<div class="offcanvas offcanvas-end" id="demo">
Top Example
<div class="offcanvas offcanvas-top" id="demo">
Bottom Example
<div class="offcanvas offcanvas-bottom" id="demo">
Example
<div class="offcanvas offcanvas-start offcanvas-lg" id="demo">
Example
<div class="offcanvas offcanvas-end" id="demo">
<button type="button" class="btn-close btn-close-white" data-bs-
dismiss="offcanvas"></button>
Bootstrap Utilities
Utilities / Helper Classes
Bootstrap 5 has a lot of utility/helper classes to quickly style elements without
using any CSS code.
Borders
Use the border classes to add or remove borders from an element:
Example
<span class="border"></span>
<span class="border border-0"></span>
<span class="border border-top-0"></span>
<span class="border border-end-0"></span>
<span class="border border-bottom-0"></span>
<span class="border border-start-0"></span>
<br>
<span class="border-top"></span>
<span class="border-end"></span>
<span class="border-bottom"></span>
<span class="border-start"></span>
Border Width
Use .border-1 to .border-5 to change the width of the border:
Example
Border Color
Add a color to the border with any of the contextual border color classes:
Example
Border Radius
Add rounded corners to an element with the rounded classes:
Example
<span class="rounded"></span>
<span class="rounded-top"></span>
<span class="rounded-end"></span>
<span class="rounded-bottom"></span>
<span class="rounded-start"></span>
<span class="rounded-circle"></span>
<span class="rounded-pill" style="width:130px"></span>
<span class="rounded-0"></span>
<span class="rounded-1"></span>
<span class="rounded-2"></span>
<span class="rounded-3"></span>
<span class="rounded-4"></span>
<span class="rounded-5"></span>
Example
Float leftFloat right
<div class="clearfix">
<span class="float-start">Float left</span>
<span class="float-end">Float right</span>
</div>
Responsive Floats
Float an element to the left or to the right depending on screen width, with the
responsive float classes (.float-*-start|end - where *
is sm (>=576px), md (>=768px), lg (>=992px), xl (>=1200px)
or xxl (>=1400px)):
Example
Float right on small screens or wider
Float none
<div class="float-sm-end">Float right on small screens or wider</div><br>
<div class="float-md-end">Float right on medium screens or wider</div><br>
<div class="float-lg-end">Float right on large screens or wider</div><br>
<div class="float-xl-end">Float right on extra large screens or
wider</div><br>
<div class="float-xxl-end">Float right on XXL screens or wider</div><br>
<div class="float-none">Float none</div>
Center Align
Center an element with the .mx-auto class (adds margin-left and margin-right:
auto):
Example
Centered
<div class="mx-auto bg-warning" style="width:150px">Centered</div>
Width
Set the width of an element with the w-* classes (.w-25, .w-50, .w-75, .w-100, .mw-
auto, .mw-100):
Example
Width 25%
Width 50%
Width 75%
Width 100%
Auto Width
Max Width 100%
<div class="w-25 bg-warning">Width 25%</div>
<div class="w-50 bg-warning">Width 50%</div>
<div class="w-75 bg-warning">Width 75%</div>
<div class="w-100 bg-warning">Width 100%</div>
<div class="w-auto bg-warning">Auto Width</div>
<div class="mw-100 bg-warning">Max Width 100%</div>
Height
Set the height of an element with the h-* classes (.h-25, .h-50, .h-75, .h-100, .mh-
auto, .mh-100):
Example
Height 25%
Height 50%
Height 75%
Height 100%
Auto Height
Spacing
Bootstrap 5 has a wide range of responsive margin and padding utility classes.
They work for all
breakpoints: xs (<=576px), sm (>=576px), md (>=768px), lg (>=992px), xl (>
=1200px) or xxl (>=1400px)):
m - sets margin
p - sets padding
Example
I only have a top padding (1.5rem)
I have a padding on all sides (3rem)
I have a margin on all sides (3rem) and a bottom padding (3rem)
<div class="pt-4 bg-warning">I only have a top padding (1.5rem)</div>
<div class="p-5 bg-success">I have a padding on all sides (3rem)</div>
<div class="m-5 pb-5 bg-info">I have a margin on all sides (3rem) and a
bottom padding (3rem)</div>
Shadows
Use the shadow- classes to add shadows to an element:
Example
No shadow
Small shadow
Default shadow
Large shadow
<div class="shadow-none p-4 mb-4 bg-light">No shadow</div>
<div class="shadow-sm p-4 mb-4 bg-white">Small shadow</div>
<div class="shadow p-4 mb-4 bg-white">Default shadow</div>
<div class="shadow-lg p-4 mb-4 bg-white">Large shadow</div>
Vertical Align
Use the align- classes to change the alignment of elements (only works on
inline, inline-block, inline-table and table cell elements):
Example
baseline top middle bottom text-top text-bottom
<span class="align-baseline">baseline</span>
<span class="align-top">top</span>
<span class="align-middle">middle</span>
<span class="align-bottom">bottom</span>
<span class="align-text-top">text-top</span>
<span class="align-text-bottom">text-bottom</span>
Aspect Ratio
Create responsive video or slideshows based on the width of the parent.
Add the .ratio class together with an aspect ratio of your choice .ratio-* to a
parent element, and add the embed (video or iframe) inside of it:
Example
<!-- Aspect ratio 1:1 -->
<div class="ratio ratio-1x1">
<iframe src="https://www.youtube.com/embed/tgbNymZ7vqY"></iframe>
</div>
Visibility
Use the .visible or .invisible classes to control the visibility of
elements. Note: These classes do not change the CSS display value. They only
add visibility:visible or visibility:hidden:
Example
I am visible
<div class="visible">I am visible</div>
<div class="invisible">I am invisible</div>
Close icon
Use the .btn-close class to style a close icon. This is often used for alerts and
modals.
Example
<button type="button" class="btn-close"></button>
Screenreaders
Use the .visually-hidden class to hide an element on all devices, except screen
readers:
Example
<span class="visually-hidden">I will be hidden on all screens except for
screen readers.</span>
Colors
As described in the Colors chapter, here is a list of all text and background color
classes:
The classes for text colors are: .text-muted, .text-primary, .text-success, .text-
info, .text-warning, .text-danger, .text-secondary, .text-white, .text-dark, .text-
body (default body color/often black) and .text-light:
Example
This text is muted.
Secondary text.
Body text.
Example
Muted link. Primary link. Success link. Info link. Warning link. Danger
link. Secondary link. Dark grey link. Body/black link. Light grey link.
You can also add 50% opacity for black or white text with the .text-black-
50 or .text-white-50 classes:
Example
Black text with 50% opacity on white background
Background Colors
The classes for background colors are: .bg-primary, .bg-success, .bg-info, .bg-
warning, .bg-danger, .bg-secondary, .bg-dark and .bg-light.
Example
The .bg-color classes above does not work well with text, or atleast then you
have to specify a proper .text-color class to get the right text color for each
background.
However, you can use the .text-bg-color classes and Bootstrap will
automatically handle the appropriate text color for each background color:
Example
This text is important.
The Flexible Box Layout Module, makes it easier to design flexible responsive
layout structure without using float or positioning. If you are new to flex, you
can read about it in our CSS Flexbox Tutorial.
If you require IE8-9 support, use Bootstrap 3. It is the most stable version
of Bootstrap, and it is still supported by the team for critical bugfixes and
documentation changes. However, no new features will be added to it.
To create a flexbox container and to transform direct children into flex items,
use the d-flex class:
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex p-3 bg-secondary text-white">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Flex item 2
Flex item 3
Example
<div class="d-inline-flex p-3 bg-secondary text-white">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Horizontal Direction
Use .flex-row to display the flex items horizontally (side by side). This is default.
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex flex-row bg-secondary">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
<div class="d-flex flex-row-reverse bg-secondary">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Vertical Direction
Use .flex-column to display the flex items vertically (on top of each other),
or .flex-column-reverse to reverse the vertical direction:
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex flex-column">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex justify-content-start">...</div>
<div class="d-flex justify-content-end">...</div>
<div class="d-flex justify-content-center">...</div>
<div class="d-flex justify-content-between">...</div>
<div class="d-flex justify-content-around">...</div>
Fill / Equal Widths
Use .flex-fill on flex items to force them into equal widths:
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex">
<div class="p-2 bg-info flex-fill">Flex item 1</div>
<div class="p-2 bg-warning flex-fill">Flex item 2</div>
<div class="p-2 bg-primary flex-fill">Flex item 3</div>
</div>
Grow
Use .flex-grow-1 on a flex item to take up the rest of the space. In the example
below, the first two flex items take up their necessary space, while the last item
takes up the rest of the available space:
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary flex-grow-1">Flex item 3</div>
</div>
Tip: Use .flex-shrink-1 on a flex item to make it shrink if necessary.
Order
Change the visual order of a specific flex item(s) with the .order classes. Valid
classes are from 0 to 5, where the lowest number has highest priority (order-1
is shown before order-2, etc..):
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex bg-secondary">
<div class="p-2 bg-info order-3">Flex item 1</div>
<div class="p-2 bg-warning order-2">Flex item 2</div>
<div class="p-2 bg-primary order-1">Flex item 3</div>
</div>
Auto Margins
Easily add auto margins to flex items with .ms-auto (push items to the right), or
by using .me-auto (push items to the left):
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex bg-secondary">
<div class="p-2 ms-auto bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Wrap
Control how flex items wrap in a flex container with .flex-nowrap (default), .flex-
wrap or .flex-wrap-reverse.
Click on the buttons below to see the difference between the three classes, by
changing the wrapping of the flex items in the example box:
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 4
Flex item 5
Flex item 6
Flex item 7
Flex item 8
Flex item 9
Flex item 10
Flex item 11
Flex item 12
Flex item 13
Flex item 14
Flex item 15
Flex item 16
Flex item 17
Flex item 18
Flex item 19
Flex item 20
Flex item 21
Flex item 22
Flex item 23
Flex item 24
Flex item 25
Example
<div class="d-flex flex-wrap">..</div>
Align Content
Control the vertical alignment of gathered flex items with the .align-content-
* classes. Valid classes are .align-content-start (default), .align-content-
end, .align-content-center, .align-content-between, .align-content-around and .align-
content-stretch.
Click on the buttons below to see the difference between the five classes, by
changing the vertical alignment of the flex items in the example box:
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 4
Flex item 5
Flex item 6
Flex item 7
Flex item 8
Flex item 9
Flex item 10
Flex item 11
Flex item 12
Flex item 13
Flex item 14
Flex item 15
Flex item 16
Flex item 17
Flex item 18
Flex item 19
Flex item 20
Flex item 21
Flex item 22
Flex item 23
Flex item 24
Flex item 25
Example
<div class="d-flex flex-wrap align-content-start">..</div>
Align Items
Control the vertical alignment of single rows of flex items with the .align-
items-* classes. Valid classes are .align-items-start, .align-items-end, .align-items-
center, .align-items-baseline, and .align-items-stretch (default).
Click on the buttons below to see the difference between the five classes:
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex align-items-start">..</div>
Align Self
Control the vertical alignment of a specified flex item with the .align-self-
* classes. Valid classes are .align-self-start, .align-self-end, .align-self-
center, .align-self-baseline, and .align-self-stretch (default).
Click on the buttons below to see the difference between the five classes:
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex bg-light" style="height:150px">
<div class="p-2 border">Flex item 1</div>
<div class="p-2 border align-self-start">Flex item 2</div>
<div class="p-2 border">Flex item 3</div>
</div>
Bootstrap Forms
Stacked Form
All textual <input> and <textarea> elements with class .form-control get
proper form styling:
Email:
Password:
Remember me
Submit
Example
<form action="/action_page.php">
<div class="mb-3 mt-3">
<label for="email" class="form-label">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter
email" name="email">
</div>
<div class="mb-3">
<label for="pwd" class="form-label">Password:</label>
<input type="password" class="form-
control" id="pwd" placeholder="Enter password" name="pswd">
</div>
<div class="form-check mb-3">
<label class="form-check-label">
<input class="form-check-
input" type="checkbox" name="remember"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Also note that we add a .form-label class to each label element to ensure correct
padding.
Checkboxes have different markup. They are wrapped around a container
element with .form-check, and labels have a class of .form-check-label, while
checkboxes and radio buttons use .form-check-input.
Textarea
Comments:
Submit
Example
<label for="comment">Comments:</label>
<textarea class="form-
control" rows="5" id="comment" name="text"></textarea>
If you want your form elements to appear side by side, use .row and .col:
Example
<form>
<div class="row">
<div class="col">
<input type="text" class="form-control" placeholder="Enter
email" name="email">
</div>
<div class="col">
<input type="password" class="form-control" placeholder="Enter
password" name="pswd">
</div>
</div>
</form>
You can change the size of .form-control inputs with .form-control-lg or .form-
control-sm:
Example
<input type="text" class="form-control form-control-lg" placeholder="Large
input">
<input type="text" class="form-control" placeholder="Normal input">
<input type="text" class="form-control form-control-sm" placeholder="Small
input">
Use the disabled and/or readonly attributes to disable the input field:
Example
<input type="text" class="form-control" placeholder="Normal input">
<input type="text" class="form-control" placeholder="Disabled
input" disabled>
<input type="text" class="form-control" placeholder="Readonly
input" readonly>
Example
<input type="text" class="form-control-plaintext" placeholder="Plaintext
input">
<input type="text" class="form-control" placeholder="Normal input">
Color Picker
To style an input with type="color" properly, use the .form-control-color class:
Example
<input type="color" class="form-control form-control-
color" value="#CCCCCC">
Bootstrap Select
Select Menu
Select menu (select one):
Multiple select menu (hold ctrl or shift (or drag with the mouse) to select more
than one):
Select menus are used if you want to allow the user to pick from multiple
options.
To style a select menu in Bootstrap 5, add the .form-select class to the <select>
element:
Example
<select class="form-select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
Use the .form-select-lg or .form-select-sm class to change the size of the select
menu:
Example
<select class="form-select form-select-lg">
<select class="form-select">
<select class="form-select form-select-sm">
Example
<select class="form-select" disabled>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
Data Lists
Bootstrap will also style data lists, which is a list of pre-defined options for an
<input> element:
Choose your browser from the list:
Example
<label for="browser" class="form-label">Choose your browser from the
list:</label>
<input class="form-control" list="browsers" name="browser" id="browser">
<datalist id="browsers">
<option value="Edge">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Option 1
Option 2
Disabled Option
Example
<div class="form-check">
<input class="form-check-
input" type="checkbox" id="check1" name="option1" value="something" checke
d>
<label class="form-check-label">Option 1</label>
</div>
Example Explained
Radio buttons
Radio buttons are used if you want to limit the user to just one selection from a
list of preset options.
Option 1
Option 2
Option 3
Example
<div class="form-check">
<input type="radio" class="form-check-
input" id="radio1" name="optradio" value="option1" checked>Option 1
<label class="form-check-label" for="radio1"></label>
</div>
<div class="form-check">
<input type="radio" class="form-check-
input" id="radio2" name="optradio" value="option2">Option 2
<label class="form-check-label" for="radio2"></label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" disabled>Option 3
<label class="form-check-label"></label>
</div>
Toggle Switches
If you want your checkbox to be styled as a toggle switch, use the .form-
switch class together with the .form-check container:
Dark Mode
Example
<div class="form-check form-switch">
<input class="form-check-
input" type="checkbox" id="mySwitch" name="darkmode" value="yes" checked>
<label class="form-check-label" for="mySwitch">Dark Mode</label>
</div>
Bootstrap Range
Custom Range
To style a range menu, add the .form-range class to the input element with
type="range":
Custom range
Default range
Example
<label for="customRange" class="form-label">Custom range</label>
<input type="range" class="form-range" id="customRange"
Steps
By default, the interval between the range numbers is 1. You can change it by
using the step attribute:
Example
<input type="range" class="form-range" step="10">
Min and Max
By default, the minimum value is 0 and maximum value is 100. You can use
the min and/or max attribute change it:
Example
<input type="range" class="form-range" min="0" max="4">
@example.com
Example
<form>
<div class="input-group">
<span class="input-group-text">@</span>
<input type="text" class="form-control" placeholder="Username">
</div>
<div class="input-group">
<input type="text" class="form-control" placeholder="Your Email">
<span class="input-group-text">@example.com</span>
</div>
</form>
Small
Default
Large
Example
<div class="input-group mb-3 input-group-sm">
<span class="input-group-text">Small</span>
<input type="text" class="form-control">
</div>
Person
OneTwoThree
Example
<!-- Multiple inputs -->
<div class="input-group mb-3">
<span class="input-group-text">Person</span>
<input type="text" class="form-control" placeholder="First Name">
<input type="text" class="form-control" placeholder="Last Name">
</div>
Example
<div class="input-group mb-3">
<div class="input-group-text">
<input type="checkbox">
</div>
<input type="text" class="form-control" placeholder="Some text">
</div>
Go
OKCancel
Example
<div class="input-group mb-3">
<button class="btn btn-outline-primary" type="button">Basic
Button</button>
<input type="text" class="form-control" placeholder="Some text">
</div>
Dropdown button
Example
<div class="input-group mt-3 mb-3">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-
toggle="dropdown">
Dropdown button
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link 1</a></li>
<li><a class="dropdown-item" href="#">Link 2</a></li>
<li><a class="dropdown-item" href="#">Link 3</a></li>
</ul>
<input type="text" class="form-control" placeholder="Username">
</div>
Email Label
With floating labels, you can insert the label inside the input field, and make
them float/animate when you click on the input field:
Password
Example
<div class="form-floating mb-3 mt-3">
<input type="text" class="form-control" id="email" placeholder="Enter
email" name="email">
<label for="email">Email</label>
</div>
Notes on floating labels: The <label> elements must come after the <input>
element, and the placeholder attribute is required for each <input> element
(even though it is not shown).
Textarea
It also works for textareas:
Comments
Example
<div class="form-floating">
<textarea class="form-
control" id="comment" name="text" placeholder="Comment goes
here"></textarea>
<label for="comment">Comments</label>
</div>
Select Menus
You can also use "floating-labels" on select menus. However, they will not
float/get animated. The label will always appear in the top left corner, inside the
select menu:
Example
<div class="form-floating">
<select class="form-select" id="sel1" name="sellist">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<label for="sel1" class="form-label">Select list (select one):</label>
</div>
Password:
I agree on blabla.
You can use different validation classes to provide valuable feedback to users.
Add either .was-validated or .needs-validation to the <form> element, depending on
whether you want to provide validation feedback before or after submitting the
form. The input fields will have a green (valid) or red (invalid) border to indicate
what's missing in the form. You can also add a .valid-feedback or .invalid-
feedback message to tell the user explicitly what's missing, or needs to be done
before submitting the form.
Example
In this example, we use .was-validated to indicate what's missing before
submitting the form:
If you do not want to use all 12 columns individually, you can group the
columns together to create wider columns:
span span span span span span span span span span span span
1 1 1 1 1 1 1 1 1 1 1 1
span 4 span 8
span 6 span 6
span 12
The grid system is responsive, and the columns will re-arrange automatically
depending on the screen size.
Make sure that the sum adds up to 12 or fewer (it is not required that you use
all 12 available columns).
Grid Classes
The Bootstrap 5 grid system has six classes:
The classes above can be combined to create more dynamic and flexible
layouts.
Tip: Each class scales up, so if you want to set the same widths for sm and md,
you only need to specify sm.
<!-- Control the column width, and how they should appear on different
devices -->
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
First example: create a row (<div class="row">). Then, add the desired number of
columns (tags with appropriate .col-*-* classes). The first star (*) represents
the responsiveness: sm, md, lg, xl or xxl, while the second star represents a
number, which should add up to 12 for each row. Second example: instead of
adding a number to each col, let bootstrap handle the layout, to create equal
width columns: two "col" elements = 50% width to each col, while three cols =
33.33% width to each col. Four cols = 25% width, etc. You can also use .col-
sm|md|lg|xl|xxl to make the columns responsive.
Grid Options
The following table summarizes how the Bootstrap 5 grid system works across
different screen sizes:
Extra
Small Medium Large Extra Large XXL
small
(>=576px) (>=768px) (>=992px) (>=1200px) (>=1400px)
(<576px)
Class .col- .col-sm- .col-md- .col-lg- .col-xl- .col-xxl-
prefix
Container
None (auto) 540px 720px 960px 1140px 1320px
width
# of
12 12 12 12 12 12
columns
col-sm-6
col-sm-6
Example: Stacked-to-horizontal
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 bg-primary">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-6 bg-dark">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Tip: The numbers in the .col-sm-* classes indicates how many columns the div
should span (out of 12). So, .col-sm-1 spans 1 column, .col-sm-4 spans 4
columns, .col-sm-6 spans 6 columns, etc.
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
Tip: You can turn any full-width layout into a fixed-width responsive layout,
by changing the .container-fluid class to .container:
<!-- Two columns: 50% width on all screens, except for extra small (100%
width) -->
<div class="row">
<div class="col-sm">1 of 2</div>
<div class="col-sm">2 of 2</div>
</div>
<!-- Four columns: 25% width on all screens, except for extra small (100%
width)-->
<div class="row">
<div class="col-sm">1 of 4</div>
<div class="col-sm">2 of 4</div>
<div class="col-sm">3 of 4</div>
<div class="col-sm">4 of 4</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
Assume we have a simple layout with two columns. We want the columns to
split 25%/75% for ALL devices.
<div class="col-3">....</div>
<div class="col-9">....</div>
The following example will result in a 25%/75% split on all devices (extra small,
small, medium, large, xlarge and xxlarge).
col-3
col-9
Example
<div class="container-fluid">
<div class="row">
<div class="col-3 bg-primary">
<p>Lorem ipsum...</p>
</div>
<div class="col-9 bg-dark">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
For a 33.3%/66.6% split, you would use .col-4 and .col-8 (and for a 50%/50%
split, you would use .col-6 and .col-6):
col-4
col-8
col-6
col-6
Example
<!-- 33.3%/66.6% split -->
<div class="container-fluid">
<div class="row">
<div class="col-4 bg-primary">
<p>Lorem ipsum...</p>
</div>
<div class="col-8 bg-dark">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
<!-- 50%/50% split -->
<div class="container-fluid">
<div class="row">
<div class="col-6 bg-primary">
<p>Lorem ipsum...</p>
</div>
<div class="col-6 bg-dark">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
Assume we have a simple layout with two columns. We want the columns to be
split 25%/75% for small devices.
Small devices are defined as having a screen width from 576 pixels to 767
pixels.
<div class="col-sm-3">....</div>
<div class="col-sm-9">....</div>
The following example will result in a 25%/75% split on small (and medium,
large, xlarge and xxlarge) devices. On extra small devices, it will automatically
stack (100%):
.col-sm-3
.col-sm-9
Example
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 bg-primary">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 bg-dark">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
For a 33.3%/66.6% split, you would use .col-sm-4 and .col-sm-8 (and for a
50%/50% split, you would use .col-sm-6 and .col-sm-6):
.col-sm-4
.col-sm-8
.col-sm-6
.col-sm-6
Example
<!-- 33.3/66.6% split: -->
<div class="container-fluid">
<div class="row">
<div class="col-sm-4 bg-primary">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-8 bg-dark">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
If the screen size is less than 576px, the columns will stack horizontally:
<!-- Two columns: 50% width on all screens, except for extra small (100%
width) -->
<div class="row">
<div class="col-sm">1 of 2</div>
<div class="col-sm">2 of 2</div>
</div>
<!-- Four columns: 25% width on all screens, except for extra small (100%
width)-->
<div class="row">
<div class="col-sm">1 of 4</div>
<div class="col-sm">2 of 4</div>
<div class="col-sm">3 of 4</div>
<div class="col-sm">4 of 4</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
In the previous chapter, we presented a grid example with classes for small
devices. We used two divs (columns) and we gave them a 25%/75% split:
<div class="col-sm-3">....</div>
<div class="col-sm-9">....</div>
Medium devices are defined as having a screen width from 768 pixels to 991
pixels.
Now Bootstrap is going to say "at the small size, look at classes with -sm- in
them and use those. At the medium size, look at classes with -md- in them and
use those".
The following example will result in a 25%/75% split on small devices and a
50%/50% split on medium (and large, xlarge and xxlarge) devices. On extra
small devices, it will automatically stack (100%):
.col-sm-3 .col-md-6
.col-sm-9 .col-md-6
Example
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
Example
<div class="row">
<div class="col-md-6">
<p>Lorem ipsum...</p>
</div>
<div class="col-md-6">
<p>Sed ut perspiciatis...</p>
</div>
</div>
Auto Layout Columns
In Bootstrap 5, there is an easy way to create equal width columns for all
devices: just remove the number from .col-md-* and only use the .col-md class
on a specified number of col elements. Bootstrap will recognize how many
columns there are, and each column will get the same width.
If the screen size is less than 768px, the columns will stack horizontally:
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
In the previous chapter, we presented a grid example with classes for small and
medium devices. We used two divs (columns) and we gave them a 25%/75%
split on small devices, and a 50%/50% split on medium devices:
Large devices are defined as having a screen width from 992 pixels to 1199
pixels.
Now Bootstrap is going to say "at the small size, look at classes with -sm- in
them and use those. At the medium size, look at classes with -md- in them and
use those. At the large size, look at classes with the word -lg- in them and use
those.
Example
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
Example
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<p>Lorem ipsum...</p>
</div>
<div class="col-lg-6">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
In the previous chapter, we presented a grid example with classes for small,
medium and large devices. We used two divs (columns) and we gave them a
25%/75% split on small devices, and a 50%/50% split on medium devices and
a 33%/66% split on large devices:
Extra large devices are defined as having a screen width from 1200 pixels and
above.
Example
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4 col-xl-2">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8 col-xl-10">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Example
<div class="container-fluid">
<div class="row">
<div class="col-xl-6">
<p>Lorem ipsum...</p>
</div>
<div class="col-xl-6">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
If the screen size is less than 1200px, the columns will stack horizontally:
<!-- Two columns: 50% width on xlarge and up-->
<div class="row">
<div class="col-xl">1 of 2</div>
<div class="col-xl">2 of 2</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
XXL devices are defined as having a screen width from 1400 pixels and
above.
The following example will result in a 50%/50% split on medium, large and
extra large devices, and a 25%/75% split on XXL devices. On small and extra
small devices, it will automatically stack (100%):
col-md-6 col-xxl-3
col-md-6 col-xxl-9
Example
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-xxl-3">
<p>Lorem ipsum...</p>
</div>
<div class="col-md-6 col-xxl-9">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
If the screen size is less than 1400px, the columns will stack horizontally:
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
col
col
col
Example
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="col">col</div>
</div>
col-4
col-4
col-4
Example
<div class="row">
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
</div>
col-3
col-6
col-3
Example
<div class="row">
<div class="col-3">col-3</div>
<div class="col-6">col-6</div>
<div class="col-3">col-3</div>
</div>
col
col-6
col
Example
<div class="row">
<div class="col">col</div>
<div class="col-6">col-6</div>
<div class="col">col</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
1 of 6
2 of 6
3 of 6
4 of 6
5 of 6
6 of 6
Example
<div class="row row-cols-1">
<div class="col">1 of 2</div>
<div class="col">2 of 2</div>
</div>
Equal Height
If one of the column is taller than the other (due to text or CSS height), the rest
will follow:
Lorem ipsum dolor sit amet, cibo sensibus interesset no sit. Et dolor possim
volutpat qui. No malis tollit iriure eam, et vel tale zril blandit, rebum vidisse
nostrum qui eu. No nostrud dolorem legendos mea, ea eum mucius oporteat
platonem.Eam an case scribentur, ei clita causae cum, alia debet eu vel.
col
col
Example
<div class="row">
<div class="col">Lorem ipsum...</div>
<div class="col">col</div>
<div class="col">col</div>
</div>
Nested Columns
col-8
col-6
col-6
col-4
The following example shows how to create a two column layout, with another
two columns inside one of the columns:
Example
<div class="row">
<div class="col-8">
.col-8
<div class="row">
<div class="col-6">.col-6</div>
<div class="col-6">.col-6</div>
</div>
</div>
<div class="col-4">.col-4</div>
</div>
Responsive Classes
The Bootstrap 5 grid system has five classes:
The classes above can be combined to create more dynamic and flexible
layouts.
Tip: Each class scales up, so if you wish to set the same widths for sm and md,
you only need to specify sm.
Stacked to Horizontal
col-sm-9
col-sm-3
col-sm
col-sm
col-sm
The following example shows how to create a column layout that starts out
stacked on extra small devices, before becoming horizontal on larger devices
(sm, md, lg and xl):
Example
<div class="row">
<div class="col-sm-9">col-sm-9</div>
<div class="col-sm-3">col-sm-3</div>
</div>
<div class="row">
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
</div>
<!-- 58%/42% split on extra small, small and medium devices and
66.3%/33.3% split on large and xlarge devices -->
<div class="row">
<div class="col-7 col-lg-8">col-7 col-lg-8</div>
<div class="col-5 col-lg-4">col-5 col-lg-4</div>
</div>
No Gutters
To change the gutters (extra space) between columns, use any of the .g-
1|2|3|4|5 classes (.g-4 is default).
Example
<div class="row g-0">