diff --git a/404.html b/404.html new file mode 100644 index 0000000000..e5a1aed18c --- /dev/null +++ b/404.html @@ -0,0 +1,173 @@ + + +
+ + + + + + + + + +Documentation and examples for Bootstrap’s logo and brand usage guidelines.
+ + +Have a need for Bootstrap’s brand resources? Great! We have only a few guidelines we follow, and in turn ask you to follow as well.
+When referencing Bootstrap, use our logo mark. Do not modify our logos in any way. Do not use Bootstrap’s branding for your own open or closed source projects. Do not use the Twitter name or logo in association with Bootstrap.
+Our logo mark is also available in black and white. All rules for our primary logo apply to these as well.
+Bootstrap should always be referred to as just Bootstrap. No Twitter before it and no capital s.
+Commonly asked questions about Bootstrap’s open source license.
+ + +Bootstrap is released under the MIT license and is copyright 2020 Twitter. Boiled down to smaller chunks, it can be described with the following conditions.
+The full Bootstrap license is located in the project repository for more information.
+ +Learn more about the team maintaining Bootstrap, how and why the project started, and how to get involved.
+ + +Bootstrap is maintained by a small team of developers on GitHub. We’re actively looking to grow this team and would love to hear from you if you’re excited about CSS at scale, writing and maintaining vanilla JavaScript plugins, and improving build tooling processes for frontend code.
+Originally created by a designer and a developer at Twitter, Bootstrap has become one of the most popular front-end frameworks and open source projects in the world.
+Bootstrap was created at Twitter in mid-2010 by @mdo and @fat. Prior to being an open-sourced framework, Bootstrap was known as Twitter Blueprint. A few months into development, Twitter held its first Hack Week and the project exploded as developers of all skill levels jumped in without any external guidance. It served as the style guide for internal tools development at the company for over a year before its public release, and continues to do so today.
+Originally released on , we’ve since had over twenty releases, including two major rewrites with v2 and v3. With Bootstrap 2, we added responsive functionality to the entire framework as an optional stylesheet. Building on that with Bootstrap 3, we rewrote the library once more to make it responsive by default with a mobile first approach.
+With Bootstrap 4, we once again rewrote the project to account for two key architectural changes: a migration to Sass and the move to CSS’s flexbox. Our intention is to help in a small way to move the web development community forward by pushing for newer CSS properties, fewer dependencies, and new technologies across more modern browsers.
+Our latest release, Bootstrap 5 (currently in development), focuses on improving v4’s codebase with as few major breaking changes as possible. We improved existing features and components, removed support for older browsers, dropped jQuery for regular JavaScript, and embraced more future-friendly technologies like CSS custom properties as part of our tooling.
+Get involved with Bootstrap development by opening an issue or submitting a pull request. Read our contributing guidelines for information on how we develop.
+ +An overview of the founding team and core contributors to Bootstrap.
+ + +Bootstrap is maintained by the founding team and a small group of invaluable core contributors, with the massive support and involvement of our community.
+ +Get involved with Bootstrap development by opening an issue or submitting a pull request. Read our contributing guidelines for information on how we develop.
+ +Links to community-translated Bootstrap documentation sites.
+ + +Community members have translated Bootstrap’s documentation into various languages. None are officially supported and they may not always be up to date.
+ +We don’t help organize or host translations, we just link to them.
+Finished a new or better translation? Open a pull request to add it to our list.
+ +Build vertically collapsing accordions in combination with our Collapse JavaScript plugin.
+ + +The accordion uses collapse internally to make it collapsible. To render an accordion that’s expanded, add the .open
class on the .accordion
.
prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Click the accordions below to expand/collapse the accordion content.
+.accordion-body
, though the transition does limit overflow.
+ .accordion-body
, though the transition does limit overflow.
+ .accordion-body
, though the transition does limit overflow.
+ <div class="accordion" id="accordionExample">
+ <div class="accordion-item">
+ <h2 class="accordion-header" id="headingOne">
+ <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
+ Accordion Item #1
+ </button>
+ </h2>
+ <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
+ <div class="accordion-body">
+ <strong>This is the first item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
+ </div>
+ </div>
+ </div>
+ <div class="accordion-item">
+ <h2 class="accordion-header" id="headingTwo">
+ <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
+ Accordion Item #2
+ </button>
+ </h2>
+ <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
+ <div class="accordion-body">
+ <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
+ </div>
+ </div>
+ </div>
+ <div class="accordion-item">
+ <h2 class="accordion-header" id="headingThree">
+ <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
+ Accordion Item #3
+ </button>
+ </h2>
+ <div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
+ <div class="accordion-body">
+ <strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
+ </div>
+ </div>
+ </div>
+</div>
Add .accordion-flush
to remove the default background-color
, some borders, and some rounded corners to render accordions edge-to-edge with their parent container.
<div class="accordion accordion-flush" id="accordionFlushExample">
+ <div class="accordion-item">
+ <h2 class="accordion-header" id="flush-headingOne">
+ <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseOne" aria-expanded="false" aria-controls="flush-collapseOne">
+ Accordion Item #1
+ </button>
+ </h2>
+ <div id="flush-collapseOne" class="accordion-collapse collapse" aria-labelledby="flush-headingOne" data-bs-parent="#accordionFlushExample">
+ <div class="accordion-body">Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.</div>
+ </div>
+ </div>
+ <div class="accordion-item">
+ <h2 class="accordion-header" id="flush-headingTwo">
+ <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseTwo" aria-expanded="false" aria-controls="flush-collapseTwo">
+ Accordion Item #2
+ </button>
+ </h2>
+ <div id="flush-collapseTwo" class="accordion-collapse collapse" aria-labelledby="flush-headingTwo" data-bs-parent="#accordionFlushExample">
+ <div class="accordion-body">Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.</div>
+ </div>
+ </div>
+ <div class="accordion-item">
+ <h2 class="accordion-header" id="flush-headingThree">
+ <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapseThree" aria-expanded="false" aria-controls="flush-collapseThree">
+ Accordion Item #3
+ </button>
+ </h2>
+ <div id="flush-collapseThree" class="accordion-collapse collapse" aria-labelledby="flush-headingThree" data-bs-parent="#accordionFlushExample">
+ <div class="accordion-body">Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.</div>
+ </div>
+ </div>
+</div>
Please read the collapse accessibility section for more information.
+ +Provide contextual feedback messages for typical user actions with the handful of available and flexible alert messages.
+ + +Alerts are available for any length of text, as well as an optional close button. For proper styling, use one of the eight required contextual classes (e.g., .alert-success
). For inline dismissal, use the alerts JavaScript plugin.
<div class="alert alert-primary" role="alert">
+ A simple primary alert—check it out!
+</div>
+<div class="alert alert-secondary" role="alert">
+ A simple secondary alert—check it out!
+</div>
+<div class="alert alert-success" role="alert">
+ A simple success alert—check it out!
+</div>
+<div class="alert alert-danger" role="alert">
+ A simple danger alert—check it out!
+</div>
+<div class="alert alert-warning" role="alert">
+ A simple warning alert—check it out!
+</div>
+<div class="alert alert-info" role="alert">
+ A simple info alert—check it out!
+</div>
+<div class="alert alert-light" role="alert">
+ A simple light alert—check it out!
+</div>
+<div class="alert alert-dark" role="alert">
+ A simple dark alert—check it out!
+</div>
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden
class.
+
Use the .alert-link
utility class to quickly provide matching colored links within any alert.
<div class="alert alert-primary" role="alert">
+ A simple primary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
+<div class="alert alert-secondary" role="alert">
+ A simple secondary alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
+<div class="alert alert-success" role="alert">
+ A simple success alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
+<div class="alert alert-danger" role="alert">
+ A simple danger alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
+<div class="alert alert-warning" role="alert">
+ A simple warning alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
+<div class="alert alert-info" role="alert">
+ A simple info alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
+<div class="alert alert-light" role="alert">
+ A simple light alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
+<div class="alert alert-dark" role="alert">
+ A simple dark alert with <a href="#" class="alert-link">an example link</a>. Give it a click if you like.
+</div>
Alerts can also contain additional HTML elements like headings, paragraphs and dividers.
+Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
+Whenever you need to, be sure to use margin utilities to keep things nice and tidy.
+<div class="alert alert-success" role="alert">
+ <h4 class="alert-heading">Well done!</h4>
+ <p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
+ <hr>
+ <p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
+</div>
Using the alert JavaScript plugin, it’s possible to dismiss any alert inline. Here’s how:
+.alert-dismissible
class, which adds extra padding to the right of the alert and positions the close button.data-bs-dismiss="alert"
attribute, which triggers the JavaScript functionality. Be sure to use the <button>
element with it for proper behavior across all devices..fade
and .show
classes.You can see this in action with a live demo:
+<div class="alert alert-warning alert-dismissible fade show" role="alert">
+ <strong>Holy guacamole!</strong> You should check in on some of those fields below.
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
+</div>
closed.bs.alert
event and programmatically sets focus()
to the most appropriate location in the page. If you’re planning to move focus to a non-interactive element that normally does not receive focus, make sure to add tabindex="-1"
to the element.
+Enable dismissal of an alert via JavaScript:
+var alertList = document.querySelectorAll('.alert')
+alertList.forEach(function (alert) {
+ new bootstrap.Alert(alert)
+})
+
Or with data
attributes on a button within the alert, as demonstrated above:
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
+
Note that closing an alert will remove it from the DOM.
+You can create an alert instance with the alert constructor, for example:
+var myAlert = document.getElementById('myAlert')
+var bsAlert = new bootstrap.Alert(myAlert)
+
This makes an alert listen for click events on descendant elements which have the data-bs-dismiss="alert"
attribute. (Not necessary when using the data-api’s auto-initialization.)
Method | +Description | +
---|---|
+ close
+ |
+
+ Closes an alert by removing it from the DOM. If the .fade and .show classes are present on the element, the alert will fade out before it is removed.
+ |
+
+ dispose
+ |
+ + Destroys an element's alert. (Removes stored data on the DOM element) + | +
+ getInstance
+ |
+
+ Static method which allows you to get the alert instance associated to a DOM element, you can use it like this: bootstrap.Alert.getInstance(alert)
+ |
+
var alertNode = document.querySelector('.alert')
+var alert = bootstrap.Alert.getInstance(alertNode)
+alert.close()
+
Bootstrap’s alert plugin exposes a few events for hooking into alert functionality.
+Event | +Description | +
---|---|
close.bs.alert |
+
+ Fires immediately when the close instance method is called.
+ |
+
closed.bs.alert |
+ + Fired when the alert has been closed and CSS transitions have completed. + | +
var myAlert = document.getElementById('myAlert')
+myAlert.addEventListener('closed.bs.alert', function () {
+ // do something, for instance, explicitly move focus to the most appropriate element,
+ // so it doesn't get lost/reset to the start of the page
+ // document.getElementById('...').focus()
+})
+
Documentation and examples for badges, our small count and labeling component.
+ + +Badges scale to match the size of the immediate parent element by using relative font sizing and em
units. As of v5, badges no longer have focus or hover styles for links.
<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>
Badges can be used as part of links or buttons to provide a counter.
+<button type="button" class="btn btn-primary">
+ Notifications <span class="badge bg-secondary">4</span>
+</button>
Note that depending on how they are used, badges may be confusing for users of screen readers and similar assistive technologies. While the styling of badges provides a visual cue as to their purpose, these users will simply be presented with the content of the badge. Depending on the specific situation, these badges may seem like random additional words or numbers at the end of a sentence, link, or button.
+Unless the context is clear (as with the “Notifications” example, where it is understood that the “4” is the number of notifications), consider including additional context with a visually hidden piece of additional text.
+<button type="button" class="btn btn-primary">
+ Profile <span class="badge bg-secondary">9</span>
+ <span class="visually-hidden">unread messages</span>
+</button>
Use our background utility classes to quickly change the appearance of a badge. Please note that when using Bootstrap’s default .bg-light
, you’ll likely need a text color utility like .text-dark
for proper styling. This is because background utilities do not set anything but background-color
.
<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 text-dark">Warning</span>
+<span class="badge bg-info text-dark">Info</span>
+<span class="badge bg-light text-dark">Light</span>
+<span class="badge bg-dark">Dark</span>
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden
class.
+
Use the .rounded-pill
utility class to make badges more rounded with a larger border-radius
.
<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 text-dark">Warning</span>
+<span class="badge rounded-pill bg-info text-dark">Info</span>
+<span class="badge rounded-pill bg-light text-dark">Light</span>
+<span class="badge rounded-pill bg-dark">Dark</span>
Indicate the current page’s location within a navigational hierarchy that automatically adds separators via CSS.
+ + +Use an ordered or unordered list with linked list items to create a minimally styled breadcrumb. Use our utilities to add additional styles as desired.
+<nav aria-label="breadcrumb">
+ <ol class="breadcrumb">
+ <li class="breadcrumb-item active" aria-current="page">Home</li>
+ </ol>
+</nav>
+
+<nav aria-label="breadcrumb">
+ <ol class="breadcrumb">
+ <li class="breadcrumb-item"><a href="#">Home</a></li>
+ <li class="breadcrumb-item active" aria-current="page">Library</li>
+ </ol>
+</nav>
+
+<nav aria-label="breadcrumb">
+ <ol class="breadcrumb">
+ <li class="breadcrumb-item"><a href="#">Home</a></li>
+ <li class="breadcrumb-item"><a href="#">Library</a></li>
+ <li class="breadcrumb-item active" aria-current="page">Data</li>
+ </ol>
+</nav>
Dividers are automatically added in CSS through ::before
and content
. They can be changed by modifying a local CSS custom property --bs-breadcrumb-divider
, or through the $breadcrumb-divider
Sass variable — and $breadcrumb-divider-flipped
for its RTL counterpart, if needed. We default to our Sass variable, which is set as a fallback to the custom property. This way, you get a global divider that you can override without recompiling CSS at any time.
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
+ <ol class="breadcrumb">
+ <li class="breadcrumb-item"><a href="#">Home</a></li>
+ <li class="breadcrumb-item active" aria-current="page">Library</li>
+ </ol>
+</nav>
When modifying via Sass, the quote function is required to generate the quotes around a string. For example, using >
as the divider, you can use this:
$breadcrumb-divider: quote(">");
+
It’s also possible to use an embedded SVG icon. Apply it via our CSS custom property, or use the Sass variable.
+<nav style="--bs-breadcrumb-divider: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='currentColor'/%3E%3C/svg%3E");" aria-label="breadcrumb">
+ <ol class="breadcrumb">
+ <li class="breadcrumb-item"><a href="#">Home</a></li>
+ <li class="breadcrumb-item active" aria-current="page">Library</li>
+ </ol>
+</nav>
$breadcrumb-divider: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='currentColor'/%3E%3C/svg%3E");
+
You can also remove the divider setting --bs-breadcrumb-divider: '';
(empty strings in CSS custom properties counts as a value), or setting the Sass variable to $breadcrumb-divider: none;
.
<nav style="--bs-breadcrumb-divider: '';" aria-label="breadcrumb">
+ <ol class="breadcrumb">
+ <li class="breadcrumb-item"><a href="#">Home</a></li>
+ <li class="breadcrumb-item active" aria-current="page">Library</li>
+ </ol>
+</nav>
$breadcrumb-divider: none;
+
Since breadcrumbs provide a navigation, it’s a good idea to add a meaningful label such as aria-label="breadcrumb"
to describe the type of navigation provided in the <nav>
element, as well as applying an aria-current="page"
to the last item of the set to indicate that it represents the current page.
For more information, see the WAI-ARIA Authoring Practices for the breadcrumb pattern.
+ +Group a series of buttons together on a single line or stack them in a vertical column.
+ + +Wrap a series of buttons with .btn
in .btn-group
.
<div class="btn-group" role="group" aria-label="Basic example">
+ <button type="button" class="btn btn-primary">Left</button>
+ <button type="button" class="btn btn-primary">Middle</button>
+ <button type="button" class="btn btn-primary">Right</button>
+</div>
role
and provide a labelIn order for assistive technologies (such as screen readers) to convey that a series of buttons is grouped, an appropriate role
attribute needs to be provided. For button groups, this would be role="group"
, while toolbars should have a role="toolbar"
.
In addition, groups and toolbars should be given an explicit label, as most assistive technologies will otherwise not announce them, despite the presence of the correct role attribute. In the examples provided here, we use aria-label
, but alternatives such as aria-labelledby
can also be used.
These classes can also be added to groups of links, as an alternative to the .nav
navigation components.
<div class="btn-group">
+ <a href="#" class="btn btn-primary active" aria-current="page">Active link</a>
+ <a href="#" class="btn btn-primary">Link</a>
+ <a href="#" class="btn btn-primary">Link</a>
+</div>
<div class="btn-group" role="group" aria-label="Basic mixed styles example">
+ <button type="button" class="btn btn-danger">Left</button>
+ <button type="button" class="btn btn-warning">Middle</button>
+ <button type="button" class="btn btn-success">Right</button>
+</div>
<div class="btn-group" role="group" aria-label="Basic outlined example">
+ <button type="button" class="btn btn-outline-primary">Left</button>
+ <button type="button" class="btn btn-outline-primary">Middle</button>
+ <button type="button" class="btn btn-outline-primary">Right</button>
+</div>
Combine button-like checkbox and radio toggle buttons into a seamless looking button group.
+<div class="btn-group" role="group" aria-label="Basic checkbox toggle button group">
+ <input type="checkbox" class="btn-check" id="btncheck1" autocomplete="off">
+ <label class="btn btn-outline-primary" for="btncheck1">Checkbox 1</label>
+
+ <input type="checkbox" class="btn-check" id="btncheck2" autocomplete="off">
+ <label class="btn btn-outline-primary" for="btncheck2">Checkbox 2</label>
+
+ <input type="checkbox" class="btn-check" id="btncheck3" autocomplete="off">
+ <label class="btn btn-outline-primary" for="btncheck3">Checkbox 3</label>
+</div>
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
+ <input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" checked>
+ <label class="btn btn-outline-primary" for="btnradio1">Radio 1</label>
+
+ <input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off">
+ <label class="btn btn-outline-primary" for="btnradio2">Radio 2</label>
+
+ <input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off">
+ <label class="btn btn-outline-primary" for="btnradio3">Radio 3</label>
+</div>
Combine sets of button groups into button toolbars for more complex components. Use utility classes as needed to space out groups, buttons, and more.
+<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
+ <div class="btn-group me-2" role="group" aria-label="First group">
+ <button type="button" class="btn btn-primary">1</button>
+ <button type="button" class="btn btn-primary">2</button>
+ <button type="button" class="btn btn-primary">3</button>
+ <button type="button" class="btn btn-primary">4</button>
+ </div>
+ <div class="btn-group me-2" role="group" aria-label="Second group">
+ <button type="button" class="btn btn-secondary">5</button>
+ <button type="button" class="btn btn-secondary">6</button>
+ <button type="button" class="btn btn-secondary">7</button>
+ </div>
+ <div class="btn-group" role="group" aria-label="Third group">
+ <button type="button" class="btn btn-info">8</button>
+ </div>
+</div>
Feel free to mix input groups with button groups in your toolbars. Similar to the example above, you’ll likely need some utilities though to space things properly.
+<div class="btn-toolbar mb-3" role="toolbar" aria-label="Toolbar with button groups">
+ <div class="btn-group me-2" role="group" aria-label="First group">
+ <button type="button" class="btn btn-outline-secondary">1</button>
+ <button type="button" class="btn btn-outline-secondary">2</button>
+ <button type="button" class="btn btn-outline-secondary">3</button>
+ <button type="button" class="btn btn-outline-secondary">4</button>
+ </div>
+ <div class="input-group">
+ <div class="input-group-text" id="btnGroupAddon">@</div>
+ <input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon">
+ </div>
+</div>
+
+<div class="btn-toolbar justify-content-between" role="toolbar" aria-label="Toolbar with button groups">
+ <div class="btn-group" role="group" aria-label="First group">
+ <button type="button" class="btn btn-outline-secondary">1</button>
+ <button type="button" class="btn btn-outline-secondary">2</button>
+ <button type="button" class="btn btn-outline-secondary">3</button>
+ <button type="button" class="btn btn-outline-secondary">4</button>
+ </div>
+ <div class="input-group">
+ <div class="input-group-text" id="btnGroupAddon2">@</div>
+ <input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon2">
+ </div>
+</div>
Instead of applying button sizing classes to every button in a group, just add .btn-group-*
to each .btn-group
, including each one when nesting multiple groups.
<div class="btn-group btn-group-lg" role="group" aria-label="...">...</div>
+<div class="btn-group" role="group" aria-label="...">...</div>
+<div class="btn-group btn-group-sm" role="group" aria-label="...">...</div>
+
Place a .btn-group
within another .btn-group
when you want dropdown menus mixed with a series of buttons.
<div class="btn-group" role="group" aria-label="Button group with nested dropdown">
+ <button type="button" class="btn btn-primary">1</button>
+ <button type="button" class="btn btn-primary">2</button>
+
+ <div class="btn-group" role="group">
+ <button id="btnGroupDrop1" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown
+ </button>
+ <ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
+ <li><a class="dropdown-item" href="#">Dropdown link</a></li>
+ <li><a class="dropdown-item" href="#">Dropdown link</a></li>
+ </ul>
+ </div>
+</div>
Make a set of buttons appear vertically stacked rather than horizontally. Split button dropdowns are not supported here.
+<div class="btn-group-vertical">
+ ...
+</div>
+
Use Bootstrap’s custom button styles for actions in forms, dialogs, and more with support for multiple sizes, states, and more.
+ + +Bootstrap includes several predefined button styles, each serving its own semantic purpose, with a few extras thrown in for more control.
+<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-danger">Danger</button>
+<button type="button" class="btn btn-warning">Warning</button>
+<button type="button" class="btn btn-info">Info</button>
+<button type="button" class="btn btn-light">Light</button>
+<button type="button" class="btn btn-dark">Dark</button>
+
+<button type="button" class="btn btn-link">Link</button>
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden
class.
+
If you don’t want the button text to wrap, you can add the .text-nowrap
class to the button. In Sass, you can set $btn-white-space: nowrap
to disable text wrapping for each button.
The .btn
classes are designed to be used with the <button>
element. However, you can also use these classes on <a>
or <input>
elements (though some browsers may apply a slightly different rendering).
When using button classes on <a>
elements that are used to trigger in-page functionality (like collapsing content), rather than linking to new pages or sections within the current page, these links should be given a role="button"
to appropriately convey their purpose to assistive technologies such as screen readers.
<a class="btn btn-primary" href="#" role="button">Link</a>
+<button class="btn btn-primary" type="submit">Button</button>
+<input class="btn btn-primary" type="button" value="Input">
+<input class="btn btn-primary" type="submit" value="Submit">
+<input class="btn btn-primary" type="reset" value="Reset">
In need of a button, but not the hefty background colors they bring? Replace the default modifier classes with the .btn-outline-*
ones to remove all background images and colors on any button.
<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-danger">Danger</button>
+<button type="button" class="btn btn-outline-warning">Warning</button>
+<button type="button" class="btn btn-outline-info">Info</button>
+<button type="button" class="btn btn-outline-light">Light</button>
+<button type="button" class="btn btn-outline-dark">Dark</button>
Fancy larger or smaller buttons? Add .btn-lg
or .btn-sm
for additional sizes.
<button type="button" class="btn btn-primary btn-lg">Large button</button>
+<button type="button" class="btn btn-secondary btn-lg">Large button</button>
<button type="button" class="btn btn-primary btn-sm">Small button</button>
+<button type="button" class="btn btn-secondary btn-sm">Small button</button>
Make buttons look inactive by adding the disabled
boolean attribute to any <button>
element. Disabled buttons have pointer-events: none
applied to, preventing hover and active states from triggering.
<button type="button" class="btn btn-lg btn-primary" disabled>Primary button</button>
+<button type="button" class="btn btn-secondary btn-lg" disabled>Button</button>
Disabled buttons using the <a>
element behave a bit different:
<a>
s don’t support the disabled
attribute, so you must add the .disabled
class to make it visually appear disabled.pointer-events
on anchor buttons.aria-disabled="true"
attribute to indicate the state of the element to assistive technologies.<a href="#" class="btn btn-primary btn-lg disabled" tabindex="-1" role="button" aria-disabled="true">Primary link</a>
+<a href="#" class="btn btn-secondary btn-lg disabled" tabindex="-1" role="button" aria-disabled="true">Link</a>
The .disabled
class uses pointer-events: none
to try to disable the link functionality of <a>
s, but that CSS property is not yet standardized. In addition, even in browsers that do support pointer-events: none
, keyboard navigation remains unaffected, meaning that sighted keyboard users and users of assistive technologies will still be able to activate these links. So to be safe, in addition to aria-disabled="true"
, also include a tabindex="-1"
attribute on these links to prevent them from receiving keyboard focus, and use custom JavaScript to disable their functionality altogether.
+
Create responsive stacks of full-width, “block buttons” like those in Bootstrap 4 with a mix of our display and gap utilities. By using utilities instead of button specific classes, we have much greater control over spacing, alignment, and responsive behaviors.
+<div class="d-grid gap-2">
+ <button class="btn btn-primary" type="button">Button</button>
+ <button class="btn btn-primary" type="button">Button</button>
+</div>
Here we create a responsive variation, starting with vertically stacked buttons until the md
breakpoint, where .d-md-block
replaces the .d-grid
class, thus nullifying the gap-2
utility. Resize your browser to see them change.
<div class="d-grid gap-2 d-md-block">
+ <button class="btn btn-primary" type="button">Button</button>
+ <button class="btn btn-primary" type="button">Button</button>
+</div>
You can adjust the width of your block buttons with grid column width classes. For example, for a half-width “block button”, use .col-6
. Center it horizontally with .mx-auto
, too.
<div class="d-grid gap-2 col-6 mx-auto">
+ <button class="btn btn-primary" type="button">Button</button>
+ <button class="btn btn-primary" type="button">Button</button>
+</div>
Additional utilities can be used to adjust the alignment of buttons when horizontal. Here we’ve taken our previous responsive example and added some flex utilities and a margin utility on the button to right align the buttons when they’re no longer stacked.
+<div class="d-grid gap-2 d-md-flex justify-content-md-end">
+ <button class="btn btn-primary me-md-2" type="button">Button</button>
+ <button class="btn btn-primary" type="button">Button</button>
+</div>
The button plugin allows you to create simple on/off toggle buttons.
+Add data-bs-toggle="button"
to toggle a button’s active
state. If you’re pre-toggling a button, you must manually add the .active
class and aria-pressed="true"
to ensure that it is conveyed appropriately to assistive technologies.
<button type="button" class="btn btn-primary" data-bs-toggle="button" autocomplete="off">Toggle button</button>
+<button type="button" class="btn btn-primary active" data-bs-toggle="button" autocomplete="off" aria-pressed="true">Active toggle button</button>
+<button type="button" class="btn btn-primary" disabled data-bs-toggle="button" autocomplete="off">Disabled toggle button</button>
<a href="#" class="btn btn-primary" role="button" data-bs-toggle="button">Toggle link</a>
+<a href="#" class="btn btn-primary active" role="button" data-bs-toggle="button" aria-pressed="true">Active toggle link</a>
+<a href="#" class="btn btn-primary disabled" tabindex="-1" aria-disabled="true" role="button" data-bs-toggle="button">Disabled toggle link</a>
You can create a button instance with the button constructor, for example:
+var button = document.getElementById('myButton')
+var bsButton = new bootstrap.Button(button)
+
Method | +Description | +
---|---|
+ toggle
+ |
+ + Toggles push state. Gives the button the appearance that it has been activated. + | +
+ dispose
+ |
+ + Destroys an element's button. (Removes stored data on the DOM element) + | +
For example, to toggle all buttons
+var buttons = document.querySelectorAll('.btn')
+buttons.forEach(function (button) {
+ var button = new bootstrap.Button(button)
+ button.toggle()
+})
+
Bootstrap’s cards provide a flexible and extensible content container with multiple variants and options.
+ + +A card is a flexible and extensible content container. It includes options for headers and footers, a wide variety of content, contextual background colors, and powerful display options. If you’re familiar with Bootstrap 3, cards replace our old panels, wells, and thumbnails. Similar functionality to those components is available as modifier classes for cards.
+Cards are built with as little markup and styles as possible, but still manage to deliver a ton of control and customization. Built with flexbox, they offer easy alignment and mix well with other Bootstrap components. They have no margin
by default, so use spacing utilities as needed.
Below is an example of a basic card with mixed content and a fixed width. Cards have no fixed width to start, so they’ll naturally fill the full width of its parent element. This is easily customized with our various sizing options.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+ Go somewhere +<div class="card" style="width: 18rem;">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
Cards support a wide variety of content, including images, text, list groups, links, and more. Below are examples of what’s supported.
+The building block of a card is the .card-body
. Use it whenever you need a padded section within a card.
<div class="card">
+ <div class="card-body">
+ This is some text within a card body.
+ </div>
+</div>
Card titles are used by adding .card-title
to a <h*>
tag. In the same way, links are added and placed next to each other by adding .card-link
to an <a>
tag.
Subtitles are used by adding a .card-subtitle
to a <h*>
tag. If the .card-title
and the .card-subtitle
items are placed in a .card-body
item, the card title and subtitle are aligned nicely.
Some quick example text to build on the card title and make up the bulk of the card's content.
+ Card link + Another link +<div class="card" style="width: 18rem;">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ <a href="#" class="card-link">Card link</a>
+ <a href="#" class="card-link">Another link</a>
+ </div>
+</div>
.card-img-top
places an image to the top of the card. With .card-text
, text can be added to the card. Text within .card-text
can also be styled with the standard HTML tags.
Some quick example text to build on the card title and make up the bulk of the card's content.
+<div class="card" style="width: 18rem;">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
Create lists of content in a card with a flush list group.
+<div class="card" style="width: 18rem;">
+ <ul class="list-group list-group-flush">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+ </ul>
+</div>
<div class="card" style="width: 18rem;">
+ <div class="card-header">
+ Featured
+ </div>
+ <ul class="list-group list-group-flush">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+ </ul>
+</div>
<div class="card" style="width: 18rem;">
+ <ul class="list-group list-group-flush">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+ </ul>
+ <div class="card-footer">
+ Card footer
+ </div>
+</div>
Mix and match multiple content types to create the card you need, or throw everything in there. Shown below are image styles, blocks, text styles, and a list group—all wrapped in a fixed-width card.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+<div class="card" style="width: 18rem;">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+ <ul class="list-group list-group-flush">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+ </ul>
+ <div class="card-body">
+ <a href="#" class="card-link">Card link</a>
+ <a href="#" class="card-link">Another link</a>
+ </div>
+</div>
Add an optional header and/or footer within a card.
+With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="card">
+ <div class="card-header">
+ Featured
+ </div>
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
Card headers can be styled by adding .card-header
to <h*>
elements.
With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="card">
+ <h5 class="card-header">Featured</h5>
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.
+ +
<div class="card">
+ <div class="card-header">
+ Quote
+ </div>
+ <div class="card-body">
+ <blockquote class="blockquote mb-0">
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
+ <footer class="blockquote-footer">Someone famous in <cite title="Source Title">Source Title</cite></footer>
+ </blockquote>
+ </div>
+</div>
With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="card text-center">
+ <div class="card-header">
+ Featured
+ </div>
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+ <div class="card-footer text-muted">
+ 2 days ago
+ </div>
+</div>
Cards assume no specific width
to start, so they’ll be 100% wide unless otherwise stated. You can change this as needed with custom CSS, grid classes, grid Sass mixins, or utilities.
Using the grid, wrap cards in columns and rows as needed.
+With supporting text below as a natural lead-in to additional content.
+ Go somewhere +With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="row">
+ <div class="col-sm-6">
+ <div class="card">
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+ </div>
+ </div>
+ <div class="col-sm-6">
+ <div class="card">
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+ </div>
+ </div>
+</div>
Use our handful of available sizing utilities to quickly set a card’s width.
+<div class="card w-75">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Button</a>
+ </div>
+</div>
+
+<div class="card w-50">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Button</a>
+ </div>
+</div>
Use custom CSS in your stylesheets or as inline styles to set a width.
+With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="card" style="width: 18rem;">
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
You can quickly change the text alignment of any card—in its entirety or specific parts—with our text align classes.
+With supporting text below as a natural lead-in to additional content.
+ Go somewhere +With supporting text below as a natural lead-in to additional content.
+ Go somewhere +With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="card" style="width: 18rem;">
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
+
+<div class="card text-center" style="width: 18rem;">
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
+
+<div class="card text-end" style="width: 18rem;">
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
Add some navigation to a card’s header (or block) with Bootstrap’s nav components.
+With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="card text-center">
+ <div class="card-header">
+ <ul class="nav nav-tabs card-header-tabs">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="true" href="#">Active</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Link</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+ </ul>
+ </div>
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
With supporting text below as a natural lead-in to additional content.
+ Go somewhere +<div class="card text-center">
+ <div class="card-header">
+ <ul class="nav nav-pills card-header-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 disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+ </ul>
+ </div>
+ <div class="card-body">
+ <h5 class="card-title">Special title treatment</h5>
+ <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
+ <a href="#" class="btn btn-primary">Go somewhere</a>
+ </div>
+</div>
Cards include a few options for working with images. Choose from appending “image caps” at either end of a card, overlaying images with card content, or simply embedding the image in a card.
+Similar to headers and footers, cards can include top and bottom “image caps”—images at the top or bottom of a card.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+Last updated 3 mins ago
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+Last updated 3 mins ago
+<div class="card mb-3">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
+ </div>
+</div>
+<div class="card">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
+ </div>
+ <img src="..." class="card-img-bottom" alt="...">
+</div>
Turn an image into a card background and overlay your card’s text. Depending on the image, you may or may not need additional styles or utilities.
+<div class="card bg-dark text-white">
+ <img src="..." class="card-img" alt="...">
+ <div class="card-img-overlay">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ <p class="card-text">Last updated 3 mins ago</p>
+ </div>
+</div>
Using a combination of grid and utility classes, cards can be made horizontal in a mobile-friendly and responsive way. In the example below, we remove the grid gutters with .g-0
and use .col-md-*
classes to make the card horizontal at the md
breakpoint. Further adjustments may be needed depending on your card content.
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+Last updated 3 mins ago
+<div class="card mb-3" style="max-width: 540px;">
+ <div class="row g-0">
+ <div class="col-md-4">
+ <img src="..." alt="...">
+ </div>
+ <div class="col-md-8">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
+ </div>
+ </div>
+ </div>
+</div>
Cards include various options for customizing their backgrounds, borders, and color.
+Use text and background utilities to change the appearance of a card.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+<div class="card text-white bg-primary mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Primary card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card text-white bg-secondary mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Secondary card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card text-white bg-success mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Success card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card text-white bg-danger mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Danger card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card text-dark bg-warning mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Warning card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card text-dark bg-info mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Info card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card text-dark bg-light mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Light card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card text-white bg-dark mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Dark card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden
class.
+
Use border utilities to change just the border-color
of a card. Note that you can put .text-{color}
classes on the parent .card
or a subset of the card’s contents as shown below.
Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+Some quick example text to build on the card title and make up the bulk of the card's content.
+<div class="card border-primary mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body text-primary">
+ <h5 class="card-title">Primary card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card border-secondary mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body text-secondary">
+ <h5 class="card-title">Secondary card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card border-success mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body text-success">
+ <h5 class="card-title">Success card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card border-danger mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body text-danger">
+ <h5 class="card-title">Danger card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card border-warning mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Warning card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card border-info mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Info card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card border-light mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body">
+ <h5 class="card-title">Light card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
+<div class="card border-dark mb-3" style="max-width: 18rem;">
+ <div class="card-header">Header</div>
+ <div class="card-body text-dark">
+ <h5 class="card-title">Dark card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+</div>
You can also change the borders on the card header and footer as needed, and even remove their background-color
with .bg-transparent
.
Some quick example text to build on the card title and make up the bulk of the card's content.
+<div class="card border-success mb-3" style="max-width: 18rem;">
+ <div class="card-header bg-transparent border-success">Header</div>
+ <div class="card-body text-success">
+ <h5 class="card-title">Success card title</h5>
+ <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
+ </div>
+ <div class="card-footer bg-transparent border-success">Footer</div>
+</div>
In addition to styling the content within cards, Bootstrap includes a few options for laying out series of cards. For the time being, these layout options are not yet responsive.
+Use card groups to render cards as a single, attached element with equal width and height columns. Card groups start off stacked and use display: flex;
to become attached with uniform dimensions starting at the sm
breakpoint.
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+Last updated 3 mins ago
+This card has supporting text below as a natural lead-in to additional content.
+Last updated 3 mins ago
+This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
+Last updated 3 mins ago
+<div class="card-group">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
+ </div>
+ </div>
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
+ <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
+ </div>
+ </div>
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
+ <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
+ </div>
+ </div>
+</div>
When using card groups with footers, their content will automatically line up.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This card has supporting text below as a natural lead-in to additional content.
+This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
+<div class="card-group">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ <div class="card-footer">
+ <small class="text-muted">Last updated 3 mins ago</small>
+ </div>
+ </div>
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
+ </div>
+ <div class="card-footer">
+ <small class="text-muted">Last updated 3 mins ago</small>
+ </div>
+ </div>
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
+ </div>
+ <div class="card-footer">
+ <small class="text-muted">Last updated 3 mins ago</small>
+ </div>
+ </div>
+</div>
Use the Bootstrap grid system and its .row-cols
classes to control how many grid columns (wrapped around your cards) you show per row. For example, here’s .row-cols-1
laying out the cards on one column, and .row-cols-md-2
splitting four cards to equal width across multiple rows, from the medium breakpoint up.
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a longer card with supporting text below as a natural lead-in to additional content.
+This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+<div class="row row-cols-1 row-cols-md-2 g-4">
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+</div>
Change it to .row-cols-3
and you’ll see the fourth card wrap.
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a longer card with supporting text below as a natural lead-in to additional content.
+This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+<div class="row row-cols-1 row-cols-md-3 g-4">
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+</div>
When you need equal height, add .h-100
to the cards. If you want equal heights by default, you can set $card-height: 100%
in Sass.
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This is a short card.
+This is a longer card with supporting text below as a natural lead-in to additional content.
+This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+<div class="row row-cols-1 row-cols-md-3 g-4">
+ <div class="col">
+ <div class="card h-100">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card h-100">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a short card.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card h-100">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card h-100">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ </div>
+ </div>
+</div>
Just like with card groups, card footers will automatically line up.
+This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+This card has supporting text below as a natural lead-in to additional content.
+This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.
+<div class="row row-cols-1 row-cols-md-3 g-4">
+ <div class="col">
+ <div class="card h-100">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
+ </div>
+ <div class="card-footer">
+ <small class="text-muted">Last updated 3 mins ago</small>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card h-100">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
+ </div>
+ <div class="card-footer">
+ <small class="text-muted">Last updated 3 mins ago</small>
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="card h-100">
+ <img src="..." class="card-img-top" alt="...">
+ <div class="card-body">
+ <h5 class="card-title">Card title</h5>
+ <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p>
+ </div>
+ <div class="card-footer">
+ <small class="text-muted">Last updated 3 mins ago</small>
+ </div>
+ </div>
+ </div>
+</div>
In v4
we used a CSS-only technique to mimic the behavior of Masonry-like columns, but this technique came with lots of unpleasant side effects. If you want to have this type of layout in v5
, you can just make use of Masonry plugin. Masonry is not included in Bootstrap, but we’ve made a demo example to help you get started.
A slideshow component for cycling through elements—images or slides of text—like a carousel.
+ + +The carousel is a slideshow for cycling through a series of content, built with CSS 3D transforms and a bit of JavaScript. It works with a series of images, text, or custom markup. It also includes support for previous/next controls and indicators.
+In browsers where the Page Visibility API is supported, the carousel will avoid sliding when the webpage is not visible to the user (such as when the browser tab is inactive, the browser window is minimized, etc.).
+prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Please be aware that nested carousels are not supported, and carousels are generally not compliant with accessibility standards.
+Carousels don’t automatically normalize slide dimensions. As such, you may need to use additional utilities or custom styles to appropriately size content. While carousels support previous/next controls and indicators, they’re not explicitly required. Add and customize as you see fit.
+The .active
class needs to be added to one of the slides otherwise the carousel will not be visible. Also be sure to set a unique id on the .carousel
for optional controls, especially if you’re using multiple carousels on a single page. Control and indicator elements must have a data-bs-target
attribute (or href
for links) that matches the id of the .carousel
element.
Here’s a carousel with slides only. Note the presence of the .d-block
and .w-100
on carousel images to prevent browser default image alignment.
<div id="carouselExampleSlidesOnly" class="carousel slide" data-bs-ride="carousel">
+ <div class="carousel-inner">
+ <div class="carousel-item active">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ </div>
+</div>
Adding in the previous and next controls:
+<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
+ <div class="carousel-inner">
+ <div class="carousel-item active">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ </div>
+ <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-bs-slide="prev">
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Previous</span>
+ </a>
+ <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-bs-slide="next">
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Next</span>
+ </a>
+</div>
You can also add the indicators to the carousel, alongside the controls, too.
+<div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
+ <ol class="carousel-indicators">
+ <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active"></li>
+ <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1"></li>
+ <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2"></li>
+ </ol>
+ <div class="carousel-inner">
+ <div class="carousel-item active">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ </div>
+ <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-bs-slide="prev">
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Previous</span>
+ </a>
+ <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-bs-slide="next">
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Next</span>
+ </a>
+</div>
Add captions to your slides easily with the .carousel-caption
element within any .carousel-item
. They can be easily hidden on smaller viewports, as shown below, with optional display utilities. We hide them initially with .d-none
and bring them back on medium-sized devices with .d-md-block
.
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
+ <ol class="carousel-indicators">
+ <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active"></li>
+ <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1"></li>
+ <li data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2"></li>
+ </ol>
+ <div class="carousel-inner">
+ <div class="carousel-item active">
+ <img src="..." class="d-block w-100" alt="...">
+ <div class="carousel-caption d-none d-md-block">
+ <h5>First slide label</h5>
+ <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
+ </div>
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ <div class="carousel-caption d-none d-md-block">
+ <h5>Second slide label</h5>
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
+ </div>
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ <div class="carousel-caption d-none d-md-block">
+ <h5>Third slide label</h5>
+ <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
+ </div>
+ </div>
+ </div>
+ <a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-bs-slide="prev">
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Previous</span>
+ </a>
+ <a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-bs-slide="next">
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Next</span>
+ </a>
+</div>
Add .carousel-fade
to your carousel to animate slides with a fade transition instead of a slide.
<div id="carouselExampleFade" class="carousel slide carousel-fade" data-bs-ride="carousel">
+ <div class="carousel-inner">
+ <div class="carousel-item active">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ </div>
+ <a class="carousel-control-prev" href="#carouselExampleFade" role="button" data-bs-slide="prev">
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Previous</span>
+ </a>
+ <a class="carousel-control-next" href="#carouselExampleFade" role="button" data-bs-slide="next">
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Next</span>
+ </a>
+</div>
.carousel-item
intervalAdd data-bs-interval=""
to a .carousel-item
to change the amount of time to delay between automatically cycling to the next item.
<div id="carouselExampleInterval" class="carousel slide" data-bs-ride="carousel">
+ <div class="carousel-inner">
+ <div class="carousel-item active" data-bs-interval="10000">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item" data-bs-interval="2000">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ </div>
+ </div>
+ <a class="carousel-control-prev" href="#carouselExampleInterval" role="button" data-bs-slide="prev">
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Previous</span>
+ </a>
+ <a class="carousel-control-next" href="#carouselExampleInterval" role="button" data-bs-slide="next">
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Next</span>
+ </a>
+</div>
Add .carousel-dark
to the .carousel
for darker controls, indicators, and captions. Controls have been inverted from their default white fill with the filter
CSS property. Captions and controls have additional Sass variables that customize the color
and background-color
.
<div id="carouselExampleDark" class="carousel carousel-dark slide" data-bs-ride="carousel">
+ <ol class="carousel-indicators">
+ <li data-bs-target="#carouselExampleDark" data-bs-slide-to="0" class="active"></li>
+ <li data-bs-target="#carouselExampleDark" data-bs-slide-to="1"></li>
+ <li data-bs-target="#carouselExampleDark" data-bs-slide-to="2"></li>
+ </ol>
+ <div class="carousel-inner">
+ <div class="carousel-item active" data-bs-interval="10000">
+ <img src="..." class="d-block w-100" alt="...">
+ <div class="carousel-caption d-none d-md-block">
+ <h5>First slide label</h5>
+ <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
+ </div>
+ </div>
+ <div class="carousel-item" data-bs-interval="2000">
+ <img src="..." class="d-block w-100" alt="...">
+ <div class="carousel-caption d-none d-md-block">
+ <h5>Second slide label</h5>
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
+ </div>
+ </div>
+ <div class="carousel-item">
+ <img src="..." class="d-block w-100" alt="...">
+ <div class="carousel-caption d-none d-md-block">
+ <h5>Third slide label</h5>
+ <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
+ </div>
+ </div>
+ </div>
+ <a class="carousel-control-prev" href="#carouselExampleDark" role="button" data-bs-slide="prev">
+ <span class="carousel-control-prev-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Previous</span>
+ </a>
+ <a class="carousel-control-next" href="#carouselExampleDark" role="button" data-bs-slide="next">
+ <span class="carousel-control-next-icon" aria-hidden="true"></span>
+ <span class="visually-hidden">Next</span>
+ </a>
+</div>
Use data attributes to easily control the position of the carousel. data-bs-slide
accepts the keywords prev
or next
, which alters the slide position relative to its current position. Alternatively, use data-bs-slide-to
to pass a raw slide index to the carousel data-bs-slide-to="2"
, which shifts the slide position to a particular index beginning with 0
.
The data-bs-ride="carousel"
attribute is used to mark a carousel as animating starting at page load. If you don’t use data-bs-ride="carousel"
to initialize your carousel, you have to initialize it yourself. It cannot be used in combination with (redundant and unnecessary) explicit JavaScript initialization of the same carousel.
Call carousel manually with:
+var myCarousel = document.querySelector('#myCarousel')
+var carousel = new bootstrap.Carousel(myCarousel)
+
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-interval=""
.
Name | +Type | +Default | +Description | +
---|---|---|---|
interval |
+ number | +5000 |
+ The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle. | +
keyboard |
+ boolean | +true |
+ Whether the carousel should react to keyboard events. | +
pause |
+ string | boolean | +"hover" |
+ If set to On touch-enabled devices, when set to |
+
slide |
+ string | boolean | +false |
+ Autoplays the carousel after the user manually cycles the first item. If "carousel", autoplays the carousel on load. | +
wrap |
+ boolean | +true |
+ Whether the carousel should cycle continuously or have hard stops. | +
touch |
+ boolean | +true |
+ Whether the carousel should support left/right swipe interactions on touchscreen devices. | +
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
+ + +You can create a carousel instance with the carousel constructor, for example, to initialize with additional options and start cycling through items:
+var myCarousel = document.querySelector('#myCarousel')
+var carousel = new bootstrap.Carousel(myCarousel, {
+ interval: 2000,
+ wrap: false
+})
+
Method | +Description | +
---|---|
cycle |
+ Cycles through the carousel items from left to right. | +
pause |
+ Stops the carousel from cycling through items. | +
prev |
+ Cycles to the previous item. Returns to the caller before the previous item has been shown (e.g., before the slid.bs.carousel event occurs). |
+
next |
+ Cycles to the next item. Returns to the caller before the next item has been shown (e.g., before the slid.bs.carousel event occurs). |
+
nextWhenVisible |
+ Don't cycle carousel to next when the page isn't visible or the carousel or its parent isn't visible. Returns to the caller before the target item has been shown + |
to |
+ Cycles the carousel to a particular frame (0 based, similar to an array). Returns to the caller before the target item has been shown (e.g., before the slid.bs.carousel event occurs). |
+
dispose |
+ Destroys an element's carousel. (Removes stored data on the DOM element) | +
getInstance |
+ Static method which allows you to get the carousel instance associated with a DOM element. | +
Bootstrap’s carousel class exposes two events for hooking into carousel functionality. Both events have the following additional properties:
+direction
: The direction in which the carousel is sliding (either "left"
or "right"
).relatedTarget
: The DOM element that is being slid into place as the active item.from
: The index of the current itemto
: The index of the next itemAll carousel events are fired at the carousel itself (i.e. at the <div class="carousel">
).
Event type | +Description | +
---|---|
slide.bs.carousel |
+ Fires immediately when the slide instance method is invoked. |
+
slid.bs.carousel |
+ Fired when the carousel has completed its slide transition. | +
var myCarousel = document.getElementById('myCarousel')
+
+myCarousel.addEventListener('slide.bs.carousel', function () {
+ // do something...
+})
+
The transition duration of .carousel-item
can be changed with the $carousel-transition
Sass variable before compiling or custom styles if you’re using the compiled CSS. If multiple transitions are applied, make sure the transform transition is defined first (eg. transition: transform 2s ease, opacity .5s ease-out
).
A generic close button for dismissing content like modals and alerts.
+ + +Provide an option to dismiss or close a component with .btn-close
. Default styling is limited, but highly customizable. Modify the Sass variables to replace the default background-image
. Be sure to include text for screen readers, as we’ve done with aria-label
.
<button type="button" class="btn-close" aria-label="Close"></button>
Disabled close buttons change their opacity
. We’ve also applied pointer-events: none
and user-select: none
to preventing hover and active states from triggering.
<button type="button" class="btn-close" disabled aria-label="Close"></button>
Change the default .btn-close
to be white with the .btn-close-white
class. This class uses the filter
property to invert the background-image
.
<button type="button" class="btn-close btn-close-white" aria-label="Close"></button>
+<button type="button" class="btn-close btn-close-white" disabled aria-label="Close"></button>
Toggle the visibility of content across your project with a few classes and our JavaScript plugins.
+ + +The collapse JavaScript plugin is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height
from its current value to 0
. Given how CSS handles animations, you cannot use padding
on a .collapse
element. Instead, use the class as an independent wrapping element.
prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Click the buttons below to show and hide another element via class changes:
+.collapse
hides content.collapsing
is applied during transitions.collapse.show
shows contentYou can use a link with the href
attribute, or a button with the data-bs-target
attribute. In both cases, the data-bs-toggle="collapse"
is required.
+ + Link with href + + +
+<p>
+ <a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
+ Link with href
+ </a>
+ <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
+ Button with data-bs-target
+ </button>
+</p>
+<div class="collapse" id="collapseExample">
+ <div class="card card-body">
+ Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
+ </div>
+</div>
A <button>
or <a>
can show and hide multiple elements by referencing them with a selector in its href
or data-bs-target
attribute.
+Multiple <button>
or <a>
can show and hide an element if they each reference it with their href
or data-bs-target
attribute
+ Toggle first element + + +
+<p>
+ <a class="btn btn-primary" data-bs-toggle="collapse" href="#multiCollapseExample1" role="button" aria-expanded="false" aria-controls="multiCollapseExample1">Toggle first element</a>
+ <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#multiCollapseExample2" aria-expanded="false" aria-controls="multiCollapseExample2">Toggle second element</button>
+ <button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target=".multi-collapse" aria-expanded="false" aria-controls="multiCollapseExample1 multiCollapseExample2">Toggle both elements</button>
+</p>
+<div class="row">
+ <div class="col">
+ <div class="collapse multi-collapse" id="multiCollapseExample1">
+ <div class="card card-body">
+ Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
+ </div>
+ </div>
+ </div>
+ <div class="col">
+ <div class="collapse multi-collapse" id="multiCollapseExample2">
+ <div class="card card-body">
+ Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
+ </div>
+ </div>
+ </div>
+</div>
Be sure to add aria-expanded
to the control element. This attribute explicitly conveys the current state of the collapsible element tied to the control to screen readers and similar assistive technologies. If the collapsible element is closed by default, the attribute on the control element should have a value of aria-expanded="false"
. If you’ve set the collapsible element to be open by default using the show
class, set aria-expanded="true"
on the control instead. The plugin will automatically toggle this attribute on the control based on whether or not the collapsible element has been opened or closed (via JavaScript, or because the user triggered another control element also tied to the same collapsible element). If the control element’s HTML element is not a button (e.g., an <a>
or <div>
), the attribute role="button"
should be added to the element.
If your control element is targeting a single collapsible element – i.e. the data-bs-target
attribute is pointing to an id
selector – you should add the aria-controls
attribute to the control element, containing the id
of the collapsible element. Modern screen readers and similar assistive technologies make use of this attribute to provide users with additional shortcuts to navigate directly to the collapsible element itself.
Note that Bootstrap’s current implementation does not cover the various optional keyboard interactions described in the WAI-ARIA Authoring Practices 1.1 accordion pattern - you will need to include these yourself with custom JavaScript.
+The collapse plugin utilizes a few classes to handle the heavy lifting:
+.collapse
hides the content.collapse.show
shows the content.collapsing
is added when the transition starts, and removed when it finishesThese classes can be found in _transitions.scss
.
Just add data-bs-toggle="collapse"
and a data-bs-target
to the element to automatically assign control of one or more collapsible elements. The data-bs-target
attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse
to the collapsible element. If you’d like it to default open, add the additional class show
.
To add accordion-like group management to a collapsible area, add the data attribute data-bs-parent="#selector"
. Refer to the demo to see this in action.
Enable manually with:
+var collapseElementList = [].slice.call(document.querySelectorAll('.collapse'))
+var collapseList = collapseElementList.map(function (collapseEl) {
+ return new bootstrap.Collapse(collapseEl)
+})
+
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-parent=""
.
Name | +Type | +Default | +Description | +
---|---|---|---|
parent |
+ selector | jQuery object | DOM element | +false |
+ If parent is provided, then all collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior - this is dependent on the card class). The attribute has to be set on the target collapsible area. |
+
toggle |
+ boolean | +true |
+ Toggles the collapsible element on invocation | +
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
+ + +Activates your content as a collapsible element. Accepts an optional options object
.
You can create a collapse instance with the constructor, for example:
+var myCollapse = document.getElementById('myCollapse')
+var bsCollapse = new bootstrap.Collapse(myCollapse, {
+ toggle: false
+})
+
Method | +Description | +
---|---|
toggle |
+ Toggles a collapsible element to shown or hidden. Returns to the caller before the collapsible element has actually been shown or hidden (i.e. before the shown.bs.collapse or hidden.bs.collapse event occurs). |
+
show |
+ Shows a collapsible element. Returns to the caller before the collapsible element has actually been shown (e.g., before the shown.bs.collapse event occurs). |
+
hide |
+ Hides a collapsible element. Returns to the caller before the collapsible element has actually been hidden (e.g., before the hidden.bs.collapse event occurs). |
+
dispose |
+ Destroys an element's collapse. (Removes stored data on the DOM element) | +
getInstance |
+ Static method which allows you to get the collapse instance associated with a DOM element. | +
Bootstrap’s collapse class exposes a few events for hooking into collapse functionality.
+Event type | +Description | +
---|---|
show.bs.collapse |
+ This event fires immediately when the show instance method is called. |
+
shown.bs.collapse |
+ This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete). | +
hide.bs.collapse |
+ This event is fired immediately when the hide method has been called. |
+
hidden.bs.collapse |
+ This event is fired when a collapse element has been hidden from the user (will wait for CSS transitions to complete). | +
var myCollapsible = document.getElementById('myCollapsible')
+myCollapsible.addEventListener('hidden.bs.collapse', function () {
+ // do something...
+})
+
Toggle contextual overlays for displaying lists of links and more with the Bootstrap dropdown plugin.
+ + +Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They’re made interactive with the included Bootstrap dropdown JavaScript plugin. They’re toggled by clicking, not by hovering; this is an intentional design decision.
+Dropdowns are built on a third party library, Popper, which provides dynamic positioning and viewport detection. Be sure to include popper.min.js before Bootstrap’s JavaScript or use bootstrap.bundle.min.js
/ bootstrap.bundle.js
which contains Popper. Popper isn’t used to position dropdowns in navbars though as dynamic positioning isn’t required.
The WAI ARIA standard defines an actual role="menu"
widget, but this is specific to application-like menus which trigger actions or functions. ARIA menus can only contain menu items, checkbox menu items, radio button menu items, radio button groups, and sub-menus.
Bootstrap’s dropdowns, on the other hand, are designed to be generic and applicable to a variety of situations and markup structures. For instance, it is possible to create dropdowns that contain additional inputs and form controls, such as search fields or login forms. For this reason, Bootstrap does not expect (nor automatically add) any of the role
and aria-
attributes required for true ARIA menus. Authors will have to include these more specific attributes themselves.
However, Bootstrap does add built-in support for most standard keyboard menu interactions, such as the ability to move through individual .dropdown-item
elements using the cursor keys and close the menu with the ESC key.
Wrap the dropdown’s toggle (your button or link) and the dropdown menu within .dropdown
, or another element that declares position: relative;
. Dropdowns can be triggered from <a>
or <button>
elements to better fit your potential needs. The examples shown here use semantic <ul>
elements where appropriate, but custom markup is supported.
Any single .btn
can be turned into a dropdown toggle with some markup changes. Here’s how you can put them to work with either <button>
elements:
<div class="dropdown">
+ <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown button
+ </button>
+ <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ </ul>
+</div>
And with <a>
elements:
<div class="dropdown">
+ <a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown link
+ </a>
+
+ <ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ </ul>
+</div>
The best part is you can do this with any button variant, too:
+<!-- Example single danger button -->
+<div class="btn-group">
+ <button type="button" class="btn btn-danger dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
+ Action
+ </button>
+ <ul class="dropdown-menu">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Separated link</a></li>
+ </ul>
+</div>
+
Similarly, create split button dropdowns with virtually the same markup as single button dropdowns, but with the addition of .dropdown-toggle-split
for proper spacing around the dropdown caret.
We use this extra class to reduce the horizontal padding
on either side of the caret by 25% and remove the margin-left
that’s added for regular button dropdowns. Those extra changes keep the caret centered in the split button and provide a more appropriately sized hit area next to the main button.
<!-- Example split danger button -->
+<div class="btn-group">
+ <button type="button" class="btn btn-danger">Action</button>
+ <button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
+ <span class="visually-hidden">Toggle Dropdown</span>
+ </button>
+ <ul class="dropdown-menu">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Separated link</a></li>
+ </ul>
+</div>
+
Button dropdowns work with buttons of all sizes, including default and split dropdown buttons.
+<!-- Large button groups (default and split) -->
+<div class="btn-group">
+ <button class="btn btn-secondary btn-lg dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
+ Large button
+ </button>
+ <ul class="dropdown-menu">
+ ...
+ </ul>
+</div>
+<div class="btn-group">
+ <button class="btn btn-secondary btn-lg" type="button">
+ Large split button
+ </button>
+ <button type="button" class="btn btn-lg btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
+ <span class="visually-hidden">Toggle Dropdown</span>
+ </button>
+ <ul class="dropdown-menu">
+ ...
+ </ul>
+</div>
+
<div class="btn-group">
+ <button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
+ Small button
+ </button>
+ <ul class="dropdown-menu">
+ ...
+ </ul>
+</div>
+<div class="btn-group">
+ <button class="btn btn-secondary btn-sm" type="button">
+ Small split button
+ </button>
+ <button type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
+ <span class="visually-hidden">Toggle Dropdown</span>
+ </button>
+ <ul class="dropdown-menu">
+ ...
+ </ul>
+</div>
+
Opt into darker dropdowns to match a dark navbar or custom style by adding .dropdown-menu-dark
onto an existing .dropdown-menu
. No changes are required to the dropdown items.
<div class="dropdown">
+ <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown button
+ </button>
+ <ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="dropdownMenuButton2">
+ <li><a class="dropdown-item active" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Separated link</a></li>
+ </ul>
+</div>
And putting it to use in a navbar:
+<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDarkDropdown" aria-controls="navbarNavDarkDropdown" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarNavDarkDropdown">
+ <ul class="navbar-nav">
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown
+ </a>
+ <ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="navbarDarkDropdownMenuLink">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </div>
+</nav>
Directions are mirrored when using Bootstrap in RTL, meaning .dropstart
will appear on the right side.
+
Trigger dropdown menus above elements by adding .dropup
to the parent element.
<!-- Default dropup button -->
+<div class="btn-group dropup">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropup
+ </button>
+ <ul class="dropdown-menu">
+ <!-- Dropdown menu links -->
+ </ul>
+</div>
+
+<!-- Split dropup button -->
+<div class="btn-group dropup">
+ <button type="button" class="btn btn-secondary">
+ Split dropup
+ </button>
+ <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
+ <span class="visually-hidden">Toggle Dropdown</span>
+ </button>
+ <ul class="dropdown-menu">
+ <!-- Dropdown menu links -->
+ </ul>
+</div>
+
Trigger dropdown menus at the right of the elements by adding .dropend
to the parent element.
<!-- Default dropend button -->
+<div class="btn-group dropend">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropright
+ </button>
+ <ul class="dropdown-menu">
+ <!-- Dropdown menu links -->
+ </ul>
+</div>
+
+<!-- Split dropend button -->
+<div class="btn-group dropend">
+ <button type="button" class="btn btn-secondary">
+ Split dropend
+ </button>
+ <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
+ <span class="visually-hidden">Toggle Dropright</span>
+ </button>
+ <ul class="dropdown-menu">
+ <!-- Dropdown menu links -->
+ </ul>
+</div>
+
Trigger dropdown menus at the left of the elements by adding .dropstart
to the parent element.
<!-- Default dropstart button -->
+<div class="btn-group dropstart">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropstart
+ </button>
+ <ul class="dropdown-menu">
+ <!-- Dropdown menu links -->
+ </ul>
+</div>
+
+<!-- Split dropstart button -->
+<div class="btn-group">
+ <div class="btn-group dropstart" role="group">
+ <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
+ <span class="visually-hidden">Toggle Dropstart</span>
+ </button>
+ <ul class="dropdown-menu">
+ <!-- Dropdown menu links -->
+ </ul>
+ </div>
+ <button type="button" class="btn btn-secondary">
+ Split dropstart
+ </button>
+</div>
+
Historically dropdown menu contents had to be links, but that’s no longer the case with v4. Now you can optionally use <button>
elements in your dropdowns instead of just <a>
s.
<div class="dropdown">
+ <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown
+ </button>
+ <ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
+ <li><button class="dropdown-item" type="button">Action</button></li>
+ <li><button class="dropdown-item" type="button">Another action</button></li>
+ <li><button class="dropdown-item" type="button">Something else here</button></li>
+ </ul>
+</div>
You can also create non-interactive dropdown items with .dropdown-item-text
. Feel free to style further with custom CSS or text utilities.
<ul class="dropdown-menu">
+ <li><span class="dropdown-item-text">Dropdown item text</span></li>
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+</ul>
Add .active
to items in the dropdown to style them as active. To convey the active state to assistive technologies, use the aria-current
attribute — using the page
value for the current page, or true
for the current item in a set.
<ul class="dropdown-menu">
+ <li><a class="dropdown-item" href="#">Regular link</a></li>
+ <li><a class="dropdown-item active" href="#" aria-current="true">Active link</a></li>
+ <li><a class="dropdown-item" href="#">Another link</a></li>
+</ul>
Add .disabled
to items in the dropdown to style them as disabled.
<ul class="dropdown-menu">
+ <li><a class="dropdown-item" href="#">Regular link</a></li>
+ <li><a class="dropdown-item disabled" href="#" tabindex="-1" aria-disabled="true">Disabled link</a></li>
+ <li><a class="dropdown-item" href="#">Another link</a></li>
+</ul>
By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add .dropdown-menu-end
to a .dropdown-menu
to right align the dropdown menu. Directions are mirrored when using Bootstrap in RTL, meaning .dropdown-menu-end
will appear on the left side.
<div class="btn-group">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
+ Right-aligned menu example
+ </button>
+ <ul class="dropdown-menu dropdown-menu-end">
+ <li><button class="dropdown-item" type="button">Action</button></li>
+ <li><button class="dropdown-item" type="button">Another action</button></li>
+ <li><button class="dropdown-item" type="button">Something else here</button></li>
+ </ul>
+</div>
If you want to use responsive alignment, disable dynamic positioning by adding the data-bs-display="static"
attribute and use the responsive variation classes.
To align right the dropdown menu with the given breakpoint or larger, add .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-end
.
<div class="btn-group">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
+ Left-aligned but right aligned when large screen
+ </button>
+ <ul class="dropdown-menu dropdown-menu-lg-end">
+ <li><button class="dropdown-item" type="button">Action</button></li>
+ <li><button class="dropdown-item" type="button">Another action</button></li>
+ <li><button class="dropdown-item" type="button">Something else here</button></li>
+ </ul>
+</div>
To align left the dropdown menu with the given breakpoint or larger, add .dropdown-menu-end
and .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-start
.
<div class="btn-group">
+ <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false">
+ Right-aligned but left aligned when large screen
+ </button>
+ <ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start">
+ <li><button class="dropdown-item" type="button">Action</button></li>
+ <li><button class="dropdown-item" type="button">Another action</button></li>
+ <li><button class="dropdown-item" type="button">Something else here</button></li>
+ </ul>
+</div>
Note that you don’t need to add a data-bs-display="static"
attribute to dropdown buttons in navbars, since Popper isn’t used in navbars.
Add a header to label sections of actions in any dropdown menu.
+<ul class="dropdown-menu">
+ <li><h6 class="dropdown-header">Dropdown header</h6></li>
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+</ul>
Separate groups of related menu items with a divider.
+<ul class="dropdown-menu">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Separated link</a></li>
+</ul>
Place any freeform text within a dropdown menu with text and use spacing utilities. Note that you’ll likely need additional sizing styles to constrain the menu width.
+<div class="dropdown-menu p-4 text-muted" style="max-width: 200px;">
+ <p>
+ Some example text that's free-flowing within the dropdown menu.
+ </p>
+ <p class="mb-0">
+ And this is more example text.
+ </p>
+</div>
Put a form within a dropdown menu, or make it into a dropdown menu, and use margin or padding utilities to give it the negative space you require.
+<div class="dropdown-menu">
+ <form class="px-4 py-3">
+ <div class="mb-3">
+ <label for="exampleDropdownFormEmail1" class="form-label">Email address</label>
+ <input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="email@example.com">
+ </div>
+ <div class="mb-3">
+ <label for="exampleDropdownFormPassword1" class="form-label">Password</label>
+ <input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password">
+ </div>
+ <div class="mb-3">
+ <div class="form-check">
+ <input type="checkbox" class="form-check-input" id="dropdownCheck">
+ <label class="form-check-label" for="dropdownCheck">
+ Remember me
+ </label>
+ </div>
+ </div>
+ <button type="submit" class="btn btn-primary">Sign in</button>
+ </form>
+ <div class="dropdown-divider"></div>
+ <a class="dropdown-item" href="#">New around here? Sign up</a>
+ <a class="dropdown-item" href="#">Forgot password?</a>
+</div>
<form class="dropdown-menu p-4">
+ <div class="mb-3">
+ <label for="exampleDropdownFormEmail2" class="form-label">Email address</label>
+ <input type="email" class="form-control" id="exampleDropdownFormEmail2" placeholder="email@example.com">
+ </div>
+ <div class="mb-3">
+ <label for="exampleDropdownFormPassword2" class="form-label">Password</label>
+ <input type="password" class="form-control" id="exampleDropdownFormPassword2" placeholder="Password">
+ </div>
+ <div class="mb-3">
+ <div class="form-check">
+ <input type="checkbox" class="form-check-input" id="dropdownCheck2">
+ <label class="form-check-label" for="dropdownCheck2">
+ Remember me
+ </label>
+ </div>
+ </div>
+ <button type="submit" class="btn btn-primary">Sign in</button>
+</form>
Use data-bs-offset
or data-bs-reference
to change the location of the dropdown.
<div class="d-flex">
+ <div class="dropdown me-1">
+ <button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuOffset" data-bs-toggle="dropdown" aria-expanded="false" data-bs-offset="10,20">
+ Offset
+ </button>
+ <ul class="dropdown-menu" aria-labelledby="dropdownMenuOffset">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ </ul>
+ </div>
+ <div class="btn-group">
+ <button type="button" class="btn btn-secondary">Reference</button>
+ <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" id="dropdownMenuReference" data-bs-toggle="dropdown" aria-expanded="false" data-bs-reference="parent">
+ <span class="visually-hidden">Toggle Dropdown</span>
+ </button>
+ <ul class="dropdown-menu" aria-labelledby="dropdownMenuReference">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Separated link</a></li>
+ </ul>
+ </div>
+</div>
Via data attributes or JavaScript, the dropdown plugin toggles hidden content (dropdown menus) by toggling the .show
class on the parent .dropdown-menu
. The data-bs-toggle="dropdown"
attribute is relied on for closing dropdown menus at an application level, so it’s a good idea to always use it.
mouseover
handlers to the immediate children of the <body>
element. This admittedly ugly hack is necessary to work around a quirk in iOS' event delegation, which would otherwise prevent a tap anywhere outside of the dropdown from triggering the code that closes the dropdown. Once the dropdown is closed, these additional empty mouseover
handlers are removed.
+Add data-bs-toggle="dropdown"
to a link or button to toggle a dropdown.
<div class="dropdown">
+ <button id="dLabel" type="button" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown trigger
+ </button>
+ <ul class="dropdown-menu" aria-labelledby="dLabel">
+ ...
+ </ul>
+</div>
+
Call the dropdowns via JavaScript:
+var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
+var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
+ return new bootstrap.Dropdown(dropdownToggleEl)
+})
+
data-bs-toggle="dropdown"
still requiredRegardless of whether you call your dropdown via JavaScript or instead use the data-api, data-bs-toggle="dropdown"
is always required to be present on the dropdown’s trigger element.
+
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-offset=""
.
Name | +Type | +Default | +Description | +
---|---|---|---|
flip |
+ boolean | +true |
+ Allow Dropdown to flip in case of an overlapping on the reference element. For more information refer to Popper's flip docs. | +
boundary |
+ string | element | +'scrollParent' |
+ Overflow constraint boundary of the dropdown menu. By default it's 'clippingParents' and can accept an HTMLElement reference (JavaScript only). For more information refer to Popper's preventOverflow docs. |
+
reference |
+ string | element | +'toggle' |
+ Reference element of the dropdown menu. Accepts the values of 'toggle' , 'parent' , or an HTMLElement reference. For more information refer to Popper's constructor docs. |
+
display |
+ string | +'dynamic' |
+ By default, we use Popper for dynamic positioning. Disable this with static . |
+
popperConfig |
+ null | object | +null |
+ To change Bootstrap's default Popper config, see Popper's configuration | +
Note when boundary
is set to any value other than 'scrollParent'
, the style position: static
is applied to the .dropdown
container.
Method | +Description | +
---|---|
toggle |
+ + Toggles the dropdown menu of a given navbar or tabbed navigation. + | +
show |
+ + Shows the dropdown menu of a given navbar or tabbed navigation. + | +
hide |
+ + Hides the dropdown menu of a given navbar or tabbed navigation. + | +
update |
+ + Updates the position of an element's dropdown. + | +
dispose |
+ + Destroys an element's dropdown. (Removes stored data on the DOM element) + | +
getInstance |
+ + Static method which allows you to get the dropdown instance associated with a DOM element. + | +
All dropdown events are fired at the .dropdown-menu
’s parent element and have a relatedTarget
property, whose value is the toggling anchor element.
+hide.bs.dropdown
and hidden.bs.dropdown
events have a clickEvent
property (only when the original Event type is click
) that contains an Event Object for the click event.
Method | +Description | +
---|---|
+ show.bs.dropdown
+ |
+ + Fires immediately when the show instance method is called. + | +
+ shown.bs.dropdown
+ |
+ + Fired when the dropdown has been made visible to the user and CSS transitions have completed. + | +
+ hide.bs.dropdown
+ |
+ + Fires immediately when the hide instance method has been called. + | +
+ hidden.bs.dropdown
+ |
+ + Fired when the dropdown has finished being hidden from the user and CSS transitions have completed. + | +
var myDropdown = document.getElementById('myDropdown')
+myDropdown.addEventListener('show.bs.dropdown', function () {
+ // do something...
+})
+
List groups are a flexible and powerful component for displaying a series of content. Modify and extend them to support just about any content within.
+ + +The most basic list group is an unordered list with list items and the proper classes. Build upon it with the options that follow, or with your own CSS as needed.
+<ul class="list-group">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+ <li class="list-group-item">Porta ac consectetur ac</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+</ul>
Add .active
to a .list-group-item
to indicate the current active selection.
<ul class="list-group">
+ <li class="list-group-item active" aria-current="true">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+ <li class="list-group-item">Porta ac consectetur ac</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+</ul>
Add .disabled
to a .list-group-item
to make it appear disabled. Note that some elements with .disabled
will also require custom JavaScript to fully disable their click events (e.g., links).
<ul class="list-group">
+ <li class="list-group-item disabled" aria-disabled="true">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+ <li class="list-group-item">Porta ac consectetur ac</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+</ul>
Use <a>
s or <button>
s to create actionable list group items with hover, disabled, and active states by adding .list-group-item-action
. We separate these pseudo-classes to ensure list groups made of non-interactive elements (like <li>
s or <div>
s) don’t provide a click or tap affordance.
Be sure to not use the standard .btn
classes here.
<div class="list-group">
+ <a href="#" class="list-group-item list-group-item-action active" aria-current="true">
+ Cras justo odio
+ </a>
+ <a href="#" class="list-group-item list-group-item-action">Dapibus ac facilisis in</a>
+ <a href="#" class="list-group-item list-group-item-action">Morbi leo risus</a>
+ <a href="#" class="list-group-item list-group-item-action">Porta ac consectetur ac</a>
+ <a href="#" class="list-group-item list-group-item-action disabled" tabindex="-1" aria-disabled="true">Vestibulum at eros</a>
+</div>
With <button>
s, you can also make use of the disabled
attribute instead of the .disabled
class. Sadly, <a>
s don’t support the disabled attribute.
<div class="list-group">
+ <button type="button" class="list-group-item list-group-item-action active" aria-current="true">
+ Cras justo odio
+ </button>
+ <button type="button" class="list-group-item list-group-item-action">Dapibus ac facilisis in</button>
+ <button type="button" class="list-group-item list-group-item-action">Morbi leo risus</button>
+ <button type="button" class="list-group-item list-group-item-action">Porta ac consectetur ac</button>
+ <button type="button" class="list-group-item list-group-item-action" disabled>Vestibulum at eros</button>
+</div>
Add .list-group-flush
to remove some borders and rounded corners to render list group items edge-to-edge in a parent container (e.g., cards).
<ul class="list-group list-group-flush">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+ <li class="list-group-item">Porta ac consectetur ac</li>
+ <li class="list-group-item">Vestibulum at eros</li>
+</ul>
Add .list-group-horizontal
to change the layout of list group items from vertical to horizontal across all breakpoints. Alternatively, choose a responsive variant .list-group-horizontal-{sm|md|lg|xl|xxl}
to make a list group horizontal starting at that breakpoint’s min-width
. Currently horizontal list groups cannot be combined with flush list groups.
ProTip: Want equal-width list group items when horizontal? Add .flex-fill
to each list group item.
<ul class="list-group list-group-horizontal">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+</ul>
+<ul class="list-group list-group-horizontal-sm">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+</ul>
+<ul class="list-group list-group-horizontal-md">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+</ul>
+<ul class="list-group list-group-horizontal-lg">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+</ul>
+<ul class="list-group list-group-horizontal-xl">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+</ul>
+<ul class="list-group list-group-horizontal-xxl">
+ <li class="list-group-item">Cras justo odio</li>
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+ <li class="list-group-item">Morbi leo risus</li>
+</ul>
Use contextual classes to style list items with a stateful background and color.
+<ul class="list-group">
+ <li class="list-group-item">Dapibus ac facilisis in</li>
+
+ <li class="list-group-item list-group-item-primary">A simple primary list group item</li>
+ <li class="list-group-item list-group-item-secondary">A simple secondary list group item</li>
+ <li class="list-group-item list-group-item-success">A simple success list group item</li>
+ <li class="list-group-item list-group-item-danger">A simple danger list group item</li>
+ <li class="list-group-item list-group-item-warning">A simple warning list group item</li>
+ <li class="list-group-item list-group-item-info">A simple info list group item</li>
+ <li class="list-group-item list-group-item-light">A simple light list group item</li>
+ <li class="list-group-item list-group-item-dark">A simple dark list group item</li>
+</ul>
Contextual classes also work with .list-group-item-action
. Note the addition of the hover styles here not present in the previous example. Also supported is the .active
state; apply it to indicate an active selection on a contextual list group item.
<div class="list-group">
+ <a href="#" class="list-group-item list-group-item-action">Dapibus ac facilisis in</a>
+
+ <a href="#" class="list-group-item list-group-item-action list-group-item-primary">A simple primary list group item</a>
+ <a href="#" class="list-group-item list-group-item-action list-group-item-secondary">A simple secondary list group item</a>
+ <a href="#" class="list-group-item list-group-item-action list-group-item-success">A simple success list group item</a>
+ <a href="#" class="list-group-item list-group-item-action list-group-item-danger">A simple danger list group item</a>
+ <a href="#" class="list-group-item list-group-item-action list-group-item-warning">A simple warning list group item</a>
+ <a href="#" class="list-group-item list-group-item-action list-group-item-info">A simple info list group item</a>
+ <a href="#" class="list-group-item list-group-item-action list-group-item-light">A simple light list group item</a>
+ <a href="#" class="list-group-item list-group-item-action list-group-item-dark">A simple dark list group item</a>
+</div>
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden
class.
+
Add badges to any list group item to show unread counts, activity, and more with the help of some utilities.
+<ul class="list-group">
+ <li class="list-group-item d-flex justify-content-between align-items-center">
+ Cras justo odio
+ <span class="badge bg-primary rounded-pill">14</span>
+ </li>
+ <li class="list-group-item d-flex justify-content-between align-items-center">
+ Dapibus ac facilisis in
+ <span class="badge bg-primary rounded-pill">2</span>
+ </li>
+ <li class="list-group-item d-flex justify-content-between align-items-center">
+ Morbi leo risus
+ <span class="badge bg-primary rounded-pill">1</span>
+ </li>
+</ul>
Add nearly any HTML within, even for linked list groups like the one below, with the help of flexbox utilities.
+Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.
+ Donec id elit non mi porta. + + +Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.
+ Donec id elit non mi porta. + + +Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.
+ Donec id elit non mi porta. + +<div class="list-group">
+ <a href="#" class="list-group-item list-group-item-action active" aria-current="true">
+ <div class="d-flex w-100 justify-content-between">
+ <h5 class="mb-1">List group item heading</h5>
+ <small>3 days ago</small>
+ </div>
+ <p class="mb-1">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
+ <small>Donec id elit non mi porta.</small>
+ </a>
+ <a href="#" class="list-group-item list-group-item-action">
+ <div class="d-flex w-100 justify-content-between">
+ <h5 class="mb-1">List group item heading</h5>
+ <small class="text-muted">3 days ago</small>
+ </div>
+ <p class="mb-1">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
+ <small class="text-muted">Donec id elit non mi porta.</small>
+ </a>
+ <a href="#" class="list-group-item list-group-item-action">
+ <div class="d-flex w-100 justify-content-between">
+ <h5 class="mb-1">List group item heading</h5>
+ <small class="text-muted">3 days ago</small>
+ </div>
+ <p class="mb-1">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
+ <small class="text-muted">Donec id elit non mi porta.</small>
+ </a>
+</div>
Place Bootstrap’s checkboxes and radios within list group items and customize as needed. You can use them without <label>
s, but please remember to include an aria-label
attribute and value for accessibility.
<ul class="list-group">
+ <li class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="" aria-label="...">
+ Cras justo odio
+ </li>
+ <li class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="" aria-label="...">
+ Dapibus ac facilisis in
+ </li>
+ <li class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="" aria-label="...">
+ Morbi leo risus
+ </li>
+ <li class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="" aria-label="...">
+ Porta ac consectetur ac
+ </li>
+ <li class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="" aria-label="...">
+ Vestibulum at eros
+ </li>
+</ul>
And if you want <label>
s as the .list-group-item
for large hit areas, you can do that, too.
<div class="list-group">
+ <label class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="">
+ Cras justo odio
+ </label>
+ <label class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="">
+ Dapibus ac facilisis in
+ </label>
+ <label class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="">
+ Morbi leo risus
+ </label>
+ <label class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="">
+ Porta ac consectetur ac
+ </label>
+ <label class="list-group-item">
+ <input class="form-check-input me-1" type="checkbox" value="">
+ Vestibulum at eros
+ </label>
+</div>
Use the tab JavaScript plugin—include it individually or through the compiled bootstrap.js
file—to extend our list group to create tabbable panes of local content.
<div class="row">
+ <div class="col-4">
+ <div class="list-group" id="list-tab" role="tablist">
+ <a class="list-group-item list-group-item-action active" id="list-home-list" data-bs-toggle="list" href="#list-home" role="tab" aria-controls="home">Home</a>
+ <a class="list-group-item list-group-item-action" id="list-profile-list" data-bs-toggle="list" href="#list-profile" role="tab" aria-controls="profile">Profile</a>
+ <a class="list-group-item list-group-item-action" id="list-messages-list" data-bs-toggle="list" href="#list-messages" role="tab" aria-controls="messages">Messages</a>
+ <a class="list-group-item list-group-item-action" id="list-settings-list" data-bs-toggle="list" href="#list-settings" role="tab" aria-controls="settings">Settings</a>
+ </div>
+ </div>
+ <div class="col-8">
+ <div class="tab-content" id="nav-tabContent">
+ <div class="tab-pane fade show active" id="list-home" role="tabpanel" aria-labelledby="list-home-list">...</div>
+ <div class="tab-pane fade" id="list-profile" role="tabpanel" aria-labelledby="list-profile-list">...</div>
+ <div class="tab-pane fade" id="list-messages" role="tabpanel" aria-labelledby="list-messages-list">...</div>
+ <div class="tab-pane fade" id="list-settings" role="tabpanel" aria-labelledby="list-settings-list">...</div>
+ </div>
+ </div>
+</div>
+
You can activate a list group navigation without writing any JavaScript by simply specifying data-bs-toggle="list"
or on an element. Use these data attributes on .list-group-item
.
<div role="tabpanel">
+ <!-- List group -->
+ <div class="list-group" id="myList" role="tablist">
+ <a class="list-group-item list-group-item-action active" data-bs-toggle="list" href="#home" role="tab">Home</a>
+ <a class="list-group-item list-group-item-action" data-bs-toggle="list" href="#profile" role="tab">Profile</a>
+ <a class="list-group-item list-group-item-action" data-bs-toggle="list" href="#messages" role="tab">Messages</a>
+ <a class="list-group-item list-group-item-action" data-bs-toggle="list" href="#settings" role="tab">Settings</a>
+ </div>
+
+ <!-- Tab panes -->
+ <div class="tab-content">
+ <div class="tab-pane active" id="home" role="tabpanel">...</div>
+ <div class="tab-pane" id="profile" role="tabpanel">...</div>
+ <div class="tab-pane" id="messages" role="tabpanel">...</div>
+ <div class="tab-pane" id="settings" role="tabpanel">...</div>
+ </div>
+</div>
+
Enable tabbable list item via JavaScript (each list item needs to be activated individually):
+var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
+triggerTabList.forEach(function (triggerEl) {
+ var tabTrigger = new bootstrap.Tab(triggerEl)
+
+ triggerEl.addEventListener('click', function (event) {
+ event.preventDefault()
+ tabTrigger.show()
+ })
+})
+
You can activate individual list item in several ways:
+var triggerEl = document.querySelector('#myTab a[href="#profile"]')
+bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
+
+var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
+bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
+
To make tabs panel fade in, add .fade
to each .tab-pane
. The first tab pane must also have .show
to make the initial content visible.
<div class="tab-content">
+ <div class="tab-pane fade show active" id="home" role="tabpanel">...</div>
+ <div class="tab-pane fade" id="profile" role="tabpanel">...</div>
+ <div class="tab-pane fade" id="messages" role="tabpanel">...</div>
+ <div class="tab-pane fade" id="settings" role="tabpanel">...</div>
+</div>
+
Activates a list item element and content container. Tab should have either a data-bs-target
or an href
targeting a container node in the DOM.
<div class="list-group" id="myList" role="tablist">
+ <a class="list-group-item list-group-item-action active" data-bs-toggle="list" href="#home" role="tab">Home</a>
+ <a class="list-group-item list-group-item-action" data-bs-toggle="list" href="#profile" role="tab">Profile</a>
+ <a class="list-group-item list-group-item-action" data-bs-toggle="list" href="#messages" role="tab">Messages</a>
+ <a class="list-group-item list-group-item-action" data-bs-toggle="list" href="#settings" role="tab">Settings</a>
+</div>
+
+<div class="tab-content">
+ <div class="tab-pane active" id="home" role="tabpanel">...</div>
+ <div class="tab-pane" id="profile" role="tabpanel">...</div>
+ <div class="tab-pane" id="messages" role="tabpanel">...</div>
+ <div class="tab-pane" id="settings" role="tabpanel">...</div>
+</div>
+
+<script>
+ var firstTabEl = document.querySelector('#myTab a:last-child')
+ var firstTab = new bootstrap.Tab(firstTabEl)
+
+ firstTab.show()
+</script>
+
Selects the given list item and shows its associated pane. Any other list item that was previously selected becomes unselected and its associated pane is hidden. Returns to the caller before the tab pane has actually been shown (for example, before the shown.bs.tab
event occurs).
var someListItemEl = document.querySelector('#someListItem')
+ var tab = new bootstrap.Tab(someListItemEl)
+
+ tab.show()
+
Destroys an element’s tab.
+Static method which allows you to get the tab instance associated with a DOM element
+var triggerEl = document.querySelector('#trigger')
+var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
+
When showing a new tab, the events fire in the following order:
+hide.bs.tab
(on the current active tab)show.bs.tab
(on the to-be-shown tab)hidden.bs.tab
(on the previous active tab, the same one as for the hide.bs.tab
event)shown.bs.tab
(on the newly-active just-shown tab, the same one as for the show.bs.tab
event)If no tab was already active, the hide.bs.tab
and hidden.bs.tab
events will not be fired.
Event type | +Description | +
---|---|
show.bs.tab |
+ This event fires on tab show, but before the new tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
+
shown.bs.tab |
+ This event fires on tab show after a tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
+
hide.bs.tab |
+ This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use event.target and event.relatedTarget to target the current active tab and the new soon-to-be-active tab, respectively. |
+
hidden.bs.tab |
+ This event fires after a new tab is shown (and thus the previous active tab is hidden). Use event.target and event.relatedTarget to target the previous active tab and the new active tab, respectively. |
+
var tabEl = document.querySelector('a[data-bs-toggle="list"]')
+tabEl.addEventListener('shown.bs.tab', function (event) {
+ event.target // newly activated tab
+ event.relatedTarget // previous active tab
+})
+
Use Bootstrap’s JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
+ + +Before getting started with Bootstrap’s modal component, be sure to read the following as our menu options have recently changed.
+<body>
so that modal content scrolls instead.position: fixed
, which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You’ll likely run into issues when nesting a .modal
within another fixed element.position: fixed
, there are some caveats with using modals on mobile devices. See our browser support docs for details.autofocus
HTML attribute has no effect in Bootstrap modals. To achieve the same effect, use some custom JavaScript:var myModal = document.getElementById('myModal')
+var myInput = document.getElementById('myInput')
+
+myModal.addEventListener('shown.bs.modal', function () {
+ myInput.focus()
+})
+
prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Keep reading for demos and usage guidelines.
+Below is a static modal example (meaning its position
and display
have been overridden). Included are the modal header, modal body (required for padding
), and modal footer (optional). We ask that you include modal headers with dismiss actions whenever possible, or provide another explicit dismiss action.
<div class="modal" tabindex="-1">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <h5 class="modal-title">Modal title</h5>
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ </div>
+ <div class="modal-body">
+ <p>Modal body text goes here.</p>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+ <button type="button" class="btn btn-primary">Save changes</button>
+ </div>
+ </div>
+ </div>
+</div>
+
Toggle a working modal demo by clicking the button below. It will slide down and fade in from the top of the page.
+ +<!-- Button trigger modal -->
+<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
+ Launch demo modal
+</button>
+
+<!-- Modal -->
+<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ </div>
+ <div class="modal-body">
+ ...
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+ <button type="button" class="btn btn-primary">Save changes</button>
+ </div>
+ </div>
+ </div>
+</div>
+
When backdrop is set to static, the modal will not close when clicking outside it. Click the button below to try it.
+ +<!-- Button trigger modal -->
+<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
+ Launch static backdrop modal
+</button>
+
+<!-- Modal -->
+<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <h5 class="modal-title" id="staticBackdropLabel">Modal title</h5>
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ </div>
+ <div class="modal-body">
+ ...
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+ <button type="button" class="btn btn-primary">Understood</button>
+ </div>
+ </div>
+ </div>
+</div>
+
When modals become too long for the user’s viewport or device, they scroll independent of the page itself. Try the demo below to see what we mean.
+ +You can also create a scrollable modal that allows scroll the modal body by adding .modal-dialog-scrollable
to .modal-dialog
.
<!-- Scrollable modal -->
+<div class="modal-dialog modal-dialog-scrollable">
+ ...
+</div>
+
Add .modal-dialog-centered
to .modal-dialog
to vertically center the modal.
<!-- Vertically centered modal -->
+<div class="modal-dialog modal-dialog-centered">
+ ...
+</div>
+
+<!-- Vertically centered scrollable modal -->
+<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
+ ...
+</div>
+
Tooltips and popovers can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed.
+ +<div class="modal-body">
+ <h5>Popover in a modal</h5>
+ <p>This <a href="#" role="button" class="btn btn-secondary popover-test" title="Popover title" data-bs-content="Popover body content is set in this attribute.">button</a> triggers a popover on click.</p>
+ <hr>
+ <h5>Tooltips in a modal</h5>
+ <p><a href="#" class="tooltip-test" title="Tooltip">This link</a> and <a href="#" class="tooltip-test" title="Tooltip">that link</a> have tooltips on hover.</p>
+</div>
+
Utilize the Bootstrap grid system within a modal by nesting .container-fluid
within the .modal-body
. Then, use the normal grid system classes as you would anywhere else.
<div class="modal-body">
+ <div class="container-fluid">
+ <div class="row">
+ <div class="col-md-4">.col-md-4</div>
+ <div class="col-md-4 ms-auto">.col-md-4 .ms-auto</div>
+ </div>
+ <div class="row">
+ <div class="col-md-3 ms-auto">.col-md-3 .ms-auto</div>
+ <div class="col-md-2 ms-auto">.col-md-2 .ms-auto</div>
+ </div>
+ <div class="row">
+ <div class="col-md-6 ms-auto">.col-md-6 .ms-auto</div>
+ </div>
+ <div class="row">
+ <div class="col-sm-9">
+ Level 1: .col-sm-9
+ <div class="row">
+ <div class="col-8 col-sm-6">
+ Level 2: .col-8 .col-sm-6
+ </div>
+ <div class="col-4 col-sm-6">
+ Level 2: .col-4 .col-sm-6
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
+
Have a bunch of buttons that all trigger the same modal with slightly different contents? Use event.relatedTarget
and HTML data-bs-*
attributes to vary the contents of the modal depending on which button was clicked.
Below is a live demo followed by example HTML and JavaScript. For more information, read the modal events docs for details on relatedTarget
.
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@mdo">Open modal for @mdo</button>
+<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@fat">Open modal for @fat</button>
+<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@getbootstrap">Open modal for @getbootstrap</button>
+
+<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <h5 class="modal-title" id="exampleModalLabel">New message</h5>
+ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ </div>
+ <div class="modal-body">
+ <form>
+ <div class="mb-3">
+ <label for="recipient-name" class="col-form-label">Recipient:</label>
+ <input type="text" class="form-control" id="recipient-name">
+ </div>
+ <div class="mb-3">
+ <label for="message-text" class="col-form-label">Message:</label>
+ <textarea class="form-control" id="message-text"></textarea>
+ </div>
+ </form>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+ <button type="button" class="btn btn-primary">Send message</button>
+ </div>
+ </div>
+ </div>
+</div>
var exampleModal = document.getElementById('exampleModal')
+exampleModal.addEventListener('show.bs.modal', function (event) {
+ // Button that triggered the modal
+ var button = event.relatedTarget
+ // Extract info from data-bs-* attributes
+ var recipient = button.getAttribute('data-bs-whatever')
+ // If necessary, you could initiate an AJAX request here
+ // and then do the updating in a callback.
+ //
+ // Update the modal's content.
+ var modalTitle = exampleModal.querySelector('.modal-title')
+ var modalBodyInput = exampleModal.querySelector('.modal-body input')
+
+ modalTitle.textContent = 'New message to ' + recipient
+ modalBodyInput.value = recipient
+})
+
The $modal-fade-transform
variable determines the transform state of .modal-dialog
before the modal fade-in animation, the $modal-show-transform
variable determines the transform of .modal-dialog
at the end of the modal fade-in animation.
If you want for example a zoom-in animation, you can set $modal-fade-transform: scale(.8)
.
For modals that simply appear rather than fade in to view, remove the .fade
class from your modal markup.
<div class="modal" tabindex="-1" aria-labelledby="..." aria-hidden="true">
+ ...
+</div>
+
If the height of a modal changes while it is open, you should call myModal.handleUpdate()
to readjust the modal’s position in case a scrollbar appears.
Be sure to add aria-labelledby="..."
, referencing the modal title, to .modal
. Additionally, you may give a description of your modal dialog with aria-describedby
on .modal
. Note that you don’t need to add role="dialog"
since we already add it via JavaScript.
Embedding YouTube videos in modals requires additional JavaScript not in Bootstrap to automatically stop playback and more. See this helpful Stack Overflow post for more information.
+Modals have three optional sizes, available via modifier classes to be placed on a .modal-dialog
. These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports.
Size | +Class | +Modal max-width | +
---|---|---|
Small | +.modal-sm |
+ 300px |
+
Default | +None | +500px |
+
Large | +.modal-lg |
+ 800px |
+
Extra large | +.modal-xl |
+ 1140px |
+
Our default modal without modifier class constitutes the “medium” size modal.
+<div class="modal-dialog modal-xl">...</div>
+<div class="modal-dialog modal-lg">...</div>
+<div class="modal-dialog modal-sm">...</div>
+
Another override is the option to pop up a modal that covers the user viewport, available via modifier classes that are placed on a .modal-dialog
.
Class | +Availability | +
---|---|
.modal-fullscreen |
+ Always | +
.modal-fullscreen-sm-down |
+ Below 576px |
+
.modal-fullscreen-md-down |
+ Below 768px |
+
.modal-fullscreen-lg-down |
+ Below 992px |
+
.modal-fullscreen-xl-down |
+ Below 1200px |
+
.modal-fullscreen-xxl-down |
+ Below 1400px |
+
<!-- Full screen modal -->
+<div class="modal-dialog modal-fullscreen-sm-down">
+ ...
+</div>
+
The modal plugin toggles your hidden content on demand, via data attributes or JavaScript. It also adds .modal-open
to the <body>
to override default scrolling behavior and generates a .modal-backdrop
to provide a click area for dismissing shown modals when clicking outside the modal.
Activate a modal without writing JavaScript. Set data-bs-toggle="modal"
on a controller element, like a button, along with a data-bs-target="#foo"
or href="#foo"
to target a specific modal to toggle.
<button type="button" data-bs-toggle="modal" data-bs-target="#myModal">Launch modal</button>
+
Create a modal with a single line of JavaScript:
+var myModal = new bootstrap.Modal(document.getElementById('myModal'), options)
+
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-backdrop=""
.
Name | +Type | +Default | +Description | +
---|---|---|---|
backdrop |
+ boolean or the string 'static' |
+ true |
+ Includes a modal-backdrop element. Alternatively, specify static for a backdrop which doesn't close the modal on click. |
+
keyboard |
+ boolean | +true |
+ Closes the modal when escape key is pressed | +
focus |
+ boolean | +true |
+ Puts the focus on the modal when initialized. | +
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
+ + +Activates your content as a modal. Accepts an optional options object
.
var myModal = new bootstrap.Modal(document.getElementById('myModal'), {
+ keyboard: false
+})
+
Manually toggles a modal. Returns to the caller before the modal has actually been shown or hidden (i.e. before the shown.bs.modal
or hidden.bs.modal
event occurs).
myModal.toggle()
+
Manually opens a modal. Returns to the caller before the modal has actually been shown (i.e. before the shown.bs.modal
event occurs).
myModal.show()
+
Manually hides a modal. Returns to the caller before the modal has actually been hidden (i.e. before the hidden.bs.modal
event occurs).
myModal.hide()
+
Manually readjust the modal’s position if the height of a modal changes while it is open (i.e. in case a scrollbar appears).
+myModal.handleUpdate()
+
Destroys an element’s modal. (Removes stored data on the DOM element)
+myModal.dispose()
+
Static method which allows you to get the modal instance associated with a DOM element
+var myModalEl = document.getElementById('myModal')
+var modal = bootstrap.Modal.getInstance(myModalEl) // Returns a Bootstrap modal instance
+
Bootstrap’s modal class exposes a few events for hooking into modal functionality. All modal events are fired at the modal itself (i.e. at the <div class="modal">
).
Event type | +Description | +
---|---|
show.bs.modal |
+ This event fires immediately when the show instance method is called. If caused by a click, the clicked element is available as the relatedTarget property of the event. |
+
shown.bs.modal |
+ This event is fired when the modal has been made visible to the user (will wait for CSS transitions to complete). If caused by a click, the clicked element is available as the relatedTarget property of the event. |
+
hide.bs.modal |
+ This event is fired immediately when the hide instance method has been called. |
+
hidden.bs.modal |
+ This event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete). | +
hidePrevented.bs.modal |
+ This event is fired when the modal is shown, its backdrop is static and a click outside the modal or an escape key press is performed with the keyboard option or data-bs-keyboard set to false . |
+
var myModalEl = document.getElementById('myModal')
+myModalEl.addEventListener('hidden.bs.modal', function (event) {
+ // do something...
+})
+
Documentation and examples for Bootstrap’s powerful, responsive navigation header, the navbar. Includes support for branding, navigation, and more, including support for our collapse plugin.
+ + +Here’s what you need to know before getting started with the navbar:
+.navbar
with .navbar-expand{-sm|-md|-lg|-xl|-xxl}
for responsive collapsing and color scheme classes.<nav>
element or, if using a more generic element such as a <div>
, add a role="navigation"
to every navbar to explicitly identify it as a landmark region for users of assistive technologies.aria-current="page"
for the current page or aria-current="true"
for the current item in a set.prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:
+.navbar-brand
for your company, product, or project name..navbar-nav
for a full-height and lightweight navigation (including support for dropdowns)..navbar-toggler
for use with our collapse plugin and other navigation toggling behaviors..navbar-text
for adding vertically centered strings of text..collapse.navbar-collapse
for grouping and hiding navbar contents by a parent breakpoint.Here’s an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at the lg
(large) breakpoint.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarSupportedContent">
+ <ul class="navbar-nav me-auto mb-2 mb-lg-0">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Link</a>
+ </li>
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown
+ </a>
+ <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ </ul>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+ </ul>
+ <form class="d-flex">
+ <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+ </div>
+ </div>
+</nav>
This example uses color (bg-light
) and spacing (my-2
, my-lg-0
, me-sm-0
, my-sm-0
) utility classes.
The .navbar-brand
can be applied to most elements, but an anchor works best, as some elements might require utility classes or custom styles.
<!-- As a link -->
+<nav class="navbar navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ </div>
+</nav>
+
+<!-- As a heading -->
+<nav class="navbar navbar-light bg-light">
+ <div class="container-fluid">
+ <span class="navbar-brand mb-0 h1">Navbar</span>
+ </div>
+</nav>
Adding images to the .navbar-brand
will likely always require custom styles or utilities to properly size. Here are some examples to demonstrate.
<!-- Just an image -->
+<nav class="navbar navbar-light bg-light">
+ <div class="container">
+ <a class="navbar-brand" href="#">
+ <img src="/docs/5.0/assets/brand/bootstrap-logo.svg" alt="" width="30" height="24">
+ </a>
+ </div>
+</nav>
<!-- Image and text -->
+<nav class="navbar navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">
+ <img src="/docs/5.0/assets/brand/bootstrap-logo.svg" alt="" width="30" height="24" class="d-inline-block align-top">
+ Bootstrap
+ </a>
+ </div>
+</nav>
Navbar navigation links build on our .nav
options with their own modifier class and require the use of toggler classes for proper responsive styling. Navigation in navbars will also grow to occupy as much horizontal space as possible to keep your navbar contents securely aligned.
Active states—with .active
—to indicate the current page can be applied directly to .nav-link
s or their immediate parent .nav-item
s.
Please note that you should also add the aria-current
attribute on the .nav-link
itself.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarNav">
+ <ul class="navbar-nav">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Features</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Pricing</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+ </ul>
+ </div>
+ </div>
+</nav>
And because we use classes for our navs, you can avoid the list-based approach entirely if you like.
+<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
+ <div class="navbar-nav">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ <a class="nav-link" href="#">Features</a>
+ <a class="nav-link" href="#">Pricing</a>
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </div>
+ </div>
+ </div>
+</nav>
You can also use dropdowns in your navbar. Dropdown menus require a wrapping element for positioning, so be sure to use separate and nested elements for .nav-item
and .nav-link
as shown below.
<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarNavDropdown">
+ <ul class="navbar-nav">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Features</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Pricing</a>
+ </li>
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
+ Dropdown link
+ </a>
+ <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ </ul>
+ </li>
+ </ul>
+ </div>
+ </div>
+</nav>
Place various form controls and components within a navbar:
+<nav class="navbar navbar-light bg-light">
+ <div class="container-fluid">
+ <form class="d-flex">
+ <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+ </div>
+</nav>
Immediate child elements of .navbar
use flex layout and will default to justify-content: space-between
. Use additional flex utilities as needed to adjust this behavior.
<nav class="navbar navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand">Navbar</a>
+ <form class="d-flex">
+ <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+ </div>
+</nav>
Input groups work, too. If your navbar is an entire form, or mostly a form, you can use the <form>
element as the container and save some HTML.
<nav class="navbar navbar-light bg-light">
+ <form class="container-fluid">
+ <div class="input-group">
+ <span class="input-group-text" id="basic-addon1">@</span>
+ <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
+ </div>
+ </form>
+</nav>
Various buttons are supported as part of these navbar forms, too. This is also a great reminder that vertical alignment utilities can be used to align different sized elements.
+<nav class="navbar navbar-light bg-light">
+ <form class="container-fluid justify-content-start">
+ <button class="btn btn-outline-success me-2" type="button">Main button</button>
+ <button class="btn btn-sm btn-outline-secondary" type="button">Smaller button</button>
+ </form>
+</nav>
Navbars may contain bits of text with the help of .navbar-text
. This class adjusts vertical alignment and horizontal spacing for strings of text.
<nav class="navbar navbar-light bg-light">
+ <div class="container-fluid">
+ <span class="navbar-text">
+ Navbar text with an inline element
+ </span>
+ </div>
+</nav>
Mix and match with other components and utilities as needed.
+<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar w/ text</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarText">
+ <ul class="navbar-nav me-auto mb-2 mb-lg-0">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Features</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Pricing</a>
+ </li>
+ </ul>
+ <span class="navbar-text">
+ Navbar text with an inline element
+ </span>
+ </div>
+ </div>
+</nav>
Theming the navbar has never been easier thanks to the combination of theming classes and background-color
utilities. Choose from .navbar-light
for use with light background colors, or .navbar-dark
for dark background colors. Then, customize with .bg-*
utilities.
<nav class="navbar navbar-dark bg-dark">
+ <!-- Navbar content -->
+</nav>
+
+<nav class="navbar navbar-dark bg-primary">
+ <!-- Navbar content -->
+</nav>
+
+<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
+ <!-- Navbar content -->
+</nav>
+
Although it’s not required, you can wrap a navbar in a .container
to center it on a page–though note that an inner container is still required. Or you can add a container inside the .navbar
to only center the contents of a fixed or static top navbar.
<div class="container">
+ <nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ </div>
+ </nav>
+</div>
Use any of the responsive containers to change how wide the content in your navbar is presented.
+<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-md">
+ <a class="navbar-brand" href="#">Navbar</a>
+ </div>
+</nav>
Use our position utilities to place navbars in non-static positions. Choose from fixed to the top, fixed to the bottom, or stickied to the top (scrolls with the page until it reaches the top, then stays there). Fixed navbars use position: fixed
, meaning they’re pulled from the normal flow of the DOM and may require custom CSS (e.g., padding-top
on the <body>
) to prevent overlap with other elements.
Also note that .sticky-top
uses position: sticky
, which isn’t fully supported in every browser.
<nav class="navbar navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Default</a>
+ </div>
+</nav>
<nav class="navbar fixed-top navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Fixed top</a>
+ </div>
+</nav>
<nav class="navbar fixed-bottom navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Fixed bottom</a>
+ </div>
+</nav>
<nav class="navbar sticky-top navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Sticky top</a>
+ </div>
+</nav>
Navbars can use .navbar-toggler
, .navbar-collapse
, and .navbar-expand{-sm|-md|-lg|-xl|-xxl}
classes to determine when their content collapses behind a button. In combination with other utilities, you can easily choose when to show or hide particular elements.
For navbars that never collapse, add the .navbar-expand
class on the navbar. For navbars that always collapse, don’t add any .navbar-expand
class.
Navbar togglers are left-aligned by default, but should they follow a sibling element like a .navbar-brand
, they’ll automatically be aligned to the far right. Reversing your markup will reverse the placement of the toggler. Below are examples of different toggle styles.
With no .navbar-brand
shown at the smallest breakpoint:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarTogglerDemo01">
+ <a class="navbar-brand" href="#">Hidden brand</a>
+ <ul class="navbar-nav me-auto mb-2 mb-lg-0">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Link</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+ </ul>
+ <form class="d-flex">
+ <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+ </div>
+ </div>
+</nav>
With a brand name shown on the left and toggler on the right:
+<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarTogglerDemo02">
+ <ul class="navbar-nav me-auto mb-2 mb-lg-0">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Link</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+ </ul>
+ <form class="d-flex">
+ <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+ </div>
+ </div>
+</nav>
With a toggler on the left and brand name on the right:
+<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <div class="container-fluid">
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <a class="navbar-brand" href="#">Navbar</a>
+ <div class="collapse navbar-collapse" id="navbarTogglerDemo03">
+ <ul class="navbar-nav me-auto mb-2 mb-lg-0">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Home</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Link</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+ </ul>
+ <form class="d-flex">
+ <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+ </div>
+ </div>
+</nav>
Sometimes you want to use the collapse plugin to trigger a container element for content that structurally sits outside of the .navbar
. Because our plugin works on the id
and data-bs-target
matching, that’s easily done!
<div class="collapse" id="navbarToggleExternalContent">
+ <div class="bg-dark p-4">
+ <h5 class="text-white h4">Collapsed content</h5>
+ <span class="text-muted">Toggleable via the navbar brand.</span>
+ </div>
+</div>
+<nav class="navbar navbar-dark bg-dark">
+ <div class="container-fluid">
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ </div>
+</nav>
When you do this, we recommend including additional JavaScript to move the focus programmatically to the container when it is opened. Otherwise, keyboard users and users of assistive technologies will likely have a hard time finding the newly revealed content - particularly if the container that was opened comes before the toggler in the document’s structure. We also recommend making sure that the toggler has the aria-controls
attribute, pointing to the id
of the content container. In theory, this allows assistive technology users to jump directly from the toggler to the container it controls–but support for this is currently quite patchy.
Documentation and examples for how to use Bootstrap’s included navigation components.
+ + +Navigation available in Bootstrap share general markup and styles, from the base .nav
class to the active and disabled states. Swap modifier classes to switch between each style.
The base .nav
component is built with flexbox and provide a strong foundation for building all types of navigation components. It includes some style overrides (for working with lists), some link padding for larger hit areas, and basic disabled styling.
The base .nav
component does not include any .active
state. The following examples include the class, mainly to demonstrate that this particular class does not trigger any special styling.
To convey the active state to assistive technologies, use the aria-current
attribute — using the page
value for current page, or true
for the current item in a set.
<ul class="nav">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
Classes are used throughout, so your markup can be super flexible. Use <ul>
s like above, <ol>
if the order of your items is important, or roll your own with a <nav>
element. Because the .nav
uses display: flex
, the nav links behave the same as nav items would, but without the extra markup.
<nav class="nav">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ <a class="nav-link" href="#">Link</a>
+ <a class="nav-link" href="#">Link</a>
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+</nav>
Change the style of .nav
s component with modifiers and utilities. Mix and match as needed, or build your own.
Change the horizontal alignment of your nav with flexbox utilities. By default, navs are left-aligned, but you can easily change them to center or right aligned.
+Centered with .justify-content-center
:
<ul class="nav justify-content-center">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
Right-aligned with .justify-content-end
:
<ul class="nav justify-content-end">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
Stack your navigation by changing the flex item direction with the .flex-column
utility. Need to stack them on some viewports but not others? Use the responsive versions (e.g., .flex-sm-column
).
<ul class="nav flex-column">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
As always, vertical navigation is possible without <ul>
s, too.
<nav class="nav flex-column">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ <a class="nav-link" href="#">Link</a>
+ <a class="nav-link" href="#">Link</a>
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+</nav>
Takes the basic nav from above and adds the .nav-tabs
class to generate a tabbed interface. Use them to create tabbable regions with our tab JavaScript plugin.
<ul class="nav nav-tabs">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
Take that same HTML, but use .nav-pills
instead:
<ul class="nav nav-pills">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
Force your .nav
’s contents to extend the full available width one of two modifier classes. To proportionately fill all available space with your .nav-item
s, use .nav-fill
. Notice that all horizontal space is occupied, but not every nav item has the same width.
<ul class="nav nav-pills nav-fill">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Much longer nav 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
When using a <nav>
-based navigation, you can safely omit .nav-item
as only .nav-link
is required for styling <a>
elements.
<nav class="nav nav-pills nav-fill">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ <a class="nav-link" href="#">Much longer nav link</a>
+ <a class="nav-link" href="#">Link</a>
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+</nav>
For equal-width elements, use .nav-justified
. All horizontal space will be occupied by nav links, but unlike the .nav-fill
above, every nav item will be the same width.
<ul class="nav nav-pills nav-justified">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#">Much longer nav 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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
Similar to the .nav-fill
example using a <nav>
-based navigation.
<nav class="nav nav-pills nav-justified">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ <a class="nav-link" href="#">Much longer nav link</a>
+ <a class="nav-link" href="#">Link</a>
+ <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+</nav>
If you need responsive nav variations, consider using a series of flexbox utilities. While more verbose, these utilities offer greater customization across responsive breakpoints. In the example below, our nav will be stacked on the lowest breakpoint, then adapt to a horizontal layout that fills the available width starting from the small breakpoint.
+<nav class="nav nav-pills flex-column flex-sm-row">
+ <a class="flex-sm-fill text-sm-center nav-link active" aria-current="page" href="#">Active</a>
+ <a class="flex-sm-fill text-sm-center nav-link" href="#">Longer nav link</a>
+ <a class="flex-sm-fill text-sm-center nav-link" href="#">Link</a>
+ <a class="flex-sm-fill text-sm-center nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
+</nav>
If you’re using navs to provide a navigation bar, be sure to add a role="navigation"
to the most logical parent container of the <ul>
, or wrap a <nav>
element around the whole navigation. Do not add the role to the <ul>
itself, as this would prevent it from being announced as an actual list by assistive technologies.
Note that navigation bars, even if visually styled as tabs with the .nav-tabs
class, should not be given role="tablist"
, role="tab"
or role="tabpanel"
attributes. These are only appropriate for dynamic tabbed interfaces, as described in the WAI ARIA Authoring Practices. See JavaScript behavior for dynamic tabbed interfaces in this section for an example. The aria-current
attribute is not necessary on dynamic tabbed interfaces since our JavaScript handles the selected state by adding aria-selected="true"
on the active tab.
Add dropdown menus with a little extra HTML and the dropdowns JavaScript plugin.
+<ul class="nav nav-tabs">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ </li>
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
+ <ul class="dropdown-menu">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Separated link</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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
<ul class="nav nav-pills">
+ <li class="nav-item">
+ <a class="nav-link active" aria-current="page" href="#">Active</a>
+ </li>
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
+ <ul class="dropdown-menu">
+ <li><a class="dropdown-item" href="#">Action</a></li>
+ <li><a class="dropdown-item" href="#">Another action</a></li>
+ <li><a class="dropdown-item" href="#">Something else here</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#">Separated link</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="#" tabindex="-1" aria-disabled="true">Disabled</a>
+ </li>
+</ul>
Use the tab JavaScript plugin—include it individually or through the compiled bootstrap.js
file—to extend our navigational tabs and pills to create tabbable panes of local content, even via dropdown menus.
Dynamic tabbed interfaces, as described in the WAI ARIA Authoring Practices, require role="tablist"
, role="tab"
, role="tabpanel"
, and additional aria-
attributes in order to convey their structure, functionality and current state to users of assistive technologies (such as screen readers).
Note that dynamic tabbed interfaces should not contain dropdown menus, as this causes both usability and accessibility issues. From a usability perspective, the fact that the currently displayed tab’s trigger element is not immediately visible (as it’s inside the closed dropdown menu) can cause confusion. From an accessibility point of view, there is currently no sensible way to map this sort of construct to a standard WAI ARIA pattern, meaning that it cannot be easily made understandable to users of assistive technologies.
+Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.
+Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
+Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.
+<ul class="nav nav-tabs" id="myTab" role="tablist">
+ <li class="nav-item" role="presentation">
+ <a class="nav-link active" id="home-tab" data-bs-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="contact-tab" data-bs-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
+ </li>
+</ul>
+<div class="tab-content" id="myTabContent">
+ <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
+ <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
+ <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
+</div>
+
To help fit your needs, this works with <ul>
-based markup, as shown above, or with any arbitrary “roll your own” markup. Note that if you’re using <nav>
, you shouldn’t add role="tablist"
directly to it, as this would override the element’s native role as a navigation landmark. Instead, switch to an alternative element (in the example below, a simple <div>
) and wrap the <nav>
around it.
<nav>
+ <div class="nav nav-tabs" id="nav-tab" role="tablist">
+ <a class="nav-link active" id="nav-home-tab" data-bs-toggle="tab" href="#nav-home" role="tab" aria-controls="nav-home" aria-selected="true">Home</a>
+ <a class="nav-link" id="nav-profile-tab" data-bs-toggle="tab" href="#nav-profile" role="tab" aria-controls="nav-profile" aria-selected="false">Profile</a>
+ <a class="nav-link" id="nav-contact-tab" data-bs-toggle="tab" href="#nav-contact" role="tab" aria-controls="nav-contact" aria-selected="false">Contact</a>
+ </div>
+</nav>
+<div class="tab-content" id="nav-tabContent">
+ <div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">...</div>
+ <div class="tab-pane fade" id="nav-profile" role="tabpanel" aria-labelledby="nav-profile-tab">...</div>
+ <div class="tab-pane fade" id="nav-contact" role="tabpanel" aria-labelledby="nav-contact-tab">...</div>
+</div>
+
The tabs plugin also works with pills.
+Consequat occaecat ullamco amet non eiusmod nostrud dolore irure incididunt est duis anim sunt officia. Fugiat velit proident aliquip nisi incididunt nostrud exercitation proident est nisi. Irure magna elit commodo anim ex veniam culpa eiusmod id nostrud sit cupidatat in veniam ad. Eiusmod consequat eu adipisicing minim anim aliquip cupidatat culpa excepteur quis. Occaecat sit eu exercitation irure Lorem incididunt nostrud.
+Ad pariatur nostrud pariatur exercitation ipsum ipsum culpa mollit commodo mollit ex. Aute sunt incididunt amet commodo est sint nisi deserunt pariatur do. Aliquip ex eiusmod voluptate exercitation cillum id incididunt elit sunt. Qui minim sit magna Lorem id et dolore velit Lorem amet exercitation duis deserunt. Anim id labore elit adipisicing ut in id occaecat pariatur ut ullamco ea tempor duis.
+Est quis nulla laborum officia ad nisi ex nostrud culpa Lorem excepteur aliquip dolor aliqua irure ex. Nulla ut duis ipsum nisi elit fugiat commodo sunt reprehenderit laborum veniam eu veniam. Eiusmod minim exercitation fugiat irure ex labore incididunt do fugiat commodo aliquip sit id deserunt reprehenderit aliquip nostrud. Amet ex cupidatat excepteur aute veniam incididunt mollit cupidatat esse irure officia elit do ipsum ullamco Lorem. Ullamco ut ad minim do mollit labore ipsum laboris ipsum commodo sunt tempor enim incididunt. Commodo quis sunt dolore aliquip aute tempor irure magna enim minim reprehenderit. Ullamco consectetur culpa veniam sint cillum aliqua incididunt velit ullamco sunt ullamco quis quis commodo voluptate. Mollit nulla nostrud adipisicing aliqua cupidatat aliqua pariatur mollit voluptate voluptate consequat non.
+<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
+ <li class="nav-item" role="presentation">
+ <a class="nav-link active" id="pills-home-tab" data-bs-toggle="pill" href="#pills-home" role="tab" aria-controls="pills-home" aria-selected="true">Home</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="pills-profile-tab" data-bs-toggle="pill" href="#pills-profile" role="tab" aria-controls="pills-profile" aria-selected="false">Profile</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="pills-contact-tab" data-bs-toggle="pill" href="#pills-contact" role="tab" aria-controls="pills-contact" aria-selected="false">Contact</a>
+ </li>
+</ul>
+<div class="tab-content" id="pills-tabContent">
+ <div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">...</div>
+ <div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">...</div>
+ <div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">...</div>
+</div>
+
And with vertical pills.
+Cillum ad ut irure tempor velit nostrud occaecat ullamco aliqua anim Lorem sint. Veniam sint duis incididunt do esse magna mollit excepteur laborum qui. Id id reprehenderit sit est eu aliqua occaecat quis et velit excepteur laborum mollit dolore eiusmod. Ipsum dolor in occaecat commodo et voluptate minim reprehenderit mollit pariatur. Deserunt non laborum enim et cillum eu deserunt excepteur ea incididunt minim occaecat.
+Culpa dolor voluptate do laboris laboris irure reprehenderit id incididunt duis pariatur mollit aute magna pariatur consectetur. Eu veniam duis non ut dolor deserunt commodo et minim in quis laboris ipsum velit id veniam. Quis ut consectetur adipisicing officia excepteur non sit. Ut et elit aliquip labore Lorem enim eu. Ullamco mollit occaecat dolore ipsum id officia mollit qui esse anim eiusmod do sint minim consectetur qui.
+Fugiat id quis dolor culpa eiusmod anim velit excepteur proident dolor aute qui magna. Ad proident laboris ullamco esse anim Lorem Lorem veniam quis Lorem irure occaecat velit nostrud magna nulla. Velit et et proident Lorem do ea tempor officia dolor. Reprehenderit Lorem aliquip labore est magna commodo est ea veniam consectetur.
+Eu dolore ea ullamco dolore Lorem id cupidatat excepteur reprehenderit consectetur elit id dolor proident in cupidatat officia. Voluptate excepteur commodo labore nisi cillum duis aliqua do. Aliqua amet qui mollit consectetur nulla mollit velit aliqua veniam nisi id do Lorem deserunt amet. Culpa ullamco sit adipisicing labore officia magna elit nisi in aute tempor commodo eiusmod.
+<div class="d-flex align-items-start">
+ <div class="nav flex-column nav-pills me-3" id="v-pills-tab" role="tablist" aria-orientation="vertical">
+ <a class="nav-link active" id="v-pills-home-tab" data-bs-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</a>
+ <a class="nav-link" id="v-pills-profile-tab" data-bs-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</a>
+ <a class="nav-link" id="v-pills-messages-tab" data-bs-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</a>
+ <a class="nav-link" id="v-pills-settings-tab" data-bs-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</a>
+ </div>
+ <div class="tab-content" id="v-pills-tabContent">
+ <div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">...</div>
+ <div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">...</div>
+ <div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">...</div>
+ <div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">...</div>
+ </div>
+</div>
+
You can activate a tab or pill navigation without writing any JavaScript by simply specifying data-bs-toggle="tab"
or data-bs-toggle="pill"
on an element. Use these data attributes on .nav-tabs
or .nav-pills
.
<!-- Nav tabs -->
+<ul class="nav nav-tabs" id="myTab" role="tablist">
+ <li class="nav-item" role="presentation">
+ <a class="nav-link active" id="home-tab" data-bs-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="messages-tab" data-bs-toggle="tab" href="#messages" role="tab" aria-controls="messages" aria-selected="false">Messages</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="settings-tab" data-bs-toggle="tab" href="#settings" role="tab" aria-controls="settings" aria-selected="false">Settings</a>
+ </li>
+</ul>
+
+<!-- Tab panes -->
+<div class="tab-content">
+ <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
+ <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
+ <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
+ <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
+</div>
+
Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
+var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
+triggerTabList.forEach(function (triggerEl) {
+ var tabTrigger = new bootstrap.Tab(triggerEl)
+
+ triggerEl.addEventListener('click', function (event) {
+ event.preventDefault()
+ tabTrigger.show()
+ })
+})
+
You can activate individual tabs in several ways:
+var triggerEl = document.querySelector('#myTab a[href="#profile"]')
+bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
+
+var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
+bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
+
To make tabs fade in, add .fade
to each .tab-pane
. The first tab pane must also have .show
to make the initial content visible.
<div class="tab-content">
+ <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
+ <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
+ <div class="tab-pane fade" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
+ <div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
+</div>
+
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
+ + +Activates a tab element and content container. Tab should have either a data-bs-target
or an href
targeting a container node in the DOM.
<ul class="nav nav-tabs" id="myTab" role="tablist">
+ <li class="nav-item" role="presentation">
+ <a class="nav-link active" id="home-tab" data-bs-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="messages-tab" data-bs-toggle="tab" href="#messages" role="tab" aria-controls="messages" aria-selected="false">Messages</a>
+ </li>
+ <li class="nav-item" role="presentation">
+ <a class="nav-link" id="settings-tab" data-bs-toggle="tab" href="#settings" role="tab" aria-controls="settings" aria-selected="false">Settings</a>
+ </li>
+</ul>
+
+<div class="tab-content">
+ <div class="tab-pane active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
+ <div class="tab-pane" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
+ <div class="tab-pane" id="messages" role="tabpanel" aria-labelledby="messages-tab">...</div>
+ <div class="tab-pane" id="settings" role="tabpanel" aria-labelledby="settings-tab">...</div>
+</div>
+
+<script>
+ var firstTabEl = document.querySelector('#myTab li:last-child a')
+ var firstTab = new bootstrap.Tab(firstTabEl)
+
+ firstTab.show()
+</script>
+
Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. Returns to the caller before the tab pane has actually been shown (i.e. before the shown.bs.tab
event occurs).
var someTabTriggerEl = document.querySelector('#someTabTrigger')
+ var tab = new bootstrap.Tab(someTabTriggerEl)
+
+ tab.show()
+
Destroys an element’s tab.
+Static method which allows you to get the tab instance associated with a DOM element
+var triggerEl = document.querySelector('#trigger')
+var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
+
When showing a new tab, the events fire in the following order:
+hide.bs.tab
(on the current active tab)show.bs.tab
(on the to-be-shown tab)hidden.bs.tab
(on the previous active tab, the same one as for the hide.bs.tab
event)shown.bs.tab
(on the newly-active just-shown tab, the same one as for the show.bs.tab
event)If no tab was already active, then the hide.bs.tab
and hidden.bs.tab
events will not be fired.
Event type | +Description | +
---|---|
show.bs.tab |
+ This event fires on tab show, but before the new tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
+
shown.bs.tab |
+ This event fires on tab show after a tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively. |
+
hide.bs.tab |
+ This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use event.target and event.relatedTarget to target the current active tab and the new soon-to-be-active tab, respectively. |
+
hidden.bs.tab |
+ This event fires after a new tab is shown (and thus the previous active tab is hidden). Use event.target and event.relatedTarget to target the previous active tab and the new active tab, respectively. |
+
var tabEl = document.querySelector('a[data-bs-toggle="tab"]')
+tabEl.addEventListener('shown.bs.tab', function (event) {
+ event.target // newly activated tab
+ event.relatedTarget // previous active tab
+})
+
Documentation and examples for showing pagination to indicate a series of related content exists across multiple pages.
+ + +We use a large block of connected links for our pagination, making links hard to miss and easily scalable—all while providing large hit areas. Pagination is built with list HTML elements so screen readers can announce the number of available links. Use a wrapping <nav>
element to identify it as a navigation section to screen readers and other assistive technologies.
In addition, as pages likely have more than one such navigation section, it’s advisable to provide a descriptive aria-label
for the <nav>
to reflect its purpose. For example, if the pagination component is used to navigate between a set of search results, an appropriate label could be aria-label="Search results pages"
.
<nav aria-label="Page navigation 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>
+</nav>
Looking to use an icon or symbol in place of text for some pagination links? Be sure to provide proper screen reader support with aria
attributes.
<nav aria-label="Page navigation example">
+ <ul class="pagination">
+ <li class="page-item">
+ <a class="page-link" href="#" aria-label="Previous">
+ <span aria-hidden="true">«</span>
+ </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="#" aria-label="Next">
+ <span aria-hidden="true">»</span>
+ </a>
+ </li>
+ </ul>
+</nav>
Pagination links are customizable for different circumstances. Use .disabled
for links that appear un-clickable and .active
to indicate the current page.
While the .disabled
class uses pointer-events: none
to try to disable the link functionality of <a>
s, that CSS property is not yet standardized and doesn’t account for keyboard navigation. As such, you should always add tabindex="-1"
on disabled links and use custom JavaScript to fully disable their functionality.
<nav aria-label="...">
+ <ul class="pagination">
+ <li class="page-item disabled">
+ <a class="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a>
+ </li>
+ <li class="page-item"><a class="page-link" href="#">1</a></li>
+ <li class="page-item active" aria-current="page">
+ <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>
+</nav>
You can optionally swap out active or disabled anchors for <span>
, or omit the anchor in the case of the prev/next arrows, to remove click functionality and prevent keyboard focus while retaining intended styles.
<nav aria-label="...">
+ <ul class="pagination">
+ <li class="page-item disabled">
+ <span class="page-link">Previous</span>
+ </li>
+ <li class="page-item"><a class="page-link" href="#">1</a></li>
+ <li class="page-item active" aria-current="page">
+ <span class="page-link">2</span>
+ </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>
+</nav>
Fancy larger or smaller pagination? Add .pagination-lg
or .pagination-sm
for additional sizes.
<nav aria-label="...">
+ <ul class="pagination pagination-lg">
+ <li class="page-item active" aria-current="page">
+ <span class="page-link">1</span>
+ </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>
+ </ul>
+</nav>
<nav aria-label="...">
+ <ul class="pagination pagination-sm">
+ <li class="page-item active" aria-current="page">
+ <span class="page-link">1</span>
+ </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>
+ </ul>
+</nav>
Change the alignment of pagination components with flexbox utilities.
+<nav aria-label="Page navigation example">
+ <ul class="pagination justify-content-center">
+ <li class="page-item disabled">
+ <a class="page-link" href="#" tabindex="-1" aria-disabled="true">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>
+</nav>
<nav aria-label="Page navigation example">
+ <ul class="pagination justify-content-end">
+ <li class="page-item disabled">
+ <a class="page-link" href="#" tabindex="-1" aria-disabled="true">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>
+</nav>
Documentation and examples for adding Bootstrap popovers, like those found in iOS, to any element on your site.
+ + +Things to know when using the popover plugin:
+bootstrap.bundle.min.js
/ bootstrap.bundle.js
which contains Popper in order for popovers to work!title
and content
values will never show a popover.container: 'body'
to avoid rendering problems in more complex components (like our input groups, button groups, etc)..disabled
or disabled
elements must be triggered on a wrapper element..text-nowrap
on your <a>
s to avoid this behavior.prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Keep reading to see how popovers work with some examples.
+One way to initialize all popovers on a page would be to select them by their data-bs-toggle
attribute:
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'))
+var popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
+ return new bootstrap.Popover(popoverTriggerEl)
+})
+
container
optionWhen you have some styles on a parent element that interfere with a popover, you’ll want to specify a custom container
so that the popover’s HTML appears within that element instead.
var popover = new bootstrap.Popover(document.querySelector('.example-popover'), {
+ container: 'body'
+})
+
<button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
Four options are available: top, right, bottom, and left aligned. Directions are mirrored when using Bootstrap in RTL.
+<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="top" data-bs-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
+ Popover on top
+</button>
+
+<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="right" data-bs-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
+ Popover on right
+</button>
+
+<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="bottom" data-bs-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
+ Popover on bottom
+</button>
+
+<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="left" data-bs-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
+ Popover on left
+</button>
+
Use the focus
trigger to dismiss popovers on the user’s next click of a different element than the toggle element.
For proper cross-browser and cross-platform behavior, you must use the <a>
tag, not the <button>
tag, and you also must include a tabindex
attribute.
+
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
var popover = new bootstrap.Popover(document.querySelector('.popover-dismiss'), {
+ trigger: 'focus'
+})
+
Elements with the disabled
attribute aren’t interactive, meaning users cannot hover or click them to trigger a popover (or tooltip). As a workaround, you’ll want to trigger the popover from a wrapper <div>
or <span>
and override the pointer-events
on the disabled element.
For disabled popover triggers, you may also prefer data-bs-trigger="hover"
so that the popover appears as immediate visual feedback to your users as they may not expect to click on a disabled element.
<span class="d-inline-block" data-bs-toggle="popover" data-bs-content="Disabled popover">
+ <button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
+</span>
Enable popovers via JavaScript:
+var exampleEl = document.getElementById('example')
+var popover = new bootstrap.Popover(exampleEl, options)
+
To allow keyboard users to activate your popovers, you should only add them to HTML elements that are traditionally keyboard-focusable and interactive (such as links or form controls). Although arbitrary HTML elements (such as <span>
s) can be made focusable by adding the tabindex="0"
attribute, this will add potentially annoying and confusing tab stops on non-interactive elements for keyboard users, and most assistive technologies currently do not announce the popover’s content in this situation. Additionally, do not rely solely on hover
as the trigger for your popovers, as this will make them impossible to trigger for keyboard users.
While you can insert rich, structured HTML in popovers with the html
option, we strongly recommend that you avoid adding an excessive amount of content. The way popovers currently work is that, once displayed, their content is tied to the trigger element with the aria-describedby
attribute. As a result, the entirety of the popover’s content will be announced to assistive technology users as one long, uninterrupted stream.
Additionally, while it is possible to also include interactive controls (such as form elements or links) in your popover (by adding these elements to the allowList
of allowed attributes and tags), be aware that currently the popover does not manage keyboard focus order. When a keyboard user opens a popover, focus remains on the triggering element, and as the popover usually does not immediately follow the trigger in the document’s structure, there is no guarantee that moving forward/pressing TAB will move a keyboard user into the popover itself. In short, simply adding interactive controls to a popover is likely to make these controls unreachable/unusable for keyboard users and users of assistive technologies, or at the very least make for an illogical overall focus order. In these cases, consider using a modal dialog instead.
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-animation=""
.
sanitize
, sanitizeFn
, and allowList
options cannot be supplied using data attributes.
+Name | +Type | +Default | +Description | +
---|---|---|---|
animation |
+ boolean | +true |
+ Apply a CSS fade transition to the popover | +
container |
+ string | element | false | +false |
+
+ Appends the popover to a specific element. Example: |
+
content |
+ string | element | function | +'' |
+
+ Default content value if If a function is given, it will be called with its |
+
delay |
+ number | object | +0 |
+
+ Delay showing and hiding the popover (ms) - does not apply to manual trigger type +If a number is supplied, delay is applied to both hide/show +Object structure is: |
+
html |
+ boolean | +false |
+ Insert HTML into the popover. If false, innerText property will be used to insert content into the DOM. Use text if you're worried about XSS attacks. |
+
placement |
+ string | function | +'right' |
+
+ How to position the popover - auto | top | bottom | left | right. When a function is used to determine the placement, it is called with the popover DOM node as its first argument and the triggering element DOM node as its second. The |
+
selector |
+ string | false | +false |
+ If a selector is provided, popover objects will be delegated to the specified targets. In practice, this is used to enable dynamic HTML content to have popovers added. See this and an informative example. | +
template |
+ string | +'<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-header"></h3><div class="popover-body"></div></div>' |
+
+ Base HTML to use when creating the popover. +The popover's The popover's
The outermost wrapper element should have the |
+
title |
+ string | element | function | +'' |
+
+ Default title value if If a function is given, it will be called with its |
+
trigger |
+ string | +'click' |
+ How popover is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space. manual cannot be combined with any other trigger. |
+
offset |
+ number | string | +0 |
+ Offset of the popover relative to its target. For more information refer to Popper's offset docs. | +
fallbackPlacement |
+ string | array | +'flip' |
+ Allow to specify which position Popper will use on fallback. For more information refer to + Popper's behavior docs | +
boundary |
+ string | element | +'scrollParent' |
+ Overflow constraint boundary of the popover. Accepts the values of 'viewport' , 'window' , 'scrollParent' , or an HTMLElement reference (JavaScript only). For more information refer to Popper's preventOverflow docs. |
+
customClass |
+ string | function | +'' |
+
+ Add classes to the popover when it is shown. Note that these classes will be added in addition to any classes specified in the template. To add multiple classes, separate them with spaces: You can also pass a function that should return a single string containing additional class names. + |
+
sanitize |
+ boolean | +true |
+ Enable or disable the sanitization. If activated 'template' , 'content' and 'title' options will be sanitized. |
+
allowList |
+ object | +Default value | +Object which contains allowed attributes and tags | +
sanitizeFn |
+ null | function | +null |
+ Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization. | +
popperConfig |
+ null | object | +null |
+ To change Bootstrap's default Popper config, see Popper's configuration | +
Options for individual popovers can alternatively be specified through the use of data attributes, as explained above. +
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
+ + +Reveals an element’s popover. Returns to the caller before the popover has actually been shown (i.e. before the shown.bs.popover
event occurs). This is considered a “manual” triggering of the popover. Popovers whose title and content are both zero-length are never displayed.
myPopover.show()
+
Hides an element’s popover. Returns to the caller before the popover has actually been hidden (i.e. before the hidden.bs.popover
event occurs). This is considered a “manual” triggering of the popover.
myPopover.hide()
+
Toggles an element’s popover. Returns to the caller before the popover has actually been shown or hidden (i.e. before the shown.bs.popover
or hidden.bs.popover
event occurs). This is considered a “manual” triggering of the popover.
myPopover.toggle()
+
Hides and destroys an element’s popover (Removes stored data on the DOM element). Popovers that use delegation (which are created using the selector
option) cannot be individually destroyed on descendant trigger elements.
myPopover.dispose()
+
Gives an element’s popover the ability to be shown. Popovers are enabled by default.
+myPopover.enable()
+
Removes the ability for an element’s popover to be shown. The popover will only be able to be shown if it is re-enabled.
+myPopover.disable()
+
Toggles the ability for an element’s popover to be shown or hidden.
+myPopover.toggleEnabled()
+
Updates the position of an element’s popover.
+myPopover.update()
+
Static method which allows you to get the popover instance associated with a DOM element
+var exampleTriggerEl = document.getElementById('example')
+var popover = bootstrap.Popover.getInstance(exampleTriggerEl) // Returns a Bootstrap popover instance
+
Event type | +Description | +
---|---|
show.bs.popover | +This event fires immediately when the show instance method is called. |
+
shown.bs.popover | +This event is fired when the popover has been made visible to the user (will wait for CSS transitions to complete). | +
hide.bs.popover | +This event is fired immediately when the hide instance method has been called. |
+
hidden.bs.popover | +This event is fired when the popover has finished being hidden from the user (will wait for CSS transitions to complete). | +
inserted.bs.popover | +This event is fired after the show.bs.popover event when the popover template has been added to the DOM. |
+
var myPopoverTrigger = document.getElementById('myPopover')
+myPopoverTrigger.addEventListener('hidden.bs.popover', function () {
+ // do something...
+})
+
Documentation and examples for using Bootstrap custom progress bars featuring support for stacked bars, animated backgrounds, and text labels.
+ + +Progress components are built with two HTML elements, some CSS to set the width, and a few attributes. We don’t use the HTML5 <progress>
element, ensuring you can stack progress bars, animate them, and place text labels over them.
.progress
as a wrapper to indicate the max value of the progress bar..progress-bar
to indicate the progress so far..progress-bar
requires an inline style, utility class, or custom CSS to set their width..progress-bar
also requires some role
and aria
attributes to make it accessible.Put that all together, and you have the following examples.
+<div class="progress">
+ <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
Bootstrap provides a handful of utilities for setting width. Depending on your needs, these may help with quickly configuring progress.
+<div class="progress">
+ <div class="progress-bar w-75" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
Add labels to your progress bars by placing text within the .progress-bar
.
<div class="progress">
+ <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div>
+</div>
We only set a height
value on the .progress
, so if you change that value the inner .progress-bar
will automatically resize accordingly.
<div class="progress" style="height: 1px;">
+ <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress" style="height: 20px;">
+ <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
Use background utility classes to change the appearance of individual progress bars.
+<div class="progress">
+ <div class="progress-bar bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
Include multiple progress bars in a progress component if you need.
+<div class="progress">
+ <div class="progress-bar" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
+ <div class="progress-bar bg-success" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>
+ <div class="progress-bar bg-info" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
Add .progress-bar-striped
to any .progress-bar
to apply a stripe via CSS gradient over the progress bar’s background color.
<div class="progress">
+ <div class="progress-bar progress-bar-striped" role="progressbar" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar progress-bar-striped bg-success" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar progress-bar-striped bg-info" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar progress-bar-striped bg-warning" role="progressbar" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
+<div class="progress">
+ <div class="progress-bar progress-bar-striped bg-danger" role="progressbar" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
+</div>
The striped gradient can also be animated. Add .progress-bar-animated
to .progress-bar
to animate the stripes right to left via CSS3 animations.
<div class="progress">
+ <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div>
+</div>
+
Automatically update Bootstrap navigation or list group components based on scroll position to indicate which link is currently active in the viewport.
+ + +Scrollspy has a few requirements to function properly:
+position: relative;
on the element you’re spying on, usually the <body>
.<a>
) are required and must point to an element with that id
.When successfully implemented, your nav or list group will update accordingly, moving the .active
class from one item to the next based on their associated targets.
If you’re making a scrollable container (other than the <body>
), be sure to have a height
set and overflow-y: scroll;
applied to it—alongside a tabindex="0"
to ensure keyboard access.
+
Scroll the area below the navbar and watch the active class change. The dropdown items will be highlighted as well.
+Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
+Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard. Freegan beard aliqua cupidatat mcsweeney's vero. Cupidatat four loko nisi, ea helvetica nulla carles. Tattooed cosby sweater food truck, mcsweeney's quis non freegan vinyl. Lo-fi wes anderson +1 sartorial. Carles non aesthetic exercitation quis gentrify. Brooklyn adipisicing craft beer vice keytar deserunt.
+Occaecat commodo aliqua delectus. Fap craft beer deserunt skateboard ea. Lomo bicycle rights adipisicing banh mi, velit ea sunt next level locavore single-origin coffee in magna veniam. High life id vinyl, echo park consequat quis aliquip banh mi pitchfork. Vero VHS est adipisicing. Consectetur nisi DIY minim messenger bag. Cred ex in, sustainable delectus consectetur fanny pack iphone.
+In incididunt echo park, officia deserunt mcsweeney's proident master cleanse thundercats sapiente veniam. Excepteur VHS elit, proident shoreditch +1 biodiesel laborum craft beer. Single-origin coffee wayfarers irure four loko, cupidatat terry richardson master cleanse. Assumenda you probably haven't heard of them art party fanny pack, tattooed nulla cardigan tempor ad. Proident wolf nesciunt sartorial keffiyeh eu banh mi sustainable. Elit wolf voluptate, lo-fi ea portland before they sold out four loko. Locavore enim nostrud mlkshk brooklyn nesciunt.
+Ad leggings keytar, brunch id art party dolor labore. Pitchfork yr enim lo-fi before they sold out qui. Tumblr farm-to-table bicycle rights whatever. Anim keffiyeh carles cardigan. Velit seitan mcsweeney's photo booth 3 wolf moon irure. Cosby sweater lomo jean shorts, williamsburg hoodie minim qui you probably haven't heard of them et cardigan trust fund culpa biodiesel wes anderson aesthetic. Nihil tattooed accusamus, cred irony biodiesel keffiyeh artisan ullamco consequat.
+Keytar twee blog, culpa messenger bag marfa whatever delectus food truck. Sapiente synth id assumenda. Locavore sed helvetica cliche irony, thundercats you probably haven't heard of them consequat hoodie gluten-free lo-fi fap aliquip. Labore elit placeat before they sold out, terry richardson proident brunch nesciunt quis cosby sweater pariatur keffiyeh ut helvetica artisan. Cardigan craft beer seitan readymade velit. VHS chambray laboris tempor veniam. Anim mollit minim commodo ullamco thundercats. +
+<nav id="navbar-example2" class="navbar navbar-light bg-light px-3">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <ul class="nav nav-pills">
+ <li class="nav-item">
+ <a class="nav-link" href="#fat">@fat</a>
+ </li>
+ <li class="nav-item">
+ <a class="nav-link" href="#mdo">@mdo</a>
+ </li>
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
+ <ul class="dropdown-menu dropdown-menu-end">
+ <li><a class="dropdown-item" href="#one">one</a></li>
+ <li><a class="dropdown-item" href="#two">two</a></li>
+ <li><hr class="dropdown-divider"></li>
+ <li><a class="dropdown-item" href="#three">three</a></li>
+ </ul>
+ </li>
+ </ul>
+</nav>
+<div data-bs-spy="scroll" data-bs-target="#navbar-example2" data-bs-offset="0" tabindex="0">
+ <h4 id="fat">@fat</h4>
+ <p>...</p>
+ <h4 id="mdo">@mdo</h4>
+ <p>...</p>
+ <h4 id="one">one</h4>
+ <p>...</p>
+ <h4 id="two">two</h4>
+ <p>...</p>
+ <h4 id="three">three</h4>
+ <p>...</p>
+</div>
+
Scrollspy also works with nested .nav
s. If a nested .nav
is .active
, its parents will also be .active
. Scroll the area next to the navbar and watch the active class change.
Ex consequat commodo adipisicing exercitation aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Do aute ipsum ipsum ullamco cillum consectetur ut et aute consectetur labore. Fugiat laborum incididunt tempor eu consequat enim dolore proident. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua et aliqua officia quis et incididunt voluptate non anim reprehenderit adipisicing dolore ut consequat deserunt mollit dolore. Aliquip nulla enim veniam non fugiat id cupidatat nulla elit cupidatat commodo velit ut eiusmod cupidatat elit dolore.
+Amet tempor mollit aliquip pariatur excepteur commodo do ea cillum commodo Lorem et occaecat elit qui et. Aliquip labore ex ex esse voluptate occaecat Lorem ullamco deserunt. Aliqua cillum excepteur irure consequat id quis ea. Sit proident ullamco aute magna pariatur nostrud labore. Reprehenderit aliqua commodo eiusmod aliquip est do duis amet proident magna consectetur consequat eu commodo fugiat non quis. Enim aliquip exercitation ullamco adipisicing voluptate excepteur minim exercitation minim minim commodo adipisicing exercitation officia nisi adipisicing. Anim id duis qui consequat labore adipisicing sint dolor elit cillum anim et fugiat.
+Cillum nisi deserunt magna eiusmod qui eiusmod velit voluptate pariatur laborum sunt enim. Irure laboris mollit consequat incididunt sint et culpa culpa incididunt adipisicing magna magna occaecat. Nulla ipsum cillum eiusmod sint elit excepteur ea labore enim consectetur in labore anim. Proident ullamco ipsum esse elit ut Lorem eiusmod dolor et eiusmod. Anim occaecat nulla in non consequat eiusmod velit incididunt.
+Quis magna Lorem anim amet ipsum do mollit sit cillum voluptate ex nulla tempor. Laborum consequat non elit enim exercitation cillum aliqua consequat id aliqua. Esse ex consectetur mollit voluptate est in duis laboris ad sit ipsum anim Lorem. Incididunt veniam velit elit elit veniam Lorem aliqua quis ullamco deserunt sit enim elit aliqua esse irure. Laborum nisi sit est tempor laborum mollit labore officia laborum excepteur commodo non commodo dolor excepteur commodo. Ipsum fugiat ex est consectetur ipsum commodo tempor sunt in proident.
+Quis anim sit do amet fugiat dolor velit sit ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat excepteur aliquip culpa aute tempor reprehenderit. Deserunt tempor mollit elit ex pariatur dolore velit fugiat mollit culpa irure ullamco est ex ullamco excepteur.
+Deserunt quis elit Lorem eiusmod amet enim enim amet minim Lorem proident nostrud. Ea id dolore anim exercitation aute fugiat labore voluptate cillum do laboris labore. Ex velit exercitation nisi enim labore reprehenderit labore nostrud ut ut. Esse officia sunt duis aliquip ullamco tempor eiusmod deserunt irure nostrud irure. Ullamco proident veniam laboris ea consectetur magna sunt ex exercitation aliquip minim enim culpa occaecat exercitation. Est tempor excepteur aliquip laborum consequat do deserunt laborum esse eiusmod irure proident ipsum esse qui.
+Labore sit culpa commodo elit adipisicing sit aliquip elit proident voluptate minim mollit nostrud aute reprehenderit do. Mollit excepteur eu Lorem ipsum anim commodo sint labore Lorem in exercitation velit incididunt. Occaecat consectetur nisi in occaecat proident minim enim sunt reprehenderit exercitation cupidatat et do officia. Aliquip consequat ad labore labore mollit ut amet. Sit pariatur tempor proident in veniam culpa aliqua excepteur elit magna fugiat eiusmod amet officia.
+<nav id="navbar-example3" class="navbar navbar-light bg-light">
+ <a class="navbar-brand" href="#">Navbar</a>
+ <nav class="nav nav-pills flex-column">
+ <a class="nav-link" href="#item-1">Item 1</a>
+ <nav class="nav nav-pills flex-column">
+ <a class="nav-link ms-3 my-1" href="#item-1-1">Item 1-1</a>
+ <a class="nav-link ms-3 my-1" href="#item-1-2">Item 1-2</a>
+ </nav>
+ <a class="nav-link" href="#item-2">Item 2</a>
+ <a class="nav-link" href="#item-3">Item 3</a>
+ <nav class="nav nav-pills flex-column">
+ <a class="nav-link ms-3 my-1" href="#item-3-1">Item 3-1</a>
+ <a class="nav-link ms-3 my-1" href="#item-3-2">Item 3-2</a>
+ </nav>
+ </nav>
+</nav>
+
+<div data-bs-spy="scroll" data-bs-target="#navbar-example3" data-bs-offset="0" tabindex="0">
+ <h4 id="item-1">Item 1</h4>
+ <p>...</p>
+ <h5 id="item-1-1">Item 1-1</h5>
+ <p>...</p>
+ <h5 id="item-1-2">Item 1-2</h5>
+ <p>...</p>
+ <h4 id="item-2">Item 2</h4>
+ <p>...</p>
+ <h4 id="item-3">Item 3</h4>
+ <p>...</p>
+ <h5 id="item-3-1">Item 3-1</h5>
+ <p>...</p>
+ <h5 id="item-3-2">Item 3-2</h5>
+ <p>...</p>
+</div>
+
Scrollspy also works with .list-group
s. Scroll the area next to the list group and watch the active class change.
Ex consequat commodo adipisicing exercitation aute excepteur occaecat ullamco duis aliqua id magna ullamco eu. Do aute ipsum ipsum ullamco cillum consectetur ut et aute consectetur labore. Fugiat laborum incididunt tempor eu consequat enim dolore proident. Qui laborum do non excepteur nulla magna eiusmod consectetur in. Aliqua et aliqua officia quis et incididunt voluptate non anim reprehenderit adipisicing dolore ut consequat deserunt mollit dolore. Aliquip nulla enim veniam non fugiat id cupidatat nulla elit cupidatat commodo velit ut eiusmod cupidatat elit dolore.
+Quis magna Lorem anim amet ipsum do mollit sit cillum voluptate ex nulla tempor. Laborum consequat non elit enim exercitation cillum aliqua consequat id aliqua. Esse ex consectetur mollit voluptate est in duis laboris ad sit ipsum anim Lorem. Incididunt veniam velit elit elit veniam Lorem aliqua quis ullamco deserunt sit enim elit aliqua esse irure. Laborum nisi sit est tempor laborum mollit labore officia laborum excepteur commodo non commodo dolor excepteur commodo. Ipsum fugiat ex est consectetur ipsum commodo tempor sunt in proident.
+Quis anim sit do amet fugiat dolor velit sit ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat excepteur aliquip culpa aute tempor reprehenderit. Deserunt tempor mollit elit ex pariatur dolore velit fugiat mollit culpa irure ullamco est ex ullamco excepteur.
+Quis anim sit do amet fugiat dolor velit sit ea ea do reprehenderit culpa duis. Nostrud aliqua ipsum fugiat minim proident occaecat excepteur aliquip culpa aute tempor reprehenderit. Deserunt tempor mollit elit ex pariatur dolore velit fugiat mollit culpa irure ullamco est ex ullamco excepteur.
+<div id="list-example" class="list-group">
+ <a class="list-group-item list-group-item-action" href="#list-item-1">Item 1</a>
+ <a class="list-group-item list-group-item-action" href="#list-item-2">Item 2</a>
+ <a class="list-group-item list-group-item-action" href="#list-item-3">Item 3</a>
+ <a class="list-group-item list-group-item-action" href="#list-item-4">Item 4</a>
+</div>
+<div data-bs-spy="scroll" data-bs-target="#list-example" data-bs-offset="0" class="scrollspy-example" tabindex="0">
+ <h4 id="list-item-1">Item 1</h4>
+ <p>...</p>
+ <h4 id="list-item-2">Item 2</h4>
+ <p>...</p>
+ <h4 id="list-item-3">Item 3</h4>
+ <p>...</p>
+ <h4 id="list-item-4">Item 4</h4>
+ <p>...</p>
+</div>
+
To easily add scrollspy behavior to your topbar navigation, add data-bs-spy="scroll"
to the element you want to spy on (most typically this would be the <body>
). Then add the data-bs-target
attribute with the ID or class of the parent element of any Bootstrap .nav
component.
body {
+ position: relative;
+}
+
<body data-bs-spy="scroll" data-bs-target="#navbar-example">
+ ...
+ <div id="navbar-example">
+ <ul class="nav nav-tabs" role="tablist">
+ ...
+ </ul>
+ </div>
+ ...
+</body>
+
After adding position: relative;
in your CSS, call the scrollspy via JavaScript:
var scrollSpy = new bootstrap.ScrollSpy(document.body, {
+ target: '#navbar-example'
+})
+
Navbar links must have resolvable id targets. For example, a <a href="#home">home</a>
must correspond to something in the DOM like <div id="home"></div>
.
+
Target elements that are not visible will be ignored and their corresponding nav items will never be highlighted. +
When using scrollspy in conjunction with adding or removing of elements from the DOM, you’ll need to call the refresh method like so:
+var dataSpyList = [].slice.call(document.querySelectorAll('[data-bs-spy="scroll"]'))
+dataSpyList.forEach(function (dataSpyEl) {
+ bootstrap.ScrollSpy.getInstance(dataSpyEl)
+ .refresh()
+})
+
Destroys an element’s scrollspy. (Removes stored data on the DOM element)
+Static method which allows you to get the scrollspy instance associated with a DOM element
+var scrollSpyContentEl = document.getElementById('content')
+var scrollSpy = bootstrap.ScrollSpy.getInstance(scrollSpyContentEl) // Returns a Bootstrap scrollspy instance
+
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-offset=""
.
Name | +Type | +Default | +Description | +
---|---|---|---|
offset |
+ number | +10 |
+ Pixels to offset from top when calculating position of scroll. | +
method |
+ string | +auto |
+ Finds which section the spied element is in. auto will choose the best method to get scroll coordinates. offset will use the Element.getBoundingClientRect() method to get scroll coordinates. position will use the HTMLElement.offsetTop and HTMLElement.offsetLeft properties to get scroll coordinates. |
+
target |
+ string | jQuery object | DOM element | ++ | Specifies element to apply Scrollspy plugin. | +
Event type | +Description | +
---|---|
activate.bs.scrollspy |
+ This event fires on the scroll element whenever a new item becomes activated by the scrollspy. | +
var firstScrollSpyEl = document.querySelector('[data-bs-spy="scroll"]')
+firstScrollSpyEl.addEventListener('activate.bs.scrollspy', function () {
+ // do something...
+})
+
Indicate the loading state of a component or page with Bootstrap spinners, built entirely with HTML, CSS, and no JavaScript.
+ + +Bootstrap “spinners” can be used to show the loading state in your projects. They’re built only with HTML and CSS, meaning you don’t need any JavaScript to create them. You will, however, need some custom JavaScript to toggle their visibility. Their appearance, alignment, and sizing can be easily customized with our amazing utility classes.
+For accessibility purposes, each loader here includes role="status"
and a nested <span class="visually-hidden">Loading...</span>
.
prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Use the border spinners for a lightweight loading indicator.
+<div class="spinner-border" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
The border spinner uses currentColor
for its border-color
, meaning you can customize the color with text color utilities. You can use any of our text color utilities on the standard spinner.
<div class="spinner-border text-primary" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-border text-secondary" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-border text-success" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-border text-danger" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-border text-warning" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-border text-info" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-border text-light" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-border text-dark" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
border-color
utilities? Each border spinner specifies a transparent
border for at least one side, so .border-{color}
utilities would override that.
+If you don’t fancy a border spinner, switch to the grow spinner. While it doesn’t technically spin, it does repeatedly grow!
+<div class="spinner-grow" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
Once again, this spinner is built with currentColor
, so you can easily change its appearance with text color utilities. Here it is in blue, along with the supported variants.
<div class="spinner-grow text-primary" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow text-secondary" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow text-success" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow text-danger" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow text-warning" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow text-info" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow text-light" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow text-dark" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
Spinners in Bootstrap are built with rem
s, currentColor
, and display: inline-flex
. This means they can easily be resized, recolored, and quickly aligned.
Use margin utilities like .m-5
for easy spacing.
<div class="spinner-border m-5" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
Use flexbox utilities, float utilities, or text alignment utilities to place spinners exactly where you need them in any situation.
+<div class="d-flex justify-content-center">
+ <div class="spinner-border" role="status">
+ <span class="visually-hidden">Loading...</span>
+ </div>
+</div>
<div class="d-flex align-items-center">
+ <strong>Loading...</strong>
+ <div class="spinner-border ms-auto" role="status" aria-hidden="true"></div>
+</div>
<div class="clearfix">
+ <div class="spinner-border float-end" role="status">
+ <span class="visually-hidden">Loading...</span>
+ </div>
+</div>
<div class="text-center">
+ <div class="spinner-border" role="status">
+ <span class="visually-hidden">Loading...</span>
+ </div>
+</div>
Add .spinner-border-sm
and .spinner-grow-sm
to make a smaller spinner that can quickly be used within other components.
<div class="spinner-border spinner-border-sm" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow spinner-grow-sm" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
Or, use custom CSS or inline styles to change the dimensions as needed.
+<div class="spinner-border" style="width: 3rem; height: 3rem;" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
+<div class="spinner-grow" style="width: 3rem; height: 3rem;" role="status">
+ <span class="visually-hidden">Loading...</span>
+</div>
Use spinners within buttons to indicate an action is currently processing or taking place. You may also swap the text out of the spinner element and utilize button text as needed.
+<button class="btn btn-primary" type="button" disabled>
+ <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
+ <span class="visually-hidden">Loading...</span>
+</button>
+<button class="btn btn-primary" type="button" disabled>
+ <span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
+ Loading...
+</button>
<button class="btn btn-primary" type="button" disabled>
+ <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
+ <span class="visually-hidden">Loading...</span>
+</button>
+<button class="btn btn-primary" type="button" disabled>
+ <span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
+ Loading...
+</button>
Push notifications to your visitors with a toast, a lightweight and easily customizable alert message.
+ + +Toasts are lightweight notifications designed to mimic the push notifications that have been popularized by mobile and desktop operating systems. They’re built with flexbox, so they’re easy to align and position.
+Things to know when using the toast plugin:
+autohide: false
.prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+To encourage extensible and predictable toasts, we recommend a header and body. Toast headers use display: flex
, allowing easy alignment of content thanks to our margin and flexbox utilities.
Toasts are as flexible as you need and have very little required markup. At a minimum, we require a single element to contain your “toasted” content and strongly encourage a dismiss button.
+<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small>11 mins ago</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+</div>
Toasts are slightly translucent, too, so they blend over whatever they might appear over. For browsers that support the backdrop-filter
CSS property, we’ll also attempt to blur the elements under a toast.
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small class="text-muted">11 mins ago</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+</div>
You can stack toasts by wrapping them in a toast container, which will vertically add some spacing.
+<div class="toast-container">
+ <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small class="text-muted">just now</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ See? Just like this.
+ </div>
+ </div>
+
+ <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small class="text-muted">2 seconds ago</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ Heads up, toasts will stack automatically
+ </div>
+ </div>
+</div>
Customize your toasts by removing sub-components, tweaking with utilities, or adding your own markup. Here we’ve created a simpler toast by removing the default .toast-header
, adding a custom hide icon from Bootstrap Icons, and using some flexbox utilities to adjust the layout.
<div class="toast d-flex align-items-center" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+ <button type="button" class="btn-close ms-auto me-2" data-bs-dismiss="toast" aria-label="Close"></button>
+</div>
Alternatively, you can also add additional controls and components to toasts.
+<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ <div class="mt-2 pt-2 border-top">
+ <button type="button" class="btn btn-primary btn-sm">Take action</button>
+ <button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="toast">Close</button>
+ </div>
+ </div>
+</div>
Building on the above example, you can create different toast color schemes with our color utilities. Here we’ve added .bg-primary
and .text-white
to the .toast
, and then added .text-white
to our close button. For a crisp edge, we remove the default border with .border-0
.
<div class="toast d-flex align-items-center text-white bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+ <button type="button" class="btn-close btn-close-white ms-auto me-2" data-bs-dismiss="toast" aria-label="Close"></button>
+</div>
Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you’re only ever going to show one toast at a time, put the positioning styles right on the .toast
.
<form>
+ <div class="form-group mb-3">
+ <label for="selectToastPlacement">Toast placement</label>
+ <select class="form-select mt-2" id="selectToastPlacement">
+ <option value="" selected>Select a position...</option>
+ <option value="top-0 start-0">Top left</option>
+ <option value="top-0 start-50 translate-middle-x">Top center</option>
+ <option value="top-0 end-0">Top right</option>
+ <option value="top-50 start-0 translate-middle-y">Middle left</option>
+ <option value="top-50 start-50 translate-middle">Middle center</option>
+ <option value="top-50 end-0 translate-middle-y">Middle right</option>
+ <option value="bottom-0 start-0">Bottom left</option>
+ <option value="bottom-0 start-50 translate-middle-x">Bottom center</option>
+ <option value="bottom-0 end-0">Bottom right</option>
+ </select>
+ </div>
+</form>
+<div aria-live="polite" aria-atomic="true" class="bg-dark position-relative bd-example-toasts">
+ <div class="toast-container position-absolute p-3" id="toastPlacement">
+ <div class="toast">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small>11 mins ago</small>
+ </div>
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+ </div>
+ </div>
+</div>
For systems that generate more notifications, consider using a wrapping element so they can easily stack.
+<div aria-live="polite" aria-atomic="true" class="position-relative">
+ <!-- Position it: -->
+ <!-- - `.toast-container` for spacing between toasts -->
+ <!-- - `.position-absolute`, `top-0` & `end-0` to position the toasts in the upper right corner -->
+ <!-- - `.p-3` to prevent the toasts from sticking to the edge of the container -->
+ <div class="toast-container position-absolute top-0 end-0 p-3">
+
+ <!-- Then put toasts within -->
+ <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small class="text-muted">just now</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ See? Just like this.
+ </div>
+ </div>
+
+ <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small class="text-muted">2 seconds ago</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ Heads up, toasts will stack automatically
+ </div>
+ </div>
+ </div>
+</div>
You can also get fancy with flexbox utilities to align toasts horizontally and/or vertically.
+<!-- Flexbox container for aligning the toasts -->
+<div aria-live="polite" aria-atomic="true" class="d-flex justify-content-center align-items-center w-100">
+
+ <!-- Then put toasts within -->
+ <div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small>11 mins ago</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+ </div>
+</div>
Toasts are intended to be small interruptions to your visitors or users, so to help those with screen readers and similar assistive technologies, you should wrap your toasts in an aria-live
region. Changes to live regions (such as injecting/updating a toast component) are automatically announced by screen readers without needing to move the user’s focus or otherwise interrupt the user. Additionally, include aria-atomic="true"
to ensure that the entire toast is always announced as a single (atomic) unit, rather than announcing what was changed (which could lead to problems if you only update part of the toast’s content, or if displaying the same toast content at a later point in time). If the information needed is important for the process, e.g. for a list of errors in a form, then use the alert component instead of toast.
Note that the live region needs to be present in the markup before the toast is generated or updated. If you dynamically generate both at the same time and inject them into the page, they will generally not be announced by assistive technologies.
+You also need to adapt the role
and aria-live
level depending on the content. If it’s an important message like an error, use role="alert" aria-live="assertive"
, otherwise use role="status" aria-live="polite"
attributes.
As the content you’re displaying changes, be sure to update the delay
timeout to ensure people have enough time to read the toast.
<div class="toast" role="alert" aria-live="polite" aria-atomic="true" data-bs-delay="10000">
+ <div role="alert" aria-live="assertive" aria-atomic="true">...</div>
+</div>
+
When using autohide: false
, you must add a close button to allow users to dismiss the toast.
<div role="alert" aria-live="assertive" aria-atomic="true" class="toast" data-bs-autohide="false">
+ <div class="toast-header">
+ <img src="..." class="rounded me-2" alt="...">
+ <strong class="me-auto">Bootstrap</strong>
+ <small>11 mins ago</small>
+ <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
+ </div>
+ <div class="toast-body">
+ Hello, world! This is a toast message.
+ </div>
+</div>
Initialize toasts via JavaScript:
+var toastElList = [].slice.call(document.querySelectorAll('.toast'))
+var toastList = toastElList.map(function (toastEl) {
+ return new bootstrap.Toast(toastEl, option)
+})
+
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-animation=""
.
Name | +Type | +Default | +Description | +
---|---|---|---|
animation |
+ boolean | +true |
+ Apply a CSS fade transition to the toast | +
autohide |
+ boolean | +true |
+ Auto hide the toast | +
delay |
+ number | +
+ 5000
+ |
+ Delay hiding the toast (ms) | +
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
+ + +Reveals an element’s toast. Returns to the caller before the toast has actually been shown (i.e. before the shown.bs.toast
event occurs).
+You have to manually call this method, instead your toast won’t show.
toast.show()
+
Hides an element’s toast. Returns to the caller before the toast has actually been hidden (i.e. before the hidden.bs.toast
event occurs). You have to manually call this method if you made autohide
to false
.
toast.hide()
+
Hides an element’s toast. Your toast will remain on the DOM but won’t show anymore.
+toast.dispose()
+
Event type | +Description | +
---|---|
show.bs.toast |
+ This event fires immediately when the show instance method is called. |
+
shown.bs.toast |
+ This event is fired when the toast has been made visible to the user. | +
hide.bs.toast |
+ This event is fired immediately when the hide instance method has been called. |
+
hidden.bs.toast |
+ This event is fired when the toast has finished being hidden from the user. | +
var myToastEl = document.getElementById('myToast')
+myToastEl.addEventListener('hidden.bs.toast', function () {
+ // do something...
+})
+
Documentation and examples for adding custom Bootstrap tooltips with CSS and JavaScript using CSS3 for animations and data-bs-attributes for local title storage.
+ + +Things to know when using the tooltip plugin:
+bootstrap.bundle.min.js
/ bootstrap.bundle.js
which contains Popper in order for tooltips to work!container: 'body'
to avoid rendering problems in more complex components (like our input groups, button groups, etc)..disabled
or disabled
elements must be triggered on a wrapper element.white-space: nowrap;
on your <a>
s to avoid this behavior.prefers-reduced-motion
media query. See the reduced motion section of our accessibility documentation.
+Got all that? Great, let’s see how they work with some examples.
+One way to initialize all tooltips on a page would be to select them by their data-bs-toggle
attribute:
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
+var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
+ return new bootstrap.Tooltip(tooltipTriggerEl)
+})
+
Hover over the links below to see tooltips:
+Tight pants next level keffiyeh you probably haven't heard of them. Photo booth beard raw denim letterpress vegan messenger bag stumptown. Farm-to-table seitan, mcsweeney's fixie sustainable quinoa 8-bit american apparel have a terry richardson vinyl chambray. Beard stumptown, cardigans banh mi lomo thundercats. Tofu biodiesel williamsburg marfa, four loko mcsweeney's cleanse vegan chambray. A really ironic artisan whatever keytar, scenester farm-to-table banksy Austin twitter handle freegan cred raw denim single-origin coffee viral. +
+Hover over the buttons below to see the four tooltips directions: top, right, bottom, and left. Directions are mirrored when using Bootstrap in RTL.
+<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">
+ Tooltip on top
+</button>
+<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" title="Tooltip on right">
+ Tooltip on right
+</button>
+<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Tooltip on bottom">
+ Tooltip on bottom
+</button>
+<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" title="Tooltip on left">
+ Tooltip on left
+</button>
+
And with custom HTML added:
+<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
+ Tooltip with HTML
+</button>
+
With an SVG:
+The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element.
+Trigger the tooltip via JavaScript:
+var exampleEl = document.getElementById('example')
+var tooltip = new bootstrap.Tooltip(exampleEl, options)
+
auto
and scroll
Tooltip position attempts to automatically change when a parent container has overflow: auto
or overflow: scroll
like our .table-responsive
, but still keeps the original placement’s positioning. To resolve, set the boundary
option to anything other than default value, 'scrollParent'
, such as 'window'
:
var exampleEl = document.getElementById('example')
+var tooltip = new bootstrap.Tooltip(exampleEl, {
+ boundary: 'window'
+})
+
The required markup for a tooltip is only a data
attribute and title
on the HTML element you wish to have a tooltip. The generated markup of a tooltip is rather simple, though it does require a position (by default, set to top
by the plugin).
You should only add tooltips to HTML elements that are traditionally keyboard-focusable and interactive (such as links or form controls). Although arbitrary HTML elements (such as <span>
s) can be made focusable by adding the tabindex="0"
attribute, this will add potentially annoying and confusing tab stops on non-interactive elements for keyboard users, and most assistive technologies currently do not announce the tooltip in this situation. Additionally, do not rely solely on hover
as the trigger for your tooltip, as this will make your tooltips impossible to trigger for keyboard users.
+
<!-- HTML to write -->
+<a href="#" data-bs-toggle="tooltip" title="Some tooltip text!">Hover over me</a>
+
+<!-- Generated markup by the plugin -->
+<div class="tooltip bs-tooltip-top" role="tooltip">
+ <div class="tooltip-arrow"></div>
+ <div class="tooltip-inner">
+ Some tooltip text!
+ </div>
+</div>
+
Elements with the disabled
attribute aren’t interactive, meaning users cannot focus, hover, or click them to trigger a tooltip (or popover). As a workaround, you’ll want to trigger the tooltip from a wrapper <div>
or <span>
, ideally made keyboard-focusable using tabindex="0"
, and override the pointer-events
on the disabled element.
<span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" title="Disabled tooltip">
+ <button class="btn btn-primary" style="pointer-events: none;" type="button" disabled>Disabled button</button>
+</span>
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-bs-
, as in data-bs-animation=""
.
sanitize
, sanitizeFn
, and allowList
options cannot be supplied using data attributes.
+Name | +Type | +Default | +Description | +
---|---|---|---|
animation |
+ boolean | +true |
+ Apply a CSS fade transition to the tooltip | +
container |
+ string | element | false | +false |
+
+ Appends the tooltip to a specific element. Example: |
+
delay |
+ number | object | +0 |
+
+ Delay showing and hiding the tooltip (ms) - does not apply to manual trigger type +If a number is supplied, delay is applied to both hide/show +Object structure is: |
+
html |
+ boolean | +false |
+
+ Allow HTML in the tooltip. +If true, HTML tags in the tooltip's Use text if you're worried about XSS attacks. + |
+
placement |
+ string | function | +'top' |
+
+ How to position the tooltip - auto | top | bottom | left | right. When a function is used to determine the placement, it is called with the tooltip DOM node as its first argument and the triggering element DOM node as its second. The |
+
selector |
+ string | false | +false |
+ If a selector is provided, tooltip objects will be delegated to the specified targets. In practice, this is used to also apply tooltips to dynamically added DOM elements (jQuery.on support). See this and an informative example. |
+
template |
+ string | +'<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' |
+
+ Base HTML to use when creating the tooltip. +The tooltip's
The outermost wrapper element should have the |
+
title |
+ string | element | function | +'' |
+
+ Default title value if If a function is given, it will be called with its |
+
trigger |
+ string | +'hover focus' |
+
+ How tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space. +
|
+
fallbackPlacement |
+ null | array | +null |
+ Allow to specify which position Popper will use on fallback. For more information refer to + Popper's behavior docs | +
boundary |
+ string | element | +'clippingParents' |
+ Overflow constraint boundary of the tooltip. By default it's 'clippingParents' and can accept an HTMLElement reference (JavaScript only). For more information refer to Popper's preventOverflow docs. |
+
customClass |
+ string | function | +'' |
+
+ Add classes to the tooltip when it is shown. Note that these classes will be added in addition to any classes specified in the template. To add multiple classes, separate them with spaces: You can also pass a function that should return a single string containing additional class names. + |
+
sanitize |
+ boolean | +true |
+ Enable or disable the sanitization. If activated 'template' and 'title' options will be sanitized. |
+
allowList |
+ object | +Default value | +Object which contains allowed attributes and tags | +
sanitizeFn |
+ null | function | +null |
+ Here you can supply your own sanitize function. This can be useful if you prefer to use a dedicated library to perform sanitization. | +
popperConfig |
+ null | object | +null |
+ To change Bootstrap's default Popper config, see Popper's configuration | +
Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above. +
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
+ + +Reveals an element’s tooltip. Returns to the caller before the tooltip has actually been shown (i.e. before the shown.bs.tooltip
event occurs). This is considered a “manual” triggering of the tooltip. Tooltips with zero-length titles are never displayed.
tooltip.show()
+
Hides an element’s tooltip. Returns to the caller before the tooltip has actually been hidden (i.e. before the hidden.bs.tooltip
event occurs). This is considered a “manual” triggering of the tooltip.
tooltip.hide()
+
Toggles an element’s tooltip. Returns to the caller before the tooltip has actually been shown or hidden (i.e. before the shown.bs.tooltip
or hidden.bs.tooltip
event occurs). This is considered a “manual” triggering of the tooltip.
tooltip.toggle()
+
Hides and destroys an element’s tooltip (Removes stored data on the DOM element). Tooltips that use delegation (which are created using the selector
option) cannot be individually destroyed on descendant trigger elements.
tooltip.dispose()
+
Gives an element’s tooltip the ability to be shown. Tooltips are enabled by default.
+tooltip.enable()
+
Removes the ability for an element’s tooltip to be shown. The tooltip will only be able to be shown if it is re-enabled.
+tooltip.disable()
+
Toggles the ability for an element’s tooltip to be shown or hidden.
+tooltip.toggleEnabled()
+
Updates the position of an element’s tooltip.
+tooltip.update()
+
Static method which allows you to get the tooltip instance associated with a DOM element
+var exampleTriggerEl = document.getElementById('example')
+var tooltip = bootstrap.Tooltip.getInstance(exampleTriggerEl) // Returns a Bootstrap tooltip instance
+
Event type | +Description | +
---|---|
show.bs.tooltip |
+ This event fires immediately when the show instance method is called. |
+
shown.bs.tooltip |
+ This event is fired when the tooltip has been made visible to the user (will wait for CSS transitions to complete). | +
hide.bs.tooltip |
+ This event is fired immediately when the hide instance method has been called. |
+
hidden.bs.tooltip |
+ This event is fired when the tooltip has finished being hidden from the user (will wait for CSS transitions to complete). | +
inserted.bs.tooltip |
+ This event is fired after the show.bs.tooltip event when the tooltip template has been added to the DOM. |
+
var myTooltipEl = document.getElementById('myTooltip')
+var tooltip = new bootstrap.Tooltip(myTooltipEl)
+
+myTooltipEl.addEventListener('hidden.bs.tooltip', function () {
+ // do something...
+})
+
+tooltip.hide()
+
Documentation and examples for displaying related images and text with the figure component in Bootstrap.
+ + +Anytime you need to display a piece of content—like an image with an optional caption, consider using a <figure>
.
Use the included .figure
, .figure-img
and .figure-caption
classes to provide some baseline styles for the HTML5 <figure>
and <figcaption>
elements. Images in figures have no explicit size, so be sure to add the .img-fluid
class to your <img>
to make it responsive.
<figure class="figure">
+ <img src="..." class="figure-img img-fluid rounded" alt="...">
+ <figcaption class="figure-caption">A caption for the above image.</figcaption>
+</figure>
Aligning the figure’s caption is easy with our text utilities.
+<figure class="figure">
+ <img src="..." class="figure-img img-fluid rounded" alt="...">
+ <figcaption class="figure-caption text-end">A caption for the above image.</figcaption>
+</figure>
Documentation and examples for opting images into responsive behavior (so they never become larger than their parent elements) and add lightweight styles to them—all via classes.
+ + +Images in Bootstrap are made responsive with .img-fluid
. This applies max-width: 100%;
and height: auto;
to the image so that it scales with the parent element.
<img src="..." class="img-fluid" alt="...">
In addition to our border-radius utilities, you can use .img-thumbnail
to give an image a rounded 1px border appearance.
<img src="..." class="img-thumbnail" alt="...">
Align images with the helper float classes or text alignment classes. block
-level images can be centered using the .mx-auto
margin utility class.
<img src="..." class="rounded float-start" alt="...">
+<img src="..." class="rounded float-end" alt="...">
<img src="..." class="rounded mx-auto d-block" alt="...">
<div class="text-center">
+ <img src="..." class="rounded" alt="...">
+</div>
If you are using the <picture>
element to specify multiple <source>
elements for a specific <img>
, make sure to add the .img-*
classes to the <img>
and not to the <picture>
tag.
<picture>
+ <source srcset="..." type="image/svg+xml">
+ <img src="..." class="img-fluid img-thumbnail" alt="...">
+</picture>
+
Reboot, a collection of element-specific CSS changes in a single file, kickstart Bootstrap to provide an elegant, consistent, and simple baseline to build upon.
+ + +[hidden]
attributeReboot builds upon Normalize, providing many HTML elements with somewhat opinionated styles using only element selectors. Additional styling is done only with classes. For example, we reboot some <table>
styles for a simpler baseline and later provide .table
, .table-bordered
, and more.
Here are our guidelines and reasons for choosing what to override in Reboot:
+rem
s instead of em
s for scalable component spacing.margin-top
. Vertical margins can collapse, yielding unexpected results. More importantly though, a single direction of margin
is a simpler mental model.rem
s for margin
s.font
-related properties to a minimum, using inherit
whenever possible.The <html>
and <body>
elements are updated to provide better page-wide defaults. More specifically:
box-sizing
is globally set on every element—including *::before
and *::after
, to border-box
. This ensures that the declared width of element is never exceeded due to padding or border.
+font-size
is declared on the <html>
, but 16px
is assumed (the browser default). font-size: 1rem
is applied on the <body>
for easy responsive type-scaling via media queries while respecting user preferences and ensuring a more accessible approach. This browser default can be overridden by modifying the $font-size-root
variable.<body>
also sets a global font-family
, font-weight
, line-height
, and color
. This is inherited later by some form elements to prevent font inconsistencies.<body>
has a declared background-color
, defaulting to #fff
.Bootstrap utilizes a “native font stack” or “system font stack” for optimum text rendering on every device and OS. These system fonts have been designed specifically with today’s devices in mind, with improved rendering on screens, variable font support, and more. Read more about native font stacks in this Smashing Magazine article.
+$font-family-sans-serif:
+ // Safari for macOS and iOS (San Francisco)
+ -apple-system,
+ // Chrome < 56 for macOS (San Francisco)
+ BlinkMacSystemFont,
+ // Windows
+ "Segoe UI",
+ // Android
+ Roboto,
+ // Basic web fallback
+ "Helvetica Neue", Arial,
+ // Linux
+ "Noto Sans",
+ "Liberation Sans",
+ // Sans serif fallback
+ sans-serif,
+ // Emoji fonts
+ "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji" !default;
+
Note that because the font stack includes emoji fonts, many common symbol/dingbat unicode characters will be rendered as multi-colored pictographs. Their appearance will vary, depending on the style used in the browser/platform’s native emoji font, and they won’t be affected by any CSS color
styles.
This font-family
is applied to the <body>
and automatically inherited globally throughout Bootstrap. To switch the global font-family
, update $font-family-base
and recompile Bootstrap.
All heading elements—e.g., <h1>
—and <p>
are reset to have their margin-top
removed. Headings have margin-bottom: .5rem
added and paragraphs margin-bottom: 1rem
for easy spacing.
Heading | +Example | +
---|---|
+ <h1></h1>
+ |
+ h1. Bootstrap heading | +
+ <h2></h2>
+ |
+ h2. Bootstrap heading | +
+ <h3></h3>
+ |
+ h3. Bootstrap heading | +
+ <h4></h4>
+ |
+ h4. Bootstrap heading | +
+ <h5></h5>
+ |
+ h5. Bootstrap heading | +
+ <h6></h6>
+ |
+ h6. Bootstrap heading | +
All lists—<ul>
, <ol>
, and <dl>
—have their margin-top
removed and a margin-bottom: 1rem
. Nested lists have no margin-bottom
. We’ve also reset the padding-left
on <ul>
and <ol>
elements.
For simpler styling, clear hierarchy, and better spacing, description lists have updated margin
s. <dd>
s reset margin-left
to 0
and add margin-bottom: .5rem
. <dt>
s are bolded.
Wrap inline snippets of code with <code>
. Be sure to escape HTML angle brackets.
<section>
should be wrapped as inline.
+For example, <code><section></code> should be wrapped as inline.
Use <pre>
s for multiple lines of code. Once again, be sure to escape any angle brackets in the code for proper rendering. The <pre>
element is reset to remove its margin-top
and use rem
units for its margin-bottom
.
<p>Sample text here...</p>
+<p>And another line of sample text here...</p>
+
+<pre><code><p>Sample text here...</p>
+<p>And another line of sample text here...</p>
+</code></pre>
For indicating variables use the <var>
tag.
<var>y</var> = <var>m</var><var>x</var> + <var>b</var>
Use the <kbd>
to indicate input that is typically entered via keyboard.
To switch directories, type <kbd>cd</kbd> followed by the name of the directory.<br>
+To edit settings, press <kbd><kbd>ctrl</kbd> + <kbd>,</kbd></kbd>
For indicating sample output from a program use the <samp>
tag.
<samp>This text is meant to be treated as sample output from a computer program.</samp>
Tables are slightly adjusted to style <caption>
s, collapse borders, and ensure consistent text-align
throughout. Additional changes for borders, padding, and more come with the .table
class.
Table heading | +Table heading | +Table heading | +Table heading | +
---|---|---|---|
Table cell | +Table cell | +Table cell | +Table cell | +
Table cell | +Table cell | +Table cell | +Table cell | +
Table cell | +Table cell | +Table cell | +Table cell | +
Various form elements have been rebooted for simpler base styles. Here are some of the most notable changes:
+<fieldset>
s have no borders, padding, or margin so they can be easily used as wrappers for individual inputs or groups of inputs.<legend>
s, like fieldsets, have also been restyled to be displayed as a heading of sorts.<label>
s are set to display: inline-block
to allow margin
to be applied.<input>
s, <select>
s, <textarea>
s, and <button>
s are mostly addressed by Normalize, but Reboot removes their margin
and sets line-height: inherit
, too.<textarea>
s are modified to only be resizable vertically as horizontal resizing often “breaks” page layout.<button>
s and <input>
button elements have cursor: pointer
when :not(:disabled)
.These changes, and more, are demonstrated below.
+ +Keep in mind date inputs are not fully supported by all browsers, namely Safari. +
Reboot includes an enhancement for role="button"
to change the default cursor to pointer
. Add this attribute to elements to help indicate elements are interactive. This role isn’t necessary for <button>
elements, which get their own cursor
change.
<span role="button" tabindex="0">Non-button element button</span>
The <address>
element is updated to reset the browser default font-style
from italic
to normal
. line-height
is also now inherited, and margin-bottom: 1rem
has been added. <address>
s are for presenting contact information for the nearest ancestor (or an entire body of work). Preserve formatting by ending lines with <br>
.
The default margin
on blockquotes is 1em 40px
, so we reset that to 0 0 1rem
for something more consistent with other elements.
++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.
+
Someone famous in Source Title
+The <abbr>
element receives basic styling to make it stand out amongst paragraph text.
The default cursor
on summary is text
, so we reset that to pointer
to convey that the element can be interacted with by clicking on it.
More info about the details.
+Here are even more details about the details.
+[hidden]
attributeHTML5 adds a new global attribute named [hidden]
, which is styled as display: none
by default. Borrowing an idea from PureCSS, we improve upon this default by making [hidden] { display: none !important; }
to help prevent its display
from getting accidentally overridden.
<input type="text" hidden>
+
[hidden]
is not compatible with jQuery’s $(...).hide()
and $(...).show()
methods. Therefore, we don’t currently especially endorse [hidden]
over other techniques for managing the display
of elements.
+
To merely toggle the visibility of an element, meaning its display
is not modified and the element can still affect the flow of the document, use the .invisible
class instead.
Documentation and examples for opt-in styling of tables (given their prevalent use in JavaScript plugins) with Bootstrap.
+ + +Due to the widespread use of <table>
elements across third-party widgets like calendars and date pickers, Bootstrap’s tables are opt-in. Add the base class .table
to any <table>
, then extend with our optional modifier classes or custom styles. All table styles are not inherited in Bootstrap, meaning any nested tables can be styled independent from the parent.
Using the most basic table markup, here’s how .table
-based tables look in Bootstrap.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table">
+ <thead>
+ <tr>
+ <th scope="col">#</th>
+ <th scope="col">First</th>
+ <th scope="col">Last</th>
+ <th scope="col">Handle</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th scope="row">1</th>
+ <td>Mark</td>
+ <td>Otto</td>
+ <td>@mdo</td>
+ </tr>
+ <tr>
+ <th scope="row">2</th>
+ <td>Jacob</td>
+ <td>Thornton</td>
+ <td>@fat</td>
+ </tr>
+ <tr>
+ <th scope="row">3</th>
+ <td colspan="2">Larry the Bird</td>
+ <td>@twitter</td>
+ </tr>
+ </tbody>
+</table>
Use contextual classes to color tables, table rows or individual cells.
+Class | +Heading | +Heading | +
---|---|---|
Default | +Cell | +Cell | +
Primary | +Cell | +Cell | +
Secondary | +Cell | +Cell | +
Success | +Cell | +Cell | +
Danger | +Cell | +Cell | +
Warning | +Cell | +Cell | +
Info | +Cell | +Cell | +
Light | +Cell | +Cell | +
Dark | +Cell | +Cell | +
<!-- On tables -->
+<table class="table-primary">...</table>
+<table class="table-secondary">...</table>
+<table class="table-success">...</table>
+<table class="table-danger">...</table>
+<table class="table-warning">...</table>
+<table class="table-info">...</table>
+<table class="table-light">...</table>
+<table class="table-dark">...</table>
+
+<!-- On rows -->
+<tr class="table-primary">...</tr>
+<tr class="table-secondary">...</tr>
+<tr class="table-success">...</tr>
+<tr class="table-danger">...</tr>
+<tr class="table-warning">...</tr>
+<tr class="table-info">...</tr>
+<tr class="table-light">...</tr>
+<tr class="table-dark">...</tr>
+
+<!-- On cells (`td` or `th`) -->
+<tr>
+ <td class="table-primary">...</td>
+ <td class="table-secondary">...</td>
+ <td class="table-success">...</td>
+ <td class="table-danger">...</td>
+ <td class="table-warning">...</td>
+ <td class="table-info">...</td>
+ <td class="table-light">...</td>
+ <td class="table-dark">...</td>
+</tr>
Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .visually-hidden
class.
+
Use .table-striped
to add zebra-striping to any table row within the <tbody>
.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-striped">
+ ...
+</table>
These classes can also be added to table variants:
+# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-dark table-striped">
+ ...
+</table>
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-success table-striped">
+ ...
+</table>
Add .table-hover
to enable a hover state on table rows within a <tbody>
.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-hover">
+ ...
+</table>
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-dark table-hover">
+ ...
+</table>
These hoverable rows can also be combined with the striped variant:
+# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-striped table-hover">
+ ...
+</table>
Highlight a table row or cell by adding a .table-active
class.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table">
+ <thead>
+ ...
+ </thead>
+ <tbody>
+ <tr class="table-active">
+ ...
+ </tr>
+ <tr>
+ ...
+ </tr>
+ <tr>
+ <th scope="row">3</th>
+ <td colspan="2" class="table-active">Larry the Bird</td>
+ <td>@twitter</td>
+ </tr>
+ </tbody>
+</table>
+
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-dark">
+ <thead>
+ ...
+ </thead>
+ <tbody>
+ <tr class="table-active">
+ ...
+ </tr>
+ <tr>
+ ...
+ </tr>
+ <tr>
+ <th scope="row">3</th>
+ <td colspan="2" class="table-active">Larry the Bird</td>
+ <td>@twitter</td>
+ </tr>
+ </tbody>
+</table>
+
For the accented tables (striped rows, hoverable rows, and active tables), we used some techniques to make these effects work for all our table variants:
+--bs-table-bg
custom property. All table variants then set that custom property to colorize the table cells. This way, we don’t get into trouble if semi-transparent colors are used as table backgrounds.background-image: linear-gradient(var(--bs-table-accent-bg), var(--bs-table-accent-bg));
to layer on top of any specified background-color
. Since --bs-table-accent-bg
is transparent by default, we have an invisible transparent linear gradient by default..table-striped
, .table-hover
or .table-active
classes are added, the --bs-table-accent-bg
is set to a semitransparent color to colorize the background.--bs-table-accent-bg
color with the highest contrast depending on that color. For example, the accent color for .table-primary
is darker while .table-dark
has a lighter accent color.Behind the scenes it looks like this:
+@mixin table-variant($state, $background) {
+ .table-#{$state} {
+ $color: color-contrast(opaque($body-bg, $background));
+ $hover-bg: mix($color, $background, percentage($table-hover-bg-factor));
+ $striped-bg: mix($color, $background, percentage($table-striped-bg-factor));
+ $active-bg: mix($color, $background, percentage($table-active-bg-factor));
+
+ --#{$variable-prefix}table-bg: #{$background};
+ --#{$variable-prefix}table-striped-bg: #{$striped-bg};
+ --#{$variable-prefix}table-striped-color: #{color-contrast($striped-bg)};
+ --#{$variable-prefix}table-active-bg: #{$active-bg};
+ --#{$variable-prefix}table-active-color: #{color-contrast($active-bg)};
+ --#{$variable-prefix}table-hover-bg: #{$hover-bg};
+ --#{$variable-prefix}table-hover-color: #{color-contrast($hover-bg)};
+
+ color: $color;
+ border-color: mix($color, $background, percentage($table-border-factor));
+ }
+}
Add .table-bordered
for borders on all sides of the table and cells.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-bordered">
+ ...
+</table>
Border color utilities can be added to change colors:
+# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-bordered border-primary">
+ ...
+</table>
Add .table-borderless
for a table without borders.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-borderless">
+ ...
+</table>
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-dark table-borderless">
+ ...
+</table>
Add .table-sm
to make any .table
more compact by cutting all cell padding
in half.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-sm">
+ ...
+</table>
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-dark table-sm">
+ ...
+</table>
Table cells of <thead>
are always vertical aligned to the bottom. Table cells in <tbody>
inherit their alignment from <table>
and are aligned to the the top by default. Use the vertical align classes to re-align where needed.
Heading 1 | +Heading 2 | +Heading 3 | +Heading 4 | +
---|---|---|---|
This cell inherits vertical-align: middle; from the table |
+ This cell inherits vertical-align: middle; from the table |
+ This cell inherits vertical-align: middle; from the table |
+ Nulla vitae elit libero, a pharetra augue. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. | +
This cell inherits vertical-align: bottom; from the table row |
+ This cell inherits vertical-align: bottom; from the table row |
+ This cell inherits vertical-align: bottom; from the table row |
+ Nulla vitae elit libero, a pharetra augue. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. | +
This cell inherits vertical-align: middle; from the table |
+ This cell inherits vertical-align: middle; from the table |
+ This cell is aligned to the top. | +Nulla vitae elit libero, a pharetra augue. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. | +
<table class="table table-sm table-dark">
+ <div class="table-responsive">
+ <table class="table align-middle">
+ <thead>
+ <tr>
+ ...
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ ...
+ </tr>
+ <tr class="align-bottom">
+ ...
+ </tr>
+ <tr>
+ <td>...</td>
+ <td>...</td>
+ <td class="align-top">This cell is aligned to the top.</td>
+ <td>...</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+</table>
+
Border styles, active styles, and table variants are not inherited by nested tables.
+# | +First | +Last | +Handle | +||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | +Mark | +Otto | +@mdo | +||||||||||||
+
|
+ |||||||||||||||
3 | +Larry | +the Bird | +
<table class="table table-striped">
+ <thead>
+ ...
+ </thead>
+ <tbody>
+ ...
+ <tr>
+ <td colspan="4">
+ <table class="table mb-0">
+ ...
+ </table>
+ </td>
+ </tr>
+ ...
+ </tbody>
+</table>
+
To prevent any styles from leaking to nested tables, we use the child combinator (>
) selector in our CSS. Since we need to target all the td
s and th
s in the thead
, tbody
, and tfoot
, our selector would look pretty long without it. As such, we use the rather odd looking .table > :not(caption) > * > *
selector to target all td
s and th
s of the .table
, but none of any potential nested tables.
Note that if you add <tr>
s as direct children of a table, those <tr>
will be wrapped in a <tbody>
by default, thus making our selectors work as intended.
Similar to tables and dark tables, use the modifier classes .table-light
or .table-dark
to make <thead>
s appear light or dark gray.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry | +the Bird | +
<table class="table">
+ <thead class="table-light">
+ ...
+ </thead>
+ <tbody>
+ ...
+ </tbody>
+</table>
+
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry | +the Bird | +
<table class="table">
+ <thead class="table-dark">
+ ...
+ </thead>
+ <tbody>
+ ...
+ </tbody>
+</table>
+
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry | +the Bird | +|
Footer | +Footer | +Footer | +Footer | +
<table class="table">
+ <thead>
+ ...
+ </thead>
+ <tbody>
+ ...
+ </tbody>
+ <tfoot>
+ ...
+ </tfoot>
+</table>
+
A <caption>
functions like a heading for a table. It helps users with screen readers to find a table and understand what it’s about and decide if they want to read it.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry the Bird | +
<table class="table table-sm">
+ <caption>List of users</caption>
+ <thead>
+ ...
+ </thead>
+ <tbody>
+ ...
+ </tbody>
+</table>
+
You can also put the <caption>
on the top of the table with .caption-top
.
# | +First | +Last | +Handle | +
---|---|---|---|
1 | +Mark | +Otto | +@mdo | +
2 | +Jacob | +Thornton | +@fat | +
3 | +Larry | +the Bird | +
<table class="table caption-top">
+ <caption>List of users</caption>
+ <thead>
+ <tr>
+ <th scope="col">#</th>
+ <th scope="col">First</th>
+ <th scope="col">Last</th>
+ <th scope="col">Handle</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th scope="row">1</th>
+ <td>Mark</td>
+ <td>Otto</td>
+ <td>@mdo</td>
+ </tr>
+ <tr>
+ <th scope="row">2</th>
+ <td>Jacob</td>
+ <td>Thornton</td>
+ <td>@fat</td>
+ </tr>
+ <tr>
+ <th scope="row">3</th>
+ <td>Larry</td>
+ <td>the Bird</td>
+ <td>@twitter</td>
+ </tr>
+ </tbody>
+</table>
Responsive tables allow tables to be scrolled horizontally with ease. Make any table responsive across all viewports by wrapping a .table
with .table-responsive
. Or, pick a maximum breakpoint with which to have a responsive table up to by using .table-responsive{-sm|-md|-lg|-xl|-xxl}
.
Responsive tables make use of overflow-y: hidden
, which clips off any content that goes beyond the bottom or top edges of the table. In particular, this can clip off dropdown menus and other third-party widgets.
+
Across every breakpoint, use .table-responsive
for horizontally scrolling tables.
# | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
---|---|---|---|---|---|---|---|---|---|
1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
<div class="table-responsive">
+ <table class="table">
+ ...
+ </table>
+</div>
+
Use .table-responsive{-sm|-md|-lg|-xl|-xxl}
as needed to create responsive tables up to a particular breakpoint. From that breakpoint and up, the table will behave normally and not scroll horizontally.
These tables may appear broken until their responsive styles apply at specific viewport widths.
+ + + +# | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
---|---|---|---|---|---|---|---|---|
1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
# | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
---|---|---|---|---|---|---|---|---|
1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
# | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
---|---|---|---|---|---|---|---|---|
1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
# | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
---|---|---|---|---|---|---|---|---|
1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
# | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
---|---|---|---|---|---|---|---|---|
1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
# | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +Heading | +
---|---|---|---|---|---|---|---|---|
1 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
2 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
3 | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +Cell | +
<div class="table-responsive">
+ <table class="table">
+ ...
+ </table>
+</div>
+
+<div class="table-responsive-sm">
+ <table class="table">
+ ...
+ </table>
+</div>
+
+<div class="table-responsive-md">
+ <table class="table">
+ ...
+ </table>
+</div>
+
+<div class="table-responsive-lg">
+ <table class="table">
+ ...
+ </table>
+</div>
+
+<div class="table-responsive-xl">
+ <table class="table">
+ ...
+ </table>
+</div>
+
+<div class="table-responsive-xxl">
+ <table class="table">
+ ...
+ </table>
+</div>
$table-striped-bg-factor
, $table-active-bg-factor
& $table-hover-bg-factor
) are used to determine the contrast in table variants.$table-bg-level
variable.$table-cell-padding-y: .5rem;
+$table-cell-padding-x: .5rem;
+$table-cell-padding-y-sm: .25rem;
+$table-cell-padding-x-sm: .25rem;
+
+$table-cell-vertical-align: top;
+
+$table-color: $body-color;
+$table-bg: transparent;
+
+$table-th-font-weight: null;
+
+$table-striped-color: $table-color;
+$table-striped-bg-factor: .05;
+$table-striped-bg: rgba($black, $table-striped-bg-factor);
+
+$table-active-color: $table-color;
+$table-active-bg-factor: .1;
+$table-active-bg: rgba($black, $table-active-bg-factor);
+
+$table-hover-color: $table-color;
+$table-hover-bg-factor: .075;
+$table-hover-bg: rgba($black, $table-hover-bg-factor);
+
+$table-border-factor: .1;
+$table-border-width: $border-width;
+$table-border-color: $border-color;
+
+$table-striped-order: odd;
+
+$table-group-separator-color: currentColor;
+
+$table-caption-color: $text-muted;
+
+$table-bg-scale: -80%;
+
+$table-variants: (
+ "primary": shift-color($primary, $table-bg-scale),
+ "secondary": shift-color($secondary, $table-bg-scale),
+ "success": shift-color($success, $table-bg-scale),
+ "info": shift-color($info, $table-bg-scale),
+ "warning": shift-color($warning, $table-bg-scale),
+ "danger": shift-color($danger, $table-bg-scale),
+ "light": $light,
+ "dark": $dark,
+);
Documentation and examples for Bootstrap typography, including global settings, headings, body text, lists, and more.
+ + +Bootstrap sets basic global display, typography, and link styles. When more control is needed, check out the textual utility classes.
+font-family
for each OS and device.font-size
(typically 16px) so visitors can customize their browser defaults as needed.$font-family-base
, $font-size-base
, and $line-height-base
attributes as our typographic base applied to the <body>
.$link-color
.$body-bg
to set a background-color
on the <body>
(#fff
by default).These styles can be found within _reboot.scss
, and the global variables are defined in _variables.scss
. Make sure to set $font-size-base
in rem
.
All HTML headings, <h1>
through <h6>
, are available.
Heading | +Example | +
---|---|
+ <h1></h1>
+ |
+ h1. Bootstrap heading | +
+ <h2></h2>
+ |
+ h2. Bootstrap heading | +
+ <h3></h3>
+ |
+ h3. Bootstrap heading | +
+ <h4></h4>
+ |
+ h4. Bootstrap heading | +
+ <h5></h5>
+ |
+ h5. Bootstrap heading | +
+ <h6></h6>
+ |
+ h6. Bootstrap heading | +
<h1>h1. Bootstrap heading</h1>
+<h2>h2. Bootstrap heading</h2>
+<h3>h3. Bootstrap heading</h3>
+<h4>h4. Bootstrap heading</h4>
+<h5>h5. Bootstrap heading</h5>
+<h6>h6. Bootstrap heading</h6>
+
.h1
through .h6
classes are also available, for when you want to match the font styling of a heading but cannot use the associated HTML element.
h1. Bootstrap heading
+h2. Bootstrap heading
+h3. Bootstrap heading
+h4. Bootstrap heading
+h5. Bootstrap heading
+h6. Bootstrap heading
+<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>
Use the included utility classes to recreate the small secondary heading text from Bootstrap 3.
+<h3>
+ Fancy display heading
+ <small class="text-muted">With faded secondary text</small>
+</h3>
Traditional heading elements are designed to work best in the meat of your page content. When you need a heading to stand out, consider using a display heading—a larger, slightly more opinionated heading style.
+<h1 class="display-1">Display 1</h1>
+<h1 class="display-2">Display 2</h1>
+<h1 class="display-3">Display 3</h1>
+<h1 class="display-4">Display 4</h1>
+<h1 class="display-5">Display 5</h1>
+<h1 class="display-6">Display 6</h1>
+
Display headings are configured via the $display-font-sizes
Sass map and two variables, $display-font-weight
and $display-line-height
.
$display-font-sizes: (
+ 1: 5rem,
+ 2: 4.5rem,
+ 3: 4rem,
+ 4: 3.5rem,
+ 5: 3rem,
+ 6: 2.5rem
+);
+
+$display-font-weight: 300;
+$display-line-height: $headings-line-height;
Make a paragraph stand out by adding .lead
.
+ Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Duis mollis, est non commodo luctus. +
+<p class="lead">
+ Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Duis mollis, est non commodo luctus.
+</p>
Styling for common inline HTML5 elements.
+You can use the mark tag to highlight text.
+This line of text is meant to be treated as deleted text.
This line of text is meant to be treated as no longer accurate.
This line of text is meant to be treated as an addition to the document.
+This line of text will render as underlined.
+This line of text is meant to be treated as fine print.
+This line rendered as bold text.
+This line rendered as italicized text.
+<p>You can use the mark tag to <mark>highlight</mark> text.</p>
+<p><del>This line of text is meant to be treated as deleted text.</del></p>
+<p><s>This line of text is meant to be treated as no longer accurate.</s></p>
+<p><ins>This line of text is meant to be treated as an addition to the document.</ins></p>
+<p><u>This line of text will render as underlined.</u></p>
+<p><small>This line of text is meant to be treated as fine print.</small></p>
+<p><strong>This line rendered as bold text.</strong></p>
+<p><em>This line rendered as italicized text.</em></p>
Beware that those tags should be used for semantic purpose:
+<mark>
represents text which is marked or highlighted for reference or notation purposes.<small>
represents side-comments and small print, like copyright and legal text.<s>
represents element that are no longer relevant or no longer accurate.<u>
represents a span of inline text which should be rendered in a way that indicates that it has a non-textual annotation.If you want to style your text, you should use the following classes instead:
+.mark
will apply the same styles as <mark>
..small
will apply the same styles as <small>
..text-decoration-underline
will apply the same styles as <u>
..text-decoration-line-through
will apply the same styles as <s>
.While not shown above, feel free to use <b>
and <i>
in HTML5. <b>
is meant to highlight words or phrases without conveying additional importance, while <i>
is mostly for voice, technical terms, etc.
Change text alignment, transform, style, weight, line-height, decoration and color with our text utilities and color utilities.
+Stylized implementation of HTML’s <abbr>
element for abbreviations and acronyms to show the expanded version on hover. Abbreviations have a default underline and gain a help cursor to provide additional context on hover and to users of assistive technologies.
Add .initialism
to an abbreviation for a slightly smaller font-size.
attr
+HTML
+<p><abbr title="attribute">attr</abbr></p>
+<p><abbr title="HyperText Markup Language" class="initialism">HTML</abbr></p>
For quoting blocks of content from another source within your document. Wrap <blockquote class="blockquote">
around any HTML as the quote.
++Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.
+
<blockquote class="blockquote">
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
+</blockquote>
The HTML spec requires that blockquote attribution be placed outside the <blockquote>
. When providing attribution, wrap your <blockquote>
in a <figure>
and use a <figcaption>
or a block level element (e.g., <p>
) with the .blockquote-footer
class. Be sure to wrap the name of the source work in <cite>
as well.
<figure>
+ <blockquote class="blockquote">
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
+ </blockquote>
+ <figcaption class="blockquote-footer">
+ Someone famous in <cite title="Source Title">Source Title</cite>
+ </figcaption>
+</figure>
Use text utilities as needed to change the alignment of your blockquote.
+<figure class="text-center">
+ <blockquote class="blockquote">
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
+ </blockquote>
+ <figcaption class="blockquote-footer">
+ Someone famous in <cite title="Source Title">Source Title</cite>
+ </figcaption>
+</figure>
<figure class="text-end">
+ <blockquote class="blockquote">
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
+ </blockquote>
+ <figcaption class="blockquote-footer">
+ Someone famous in <cite title="Source Title">Source Title</cite>
+ </figcaption>
+</figure>
Remove the default list-style
and left margin on list items (immediate children only). This only applies to immediate children list items, meaning you will need to add the class for any nested lists as well.
<ul class="list-unstyled">
+ <li>Lorem ipsum dolor sit amet</li>
+ <li>Consectetur adipiscing elit</li>
+ <li>Integer molestie lorem at massa</li>
+ <li>Facilisis in pretium nisl aliquet</li>
+ <li>Nulla volutpat aliquam velit
+ <ul>
+ <li>Phasellus iaculis neque</li>
+ <li>Purus sodales ultricies</li>
+ <li>Vestibulum laoreet porttitor sem</li>
+ <li>Ac tristique libero volutpat at</li>
+ </ul>
+ </li>
+ <li>Faucibus porta lacus fringilla vel</li>
+ <li>Aenean sit amet erat nunc</li>
+ <li>Eget porttitor lorem</li>
+</ul>
Remove a list’s bullets and apply some light margin
with a combination of two classes, .list-inline
and .list-inline-item
.
<ul class="list-inline">
+ <li class="list-inline-item">Lorem ipsum</li>
+ <li class="list-inline-item">Phasellus iaculis</li>
+ <li class="list-inline-item">Nulla volutpat</li>
+</ul>
Align terms and descriptions horizontally by using our grid system’s predefined classes (or semantic mixins). For longer terms, you can optionally add a .text-truncate
class to truncate the text with an ellipsis.
Vestibulum id ligula porta felis euismod semper eget lacinia odio sem nec elit.
+Donec id elit non mi porta gravida at eget metus.
+<dl class="row">
+ <dt class="col-sm-3">Description lists</dt>
+ <dd class="col-sm-9">A description list is perfect for defining terms.</dd>
+
+ <dt class="col-sm-3">Euismod</dt>
+ <dd class="col-sm-9">
+ <p>Vestibulum id ligula porta felis euismod semper eget lacinia odio sem nec elit.</p>
+ <p>Donec id elit non mi porta gravida at eget metus.</p>
+ </dd>
+
+ <dt class="col-sm-3">Malesuada porta</dt>
+ <dd class="col-sm-9">Etiam porta sem malesuada magna mollis euismod.</dd>
+
+ <dt class="col-sm-3 text-truncate">Truncated term is truncated</dt>
+ <dd class="col-sm-9">Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</dd>
+
+ <dt class="col-sm-3">Nesting</dt>
+ <dd class="col-sm-9">
+ <dl class="row">
+ <dt class="col-sm-4">Nested definition list</dt>
+ <dd class="col-sm-8">Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc.</dd>
+ </dl>
+ </dd>
+</dl>
In Bootstrap 5, we’ve enabled responsive font sizes by default, allowing text to scale more naturally across device and viewport sizes. Have a look at the RFS page to find out how this works.
+ +Bootstrap is supported by an extensive color system that themes our styles and components. This enables more comprehensive customization and extension for any project.
+ + +We use a subset of all colors to create a smaller color palette for generating color schemes, also available as Sass variables and a Sass map in Bootstrap’s scss/_variables.scss
file.
All these colors are available as a Sass map, $theme-colors
.
$theme-colors: (
+ "primary": $primary,
+ "secondary": $secondary,
+ "success": $success,
+ "info": $info,
+ "warning": $warning,
+ "danger": $danger,
+ "light": $light,
+ "dark": $dark
+);
Check out our Sass maps and loops docs for how to modify these colors.
+All Bootstrap colors are available as Sass variables and a Sass map in scss/_variables.scss
file. To avoid increased file sizes, we don’t create text or background color classes for each of these variables. Instead, we choose a subset of these colors for a theme palette.
Be sure to monitor contrast ratios as you customize colors. As shown below, we’ve added three contrast ratios to each of the main colors—one for the swatch’s current colors, one for against white, and one for against black.
+Sass cannot programmatically generate variables, so we manually created variables for every tint and shade ourselves. We specify the midpoint value (e.g., $blue-500
) and use custom color functions to tint (lighten) or shade (darken) our colors via Sass’s mix()
color function.
Using mix()
is not the same as lighten()
and darken()
—the former blends the specified color with white or black, while the latter only adjusts the lightness value of each color. The result is a much more complete suite of colors, as shown in this CodePen demo.
Our tint-color()
and shade-color()
functions use mix()
alongside our $theme-color-interval
variable, which specifies a stepped percentage value for each mixed color we produce. See the scss/_functions.scss
and scss/_variables.scss
files for the full source code.
Bootstrap’s source Sass files include three maps to help you quickly and easily loop over a list of colors and their hex values.
+$colors
lists all our available base (500
) colors$theme-colors
lists all semantically named theme colors (shown below)$grays
lists all tints and shades of grayWithin scss/_variables.scss
, you’ll find Bootstrap’s color variables and Sass map. Here’s an example of the $colors
Sass map:
$colors: (
+ "blue": $blue,
+ "indigo": $indigo,
+ "purple": $purple,
+ "pink": $pink,
+ "red": $red,
+ "orange": $orange,
+ "yellow": $yellow,
+ "green": $green,
+ "teal": $teal,
+ "cyan": $cyan,
+ "white": $white,
+ "gray": $gray-600,
+ "gray-dark": $gray-800
+);
Add, remove, or modify values within the map to update how they’re used in many other components. Unfortunately at this time, not every component utilizes this Sass map. Future updates will strive to improve upon this. Until then, plan on making use of the ${color}
variables and this Sass map.
Here’s how you can use these in your Sass:
+.alpha { color: $purple; }
+.beta {
+ color: $yellow-300;
+ background-color: $indigo-900;
+}
+
Color utility classes are also available for setting color
and background-color
using the 500
color values.
Learn how and why we build nearly all our components responsively and with base and modifier classes.
+ + +Bootstrap’s components are largely built with a base-modifier nomenclature. We group as many shared properties as possible into a base class, like .btn
, and then group individual styles for each variant into modifier classes, like .btn-primary
or .btn-success
.
To build our modifier classes, we use Sass’s @each
loops to iterate over a Sass map. This is especially helpful for generating variants of a component by our $theme-colors
and creating responsive variants for each breakpoint. As you customize these Sass maps and recompile, you’ll automatically see your changes reflected in these loops.
Check out our Sass maps and loops docs for how to customize these loops and extend Bootstrap’s base-modifier approach to your own code.
+Many of Bootstrap’s components are built with a base-modifier class approach. This means the bulk of the styling is contained to a base class (e.g., .btn
) while style variations are confined to modifier classes (e.g., .btn-danger
). These modifier classes are built from the $theme-colors
map to make customizing the number and name of our modifier classes.
Here are two examples of how we loop over the $theme-colors
map to generate modifiers to the .alert
and .list-group
components.
// Generate contextual modifier classes for colorizing the alert.
+
+@each $state, $value in $theme-colors {
+ $background: shift-color($value, $alert-bg-scale);
+ $border: shift-color($value, $alert-border-scale);
+ $color: shift-color($value, $alert-color-scale);
+ @if (contrast-ratio($background, $color) < $min-contrast-ratio) {
+ $color: mix($value, color-contrast($background), abs($alert-color-scale));
+ }
+ .alert-#{$state} {
+ @include alert-variant($background, $border, $color);
+ }
+}
// List group contextual variants
+//
+// Add modifier classes to change text and background color on individual items.
+// Organizationally, this must come after the `:hover` states.
+
+@each $state, $value in $theme-colors {
+ $background: shift-color($value, $list-group-item-bg-scale);
+ $color: shift-color($value, $list-group-item-color-scale);
+ @if (contrast-ratio($background, $color) < $min-contrast-ratio) {
+ $color: mix($value, color-contrast($background), abs($alert-color-scale));
+ }
+
+ @include list-group-item-variant($state, $background, $color);
+}
These Sass loops aren’t limited to color maps, either. You can also generate responsive variations of your components. Take for example our responsive alignment of the dropdowns where we mix an @each
loop for the $grid-breakpoints
Sass map with a media query include.
// We deliberately hardcode the `bs-` prefix because we check
+// this custom property in JS to determine Popper's positioning
+
+@each $breakpoint in map-keys($grid-breakpoints) {
+ @include media-breakpoint-up($breakpoint) {
+ $infix: breakpoint-infix($breakpoint, $grid-breakpoints);
+
+ .dropdown-menu#{$infix}-start {
+ --bs-position: start;
+ right: auto #{"/* rtl:ignore */"};
+ left: 0 #{"/* rtl:ignore */"};
+ }
+
+ .dropdown-menu#{$infix}-end {
+ --bs-position: end;
+ right: 0 #{"/* rtl:ignore */"};
+ left: auto #{"/* rtl:ignore */"};
+ }
+ }
+}
Should you modify your $grid-breakpoints
, your changes will apply to all the loops iterating over that map.
$grid-breakpoints: (
+ xs: 0,
+ sm: 576px,
+ md: 768px,
+ lg: 992px,
+ xl: 1200px,
+ xxl: 1400px
+);
For more information and examples on how to modify our Sass maps and variables, please refer to the Sass section of the Grid documentation.
+We encourage you to adopt these guidelines when building with Bootstrap to create your own components. We’ve extended this approach ourselves to the custom components in our documentation and examples. Components like our callouts are built just like our provided components with base and modifier classes.
+<div class="callout">...</div>
+
In your CSS, you’d have something like the following where the bulk of the styling is done via .callout
. Then, the unique styles between each variant is controlled via modifier class.
// Base class
+.callout {}
+
+// Modifier classes
+.callout-info {}
+.callout-warning {}
+.callout-danger {}
+
For the callouts, that unique styling is just a border-left-color
. When you combine that base class with one of those modifier classes, you get your complete component family:
Use Bootstrap’s CSS custom properties for fast and forward-looking design and development.
+ + +Bootstrap includes around two dozen CSS custom properties (variables) in its compiled CSS, with dozens more on the way for improved customization on a per-component basis. These provide easy access to commonly used values like our theme colors, breakpoints, and primary font stacks when working in your browser’s inspector, a code sandbox, or general prototyping.
+All our custom properties are prefixed with bs-
to avoid conflicts with third party CSS.
Here are the variables we include (note that the :root
is required) that can be accessed anywhere Bootstrap’s CSS is loaded. They’re located in our _root.scss
file and included in our compiled dist files.
:root {
+ --bs-blue: #0d6efd;
+ --bs-indigo: #6610f2;
+ --bs-purple: #6f42c1;
+ --bs-pink: #d63384;
+ --bs-red: #dc3545;
+ --bs-orange: #fd7e14;
+ --bs-yellow: #ffc107;
+ --bs-green: #198754;
+ --bs-teal: #20c997;
+ --bs-cyan: #0dcaf0;
+ --bs-white: #fff;
+ --bs-gray: #6c757d;
+ --bs-gray-dark: #343a40;
+ --bs-primary: #0d6efd;
+ --bs-secondary: #6c757d;
+ --bs-success: #198754;
+ --bs-info: #0dcaf0;
+ --bs-warning: #ffc107;
+ --bs-danger: #dc3545;
+ --bs-light: #f8f9fa;
+ --bs-dark: #212529;
+ --bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
+ --bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
+ --bs-gradient: linear-gradient(180deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0));
+}
+
We’re also beginning to make use of custom properties as local variables for various components. This way we can reduce our compiled CSS, ensure styles aren’t inherited in places like nested tables, and allow some basic restyling and extending of Bootstrap components after Sass compilation.
+Have a look at our table documentation for some insight into how we’re using CSS variables.
+We’re also using CSS variables across our grids—primarily for gutters—with more component usage coming in the future.
+CSS variables offer similar flexibility to Sass’s variables, but without the need for compilation before being served to the browser. For example, here we’re resetting our page’s font and link styles with CSS variables.
+body {
+ font: 1rem/1.5 var(--bs-font-sans-serif);
+}
+a {
+ color: var(--bs-blue);
+}
+
Keep your projects lean, responsive, and maintainable so you can deliver the best experience and focus on more important jobs.
+ + +When using Sass in your asset pipeline, make sure you optimize Bootstrap by only @import
ing the components you need. Your largest optimizations will likely come from the Layout & Components
section of our bootstrap.scss
.
// Configuration
+@import "functions";
+@import "variables";
+@import "mixins";
+@import "utilities";
+
+// Layout & components
+@import "root";
+@import "reboot";
+@import "type";
+@import "images";
+@import "containers";
+@import "grid";
+@import "tables";
+@import "forms";
+@import "buttons";
+@import "transitions";
+@import "dropdown";
+@import "button-group";
+@import "nav";
+@import "navbar";
+@import "card";
+@import "accordion";
+@import "breadcrumb";
+@import "pagination";
+@import "badge";
+@import "alert";
+@import "progress";
+@import "list-group";
+@import "close";
+@import "toasts";
+@import "modal";
+@import "tooltip";
+@import "popover";
+@import "carousel";
+@import "spinners";
+
+// Helpers
+@import "helpers";
+
+// Utilities
+@import "utilities/api";
If you’re not using a component, comment it out or delete it entirely. For example, if you’re not using the carousel, remove that import to save some file size in your compiled CSS. Keep in mind there are some dependencies across Sass imports that may make it more difficult to omit a file.
+Bootstrap’s JavaScript includes every component in our primary dist files (bootstrap.js
and bootstrap.min.js
), and even our primary dependency (Popper) with our bundle files (bootstrap.bundle.js
and bootstrap.bundle.min.js
). While you’re customizing via Sass, be sure to remove related JavaScript.
For instance, assuming you’re using your own JavaScript bundler like Webpack or Rollup, you’d only import the JavaScript you plan on using. In the example below, we show how to just include our modal JavaScript:
+// Import just what we need
+
+// import 'bootstrap/js/dist/alert';
+// import 'bootstrap/js/dist/button';
+// import 'bootstrap/js/dist/carousel';
+// import 'bootstrap/js/dist/collapse';
+// import 'bootstrap/js/dist/dropdown';
+import 'bootstrap/js/dist/modal';
+// import 'bootstrap/js/dist/popover';
+// import 'bootstrap/js/dist/scrollspy';
+// import 'bootstrap/js/dist/tab';
+// import 'bootstrap/js/dist/toast';
+// import 'bootstrap/js/dist/tooltip';
+
This way, you’re not including any JavaScript you don’t intend to use for components like buttons, carousels, and tooltips. If you’re importing dropdowns, tooltips or popovers, be sure to list the Popper dependency in your package.json
file.
Files in bootstrap/js/dist
use the default export, so if you want to use one of them you have to do the following:
import Modal from 'bootstrap/js/dist/modal'
+
+const modal = new Modal(document.getElementById('myModal'))
+
Bootstrap depends on Autoprefixer to automatically add browser prefixes to certain CSS properties. Prefixes are dictated by our .browserslistrc
file, found in the root of the Bootstrap repo. Customizing this list of browsers and recompiling the Sass will automatically remove some CSS from your compiled CSS, if there are vendor prefixes unique to that browser or version.
Help wanted with this section, please consider opening a PR. Thanks!
+While we don’t have a prebuilt example for using PurgeCSS with Bootstrap, there are some helpful articles and walkthroughs that the community has written. Here are some options:
+Lastly, this CSS Tricks article on unused CSS shows how to use PurgeCSS and other similar tools.
+Whenever possible, be sure to compress all the code you serve to your visitors. If you’re using Bootstrap dist files, try to stick to the minified versions (indicated by the .min.css
and .min.js
extensions). If you’re building Bootstrap from the source with your own build system, be sure to implement your own minifiers for HTML, CSS, and JS.
Help wanted with this section, please consider opening a PR. Thanks!
+Help wanted with this section, please consider opening a PR. Thanks!
+ +Quickly customize Bootstrap with built-in variables to easily toggle global CSS preferences for controlling style and behavior.
+ + +Customize Bootstrap with our built-in custom variables file and easily toggle global CSS preferences with new $enable-*
Sass variables. Override a variable’s value and recompile with npm run test
as needed.
You can find and customize these variables for key global options in Bootstrap’s scss/_variables.scss
file.
Variable | +Values | +Description | +
---|---|---|
$spacer |
+1rem (default), or any value > 0 |
+Specifies the default spacer value to programmatically generate our spacer utilities. | +
$enable-rounded |
+true (default) or false |
+Enables predefined border-radius styles on various components. |
+
$enable-shadows |
+true or false (default) |
+Enables predefined box-shadow styles on various components. |
+
$enable-gradients |
+true or false (default) |
+Enables predefined gradients via background-image styles on various components. |
+
$enable-transitions |
+true (default) or false |
+Enables predefined transition s on various components. |
+
$enable-reduced-motion |
+true (default) or false |
+Enables the prefers-reduced-motion media query, which suppresses certain animations/transitions based on the users' browser/operating system preferences. |
+
$enable-grid-classes |
+true (default) or false |
+Enables the generation of CSS classes for the grid system (e.g. .row , .col-md-1 , etc.). |
+
$enable-caret |
+true (default) or false |
+Enables pseudo element caret on .dropdown-toggle . |
+
$enable-button-pointers |
+true (default) or false |
+Add “hand” cursor to non-disabled button elements. | +
$enable-rfs |
+true (default) or false |
+Globally enables RFS. | +
$enable-validation-icons |
+true (default) or false |
+Enables background-image icons within textual inputs and some custom forms for validation states. |
+
$enable-negative-margins |
+true or false (default) |
+Enables the generation of negative margin utilities. | +
$enable-deprecation-messages |
+true or false (default) |
+Set to true to show warnings when using any of the deprecated mixins and functions that are planned to be removed in v5 . |
+
$enable-important-utilities |
+true (default) or false |
+Enables the !important suffix in utility classes. |
+
Learn how to theme, customize, and extend Bootstrap with Sass, a boatload of global options, an expansive color system, and more.
+ + +There are multiple ways to customize Bootstrap. Your best path can depend on your project, the complexity of your build tools, the version of Bootstrap you’re using, browser support, and more.
+Our two preferred methods are:
+While we cannot go into details here on how to use every package manager, we can give some guidance on using Bootstrap with your own Sass compiler.
+For those who want to use the distribution files, review the getting started page for how to include those files and an example HTML page. From there, consult the docs for the layout, components, and behaviors you’d like to use.
+As you familiarize yourself with Bootstrap, continue exploring this section for more details on how to utilize our global options, making use of and changing our color system, how we build our components, how to use our growing list of CSS custom properties, and how to optimize your code when building with Bootstrap.
+ +Utilize our source Sass files to take advantage of variables, maps, mixins, and functions to help you build faster and customize your project.
+ + +Utilize our source Sass files to take advantage of variables, maps, mixins, and more. In our build we’ve increased the Sass rounding precision to 6 (by default it’s 5) to prevent issues with browser rounding.
+Whenever possible, avoid modifying Bootstrap’s core files. For Sass, that means creating your own stylesheet that imports Bootstrap so you can modify and extend it. Assuming you’re using a package manager like npm, you’ll have a file structure that looks like this:
+your-project/
+├── scss
+│ └── custom.scss
+└── node_modules/
+ └── bootstrap
+ ├── js
+ └── scss
+
If you’ve downloaded our source files and aren’t using a package manager, you’ll want to manually setup something similar to that structure, keeping Bootstrap’s source files separate from your own.
+your-project/
+├── scss
+│ └── custom.scss
+└── bootstrap/
+ ├── js
+ └── scss
+
In your custom.scss
, you’ll import Bootstrap’s source Sass files. You have two options: include all of Bootstrap, or pick the parts you need. We encourage the latter, though be aware there are some requirements and dependencies across our components. You also will need to include some JavaScript for our plugins.
// Custom.scss
+// Option A: Include all of Bootstrap
+
+@import "../node_modules/bootstrap/scss/bootstrap";
+
// Custom.scss
+// Option B: Include parts of Bootstrap
+
+// Required
+@import "../node_modules/bootstrap/scss/functions";
+@import "../node_modules/bootstrap/scss/variables";
+@import "../node_modules/bootstrap/scss/mixins";
+
+// Optional
+@import "../node_modules/bootstrap/scss/root";
+@import "../node_modules/bootstrap/scss/reboot";
+@import "../node_modules/bootstrap/scss/type";
+@import "../node_modules/bootstrap/scss/images";
+@import "../node_modules/bootstrap/scss/containers";
+@import "../node_modules/bootstrap/scss/grid";
+
With that setup in place, you can begin to modify any of the Sass variables and maps in your custom.scss
. You can also start to add parts of Bootstrap under the // Optional
section as needed. We suggest using the full import stack from our bootstrap.scss
file as your starting point.
Every Sass variable in Bootstrap includes the !default
flag allowing you to override the variable’s default value in your own Sass without modifying Bootstrap’s source code. Copy and paste variables as needed, modify their values, and remove the !default
flag. If a variable has already been assigned, then it won’t be re-assigned by the default values in Bootstrap.
You will find the complete list of Bootstrap’s variables in scss/_variables.scss
. Some variables are set to null
, these variables don’t output the property unless they are overridden in your configuration.
Variable overrides within the same Sass file can come before or after the default variables. However, when overriding across Sass files, your overrides must come before you import Bootstrap’s Sass files.
+Here’s an example that changes the background-color
and color
for the <body>
when importing and compiling Bootstrap via npm:
// Your variable overrides
+$body-bg: #000;
+$body-color: #111;
+
+// Bootstrap and its default variables
+@import "../node_modules/bootstrap/scss/bootstrap";
+
Repeat as necessary for any variable in Bootstrap, including the global options below.
+Bootstrap includes a handful of Sass maps, key value pairs that make it easier to generate families of related CSS. We use Sass maps for our colors, grid breakpoints, and more. Just like Sass variables, all Sass maps include the !default
flag and can be overridden and extended.
Some of our Sass maps are merged into empty ones by default. This is done to allow easy expansion of a given Sass map, but comes at the cost of making removing items from a map slightly more difficult.
+All variables in the $theme-colors
map are defined as standalone variables. To modify an existing color in our $theme-colors
map, add the following to your custom Sass file:
$primary: #0074d9;
+$danger: #ff4136;
+
Later on, theses variables are set in Bootstrap’s $theme-colors
map:
$theme-colors: (
+ "primary": $primary,
+ "danger": $danger
+);
+
Add new colors to $theme-colors
, or any other map, by creating a new Sass map with your custom values and merging it with the original map. In this case, we’ll create a new $custom-colors
map and merge it with $theme-colors
.
// Create your own map
+$custom-colors: (
+ "custom-color": #900
+);
+
+// Merge the maps
+$theme-colors: map-merge($theme-colors, $custom-colors);
+
To remove colors from $theme-colors
, or any other map, use map-remove
. Be aware you must insert it between our requirements and options:
// Required
+@import "../node_modules/bootstrap/scss/functions";
+@import "../node_modules/bootstrap/scss/variables";
+@import "../node_modules/bootstrap/scss/mixins";
+
+$theme-colors: map-remove($theme-colors, "info", "light", "dark");
+
+// Optional
+@import "../node_modules/bootstrap/scss/root";
+@import "../node_modules/bootstrap/scss/reboot";
+@import "../node_modules/bootstrap/scss/type";
+...
+
Bootstrap assumes the presence of some specific keys within Sass maps as we used and extend these ourselves. As you customize the included maps, you may encounter errors where a specific Sass map’s key is being used.
+For example, we use the primary
, success
, and danger
keys from $theme-colors
for links, buttons, and form states. Replacing the values of these keys should present no issues, but removing them may cause Sass compilation issues. In these instances, you’ll need to modify the Sass code that makes use of those values.
Next to the Sass maps we have, theme colors can also be used as standalone variables, like $primary
.
.custom-element {
+ color: $gray-100;
+ background-color: $dark;
+}
+
You can lighten or darken colors with Bootstrap’s tint-color()
and shade-color()
functions. These functions will mix colors with black or white, unlike Sass' native lighten()
and darken()
functions which will change the lightness by a fixed amount, which often doesn’t lead to the desired effect.
// Tint a color: mix a color with white
+@function tint-color($color, $weight) {
+ @return mix(white, $color, $weight);
+}
+
+// Shade a color: mix a color with black
+@function shade-color($color, $weight) {
+ @return mix(black, $color, $weight);
+}
+
+// Shade the color if the weight is positive, else tint it
+@function shift-color($color, $weight) {
+ @return if($weight > 0, shade-color($color, $weight), tint-color($color, -$weight));
+}
In practice, you’d call the function and pass in the color and weight parameters.
+.custom-element {
+ color: tint-color($primary, 10%);
+}
+
+.custom-element-2 {
+ color: shade-color($danger, 30%);
+}
+
In order to meet WCAG 2.0 accessibility standards for color contrast, authors must provide a contrast ratio of at least 4.5:1, with very few exceptions.
+An additional function we include in Bootstrap is the color contrast function, color-contrast
. It utilizes the WCAG 2.0 algorithm for calculating contrast thresholds based on relative luminance in a sRGB
colorspace to automatically return a light (#fff
), dark (#212529
) or black (#000
) contrast color based on the specified base color. This function is especially useful for mixins or loops where you’re generating multiple classes.
For example, to generate color swatches from our $theme-colors
map:
@each $color, $value in $theme-colors {
+ .swatch-#{$color} {
+ color: color-contrast($value);
+ }
+}
+
It can also be used for one-off contrast needs:
+.custom-element {
+ color: color-contrast(#000); // returns `color: #fff`
+}
+
You can also specify a base color with our color map functions:
+.custom-element {
+ color: color-contrast($dark); // returns `color: #fff`
+}
+
We use the escape-svg
function to escape the <
, >
and #
characters for SVG background images. When using the escape-svg
function, data URIs must be quoted.
We use the add
and subtract
functions to wrap the CSS calc
function. The primary purpose of these functions is to avoid errors when a “unitless” 0
value is passed into a calc
expression. Expressions like calc(10px - 0)
will return an error in all browsers, despite being mathematically correct.
Example where the calc is valid:
+$border-radius: .25rem;
+$border-width: 1px;
+
+.element {
+ // Output calc(.25rem - 1px) is valid
+ border-radius: calc($border-radius - $border-width);
+}
+
+.element {
+ // Output the same calc(.25rem - 1px) as above
+ border-radius: subtract($border-radius, $border-width);
+}
+
Example where the calc is invalid:
+$border-radius: .25rem;
+$border-width: 0;
+
+.element {
+ // Output calc(.25rem - 0) is invalid
+ border-radius: calc($border-radius - $border-width);
+}
+
+.element {
+ // Output .25rem
+ border-radius: subtract($border-radius, $border-width);
+}
+
`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\n\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n\n// Abbreviations\n//\n// 1. Duplicate behavior to the data-bs-* attribute for our tooltip plugin\n// 2. Add the correct text decoration in Chrome, Edge, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Prevent the text-decoration to be skipped.\n\nabbr[title],\nabbr[data-bs-original-title] { // 1\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n text-decoration-skip-ink: none; // 4\n}\n\n\n// Address\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\n\n// Lists\n\nol,\nul {\n padding-left: 2rem;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\n// 1. Undo browser default\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // 1\n}\n\n\n// Blockquote\n\nblockquote {\n margin: 0 0 1rem;\n}\n\n\n// Strong\n//\n// Add the correct font weight in Chrome, Edge, and Safari\n\nb,\nstrong {\n font-weight: $font-weight-bolder;\n}\n\n\n// Small\n//\n// Add the correct font size in all browsers\n\nsmall {\n @include font-size($small-font-size);\n}\n\n\n// Mark\n\nmark {\n padding: $mark-padding;\n background-color: $mark-bg;\n}\n\n\n// Sub and Sup\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n\nsub,\nsup {\n position: relative;\n @include font-size($sub-sup-font-size);\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n// Links\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n\n &:hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([class]) {\n &,\n &:hover {\n color: inherit;\n text-decoration: none;\n }\n}\n\n\n// Code\n\npre,\ncode,\nkbd,\nsamp {\n font-family: $font-family-code;\n @include font-size(1em); // Correct the odd `em` font sizing in all browsers.\n direction: ltr #{\"/* rtl:ignore */\"};\n unicode-bidi: bidi-override;\n}\n\n// 1. Remove browser default top margin\n// 2. Reset browser default of `1em` to use `rem`s\n// 3. Don't allow content to break outside\n\npre {\n display: block;\n margin-top: 0; // 1\n margin-bottom: 1rem; // 2\n overflow: auto; // 3\n @include font-size($code-font-size);\n color: $pre-color;\n\n // Account for some code outputs that place code tags in pre tags\n code {\n @include font-size(inherit);\n color: inherit;\n word-break: normal;\n }\n}\n\ncode {\n @include font-size($code-font-size);\n color: $code-color;\n word-wrap: break-word;\n\n // Streamline the style when inside anchors to avoid broken underline and more\n a > & {\n color: inherit;\n }\n}\n\nkbd {\n padding: $kbd-padding-y $kbd-padding-x;\n @include font-size($kbd-font-size);\n color: $kbd-color;\n background-color: $kbd-bg;\n @include border-radius($border-radius-sm);\n\n kbd {\n padding: 0;\n @include font-size(1em);\n font-weight: $nested-kbd-font-weight;\n }\n}\n\n\n// Figures\n//\n// Apply a consistent margin strategy (matches our type styles).\n\nfigure {\n margin: 0 0 1rem;\n}\n\n\n// Images and content\n\nimg,\nsvg {\n vertical-align: middle;\n}\n\n\n// Tables\n//\n// Prevent double borders\n\ntable {\n caption-side: bottom;\n border-collapse: collapse;\n}\n\ncaption {\n padding-top: $table-cell-padding-y;\n padding-bottom: $table-cell-padding-y;\n color: $table-caption-color;\n text-align: left;\n}\n\n// 1. Removes font-weight bold by inheriting\n// 2. Matches default `