Bootstrap 2
Bootstrap 2
With our online editor, you can edit the code, and click on a button to view the
result.
Bootstrap 4 Example
<div class="jumbotron text-center">
<h1>My First Bootstrap Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>
<div class="container">
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
<p>Lorem ipsum dolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
<p>Lorem ipsum dolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
<p>Lorem ipsum dolor..</p>
</div>
</div>
</div>
Try it Yourself »
Click on the "Try it Yourself" button to see how it works.
ADVERTISEMENT
Bootstrap 4 supports the latest, stable releases of all major browsers and
platforms. However, Internet Explorer 9 and down is not supported.
Bootstrap References
A complete list of all Bootstrap 4 CSS classes with description and examples:
If you want to do more with Bootstrap components, see our complete Bootstrap
4 JavaScript/jQuery reference - all with "Try it Yourself" examples:
Bootstrap 4 Exercises
Test Yourself With Exercises
Exercise:
Use a Bootstrap class to center the following text:
Submit Answer »
What is Bootstrap?
Bootstrap is a free front-end framework for faster and easier web
development
Bootstrap includes HTML and CSS based design templates for typography,
forms, buttons, tables, navigation, modals, image carousels and many
other, as well as optional JavaScript plugins
Bootstrap also gives you the ability to easily create responsive designs
Responsive web design is about creating web sites which automatically adjust
themselves to look good on all devices, from small phones to large desktops.
Bootstrap 4 Example
<div class="jumbotron text-center">
<h1>My First Bootstrap Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>
<div class="container">
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
<p>Lorem ipsum dolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
<p>Lorem ipsum dolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
<p>Lorem ipsum dolor..</p>
</div>
</div>
</div>
Try it Yourself »
Bootstrap 4 supports the latest, stable releases of all major browsers and
platforms. However, Internet Explorer 9 and down is not supported.
If you require IE8-9 support, use Bootstrap 3. It is the most stable version
of Bootstrap, and it is still supported by the team for critical bugfixes and
documentation changes. However, no new features will be added to it.
You can:
Bootstrap 4 CDN
If you don't want to download and host Bootstrap 4 yourself, you can include it
from a CDN (Content Delivery Network).
MaxCDN provides CDN support for Bootstrap's CSS and JavaScript. You must
also include jQuery:
MaxCDN:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.c
ss">
Downloading Bootstrap 4
If you want to download and host Bootstrap 4 yourself, go
to https://getbootstrap.com/, and follow the instructions there.
Bootstrap 4 uses HTML elements and CSS properties that require the HTML5
doctype.
Always include the HTML5 doctype at the beginning of the page, along with the
lang attribute and the correct character set:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
</html>
2. Bootstrap 4 is mobile-first
The initial-scale=1 part sets the initial zoom level when the page is first loaded
by the browser.
3. Containers
.container
.container-fluid
Container Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.c
ss">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></
script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.m
in.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
></script>
</head>
<body>
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body>
</html>
Try it Yourself »
The following example shows the code for a basic Bootstrap 4 page (with a full
width container):
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body>
</html>
Bootstrap 4 Containers
❮ PreviousNext ❯
Containers
You learned from the previous chapter that Bootstrap requires a containing
element to wrap site contents.
Containers are used to pad the content inside of them, and there are two
container classes available:
.container
.container-fluid
Fixed Container
Use the .container class to create a responsive, fixed-width container.
Note that its width (max-width) will change on different screen sizes:
Open the example below and resize the browser window to see that the
container width will change at different breakpoints:
Example
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
Try it Yourself »
Fluid Container
Use the .container-fluid class to create a full width container, that will always
span the entire width of the screen (width is always 100%):
Example
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
Try it Yourself »
Container Padding
By default, containers have 15px left and right padding, with no top or bottom
padding. Therefore, we often use spacing utilities, such as extra padding and
margins to make them look even better. For example, .pt-3 means "add a top
padding of 16px":
Example
<div class="container pt-3"></div>
Try it Yourself »
You will learn much more about spacing utilities, in our BS4 Utilities Chapter.
Example
Try it Yourself »
You will learn much more about colors and border utilities, in our BS4 Colors
Chapter and BS4 Utilities Chapter.
Responsive Containers
You can also use the .container-sm|md|lg|xl classes to create responsive
containers.
Example
<div class="container-sm">.container-sm</div>
<div class="container-md">.container-md</div>
<div class="container-lg">.container-lg</div>
<div class="container-xl">.container-xl</div>
Bootstrap 4 Grids
❮ PreviousNext ❯
If you do not want to use all 12 columns individually, you can group the columns
together to create wider columns:
span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1
span 4 span 8
span 6 span 6
span 12
The grid system is responsive, and the columns will re-arrange automatically
depending on the screen size.
Make sure that the sum adds up to 12 or fewer (it is not required that you use
all 12 available columns).
Grid Classes
The Bootstrap 4 grid system has five classes:
The classes above can be combined to create more dynamic and flexible
layouts.
Tip: Each class scales up, so if you wish to set the same widths for sm and md,
you only need to specify sm.
<!-- Control the column width, and how they should appear on different
devices -->
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
First example: create a row (<div class="row">). Then, add the desired number of
columns (tags with appropriate .col-*-* classes). The first star (*) represents
the responsiveness: sm, md, lg or xl, while the second star represents a
number, which should add up to 12 for each row.
.col
.col
The following example shows how to create three equal-width columns, on all
devices and screen widths:
Example
<div class="row">
<div class="col">.col</div>
<div class="col">.col</div>
<div class="col">.col</div>
</div>
Try it Yourself »
Responsive Columns
.col-sm-3
.col-sm-3
.col-sm-3
.col-sm-3
The following example shows how to create four equal-width columns starting at
tablets and scaling to extra large desktops. On mobile phones or screens
that are less than 576px wide, the columns will automatically stack on
top of each other:
Example
<div class="row">
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
<div class="col-sm-3">.col-sm-3</div>
</div>
Try it Yourself »
The following example shows how to get two various-width columns starting at
tablets and scaling to large extra desktops:
Example
<div class="row">
<div class="col-sm-4">.col-sm-4</div>
<div class="col-sm-8">.col-sm-8</div>
</div>
Bootstrap 4 Text/Typography
❮ PreviousNext ❯
<h1> - <h6>
Bootstrap 4 styles HTML headings (<h1> to <h6>) with a bolder font-weight and
an increased font-size:
Example
h1 Bootstrap heading (2.5rem = 40px)
Display Headings
Display headings are used to stand out more than normal headings (larger font-
size and lighter font-weight), and there are four classes to choose
from: .display-1, .display-2, .display-3, .display-4
Example
Display 1
Display 2
Display 3
Display 4
Try it Yourself »
<small>
In Bootstrap 4 the HTML <small> element is used to create a lighter, secondary
text in any heading:
Example
h1 heading secondary text
h2 heading secondary text
h3 heading secondary text
h4 heading secondary text
h5 heading secondary text
h6 heading secondary text
Try it Yourself »
ADVERTISEMENT
<mark>
Bootstrap 4 will style the HTML <mark> element with a yellow background color
and some padding:
Example
Use the mark element to highlight text.
Try it Yourself »
<abbr>
Bootstrap 4 will style the HTML <abbr> element with a dotted border bottom:
Example
The WHO was founded in 1948.
Try it Yourself »
<blockquote>
Add the .blockquote class to a <blockquote> when quoting blocks of content from
another source:
Example
For 50 years, WWF has been protecting the future of nature. The world's leading
conservation organization, WWF works in 100 countries and is supported by 1.2 million
members in the United States and close to 5 million globally.
Try it Yourself »
<dl>
Bootstrap 4 will style the HTML <dl> element in the following way:
Example
Coffee
Milk
Try it Yourself »
<code>
Bootstrap 4 will style the HTML <code> element in the following way:
Example
The following HTML elements: span, section, and div defines a section in a document.
Try it Yourself »
<kbd>
Bootstrap 4 will style the HTML <kbd> element in the following way:
Example
Use ctrl + p to open the Print dialog box.
Try it Yourself »
<pre>
Bootstrap 4 will style the HTML <pre> element in the following way:
Example
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both spaces and
line breaks.
Try it Yourself »
More Typography Classes
The Bootstrap 4 classes below can be added to style HTML elements further:
.text-reset Resets the color of a text or a link (inherits the color Try it
from its parent)
.list- Removes the default list-style and left margin on list Try it
unstyled items (works on both <ul> and <ol>). This class only
applies to immediate children list items (to remove the
default list-style from any nested lists, apply this class to
any nested lists as well)
.list-inline Places all list items on a single line (used together Try it
with .list-inline-item on each <li> elements)
Bootstrap 4 Colors
❮ PreviousNext ❯
Text Colors
Bootstrap 4 has some contextual classes that can be used to provide "meaning
through colors".
Example
This text is muted.
This text is important.
Secondary text.
Body text.
Contextual text classes can also be used on links, which will add a darker hover
color:
Example
Muted link. Primary link. Success link. Info link. Warning link. Danger link. Secondary
link. Dark grey link. Body/black link. Light grey link.
Try it Yourself »
You can also add 50% opacity for black or white text with the .text-black-
50 or .text-white-50 classes:
Example
Black text with 50% opacity on white background
Background Colors
The classes for background colors are: .bg-primary, .bg-success, .bg-info, .bg-
warning, .bg-danger, .bg-secondary, .bg-dark and .bg-light.
Note that background colors do not set the text color, so in some cases you'll
want to use them together with a .text-* class.
Example
This text is important.
Bootstrap 4 Tables
❮ PreviousNext ❯
Example
Firstname Lastname Email
Try it Yourself »
Striped Rows
The .table-striped class adds zebra-stripes to a table:
Example
Firstname Lastname Email
Try it Yourself »
Bordered Table
The .table-bordered class adds borders on all sides of the table and cells:
Example
Firstname Lastname Email
Try it Yourself »
Hover Rows
The .table-hover class adds a hover effect (grey background color) on table
rows:
Example
Firstname Lastname Email
Try it Yourself »
Black/Dark Table
The .table-dark class adds a black background to the table:
Example
Firstname Lastname Email
Try it Yourself »
Example
Firstname Lastname Email
Try it Yourself »
Example
Firstname Lastname Email
Try it Yourself »
Borderless Table
The .table-borderless class removes borders from the table:
Example
Firstname Lastname Email
Try it Yourself »
Contextual Classes
Contextual classes can be used to color the whole table (<table>), the table
rows (<tr>) or table cells (<td>).
Example
Firstname Lastname Email
Dark Bo [email protected]
Try it Yourself »
Class Description
.table-active Grey: Applies the hover color to the table row or table cell
Class Description
Example
Firstname Lastname Email
Try it Yourself »
Small table
The .table-sm class makes the table smaller by cutting cell padding in half:
Example
Firstname Lastname Email
Try it Yourself »
Responsive Tables
The .table-responsive class adds a scrollbar to the table when needed (when it is
too big horizontally):
Example
<div class="table-responsive">
<table class="table">
...
</table>
</div>
Try it Yourself »
You can also decide when the table should get a scrollbar, depending on screen width:
Class Screen width
Example
<div class="table-responsive-sm">
<table class="table">
...
</table>
</div>
Bootstrap 4 Images
❮ PreviousNext ❯
Thumbnail:
Rounded Corners
The .rounded class adds rounded corners to an image:
Example
<img src="cinqueterre.jpg" class="rounded" alt="Cinque Terre">
Try it Yourself »
Circle
The .rounded-circle class shapes the image to a circle:
Example
<img src="cinqueterre.jpg" class="rounded-circle" alt="Cinque Terre">
Try it Yourself »
Thumbnail
The .img-thumbnail class shapes the image to a thumbnail (bordered):
Example
<img src="cinqueterre.jpg" class="img-thumbnail" alt="Cinque Terre">
Try it Yourself »
Aligning Images
Float an image to the right with the .float-right class or to the left with .float-
left:
Example
<img src="paris.jpg" class="float-left">
<img src="paris.jpg" class="float-right">
Try it Yourself »
Centered Image
Center an image by adding the utility classes .mx-auto (margin:auto) and .d-
block (display:block) to the image:
Example
<img src="paris.jpg" class="mx-auto d-block">
Try it Yourself »
Responsive Images
Images come in all sizes. So do screens. Responsive images automatically
adjust to fit the size of the screen.
Example
<img class="img-fluid" src="img_chania.jpg" alt="Chania">
Bootstrap 4 Jumbotron
❮ PreviousNext ❯
Bootstrap 4 Jumbotron
A jumbotron indicates a big grey box for calling extra attention to some special
content or information.
Tip: Inside a jumbotron you can put nearly any valid HTML, including other
Bootstrap elements/classes.
Bootstrap Tutorial
Bootstrap is the most popular HTML, CSS, and JS framework for developing
responsive, mobile-first projects on the web.
Example
<div class="jumbotron">
<h1>Bootstrap Tutorial</h1>
<p>Bootstrap is the most popular HTML, CSS...</p>
</div>
Try it Yourself »
Full-width Jumbotron
If you want a full-width jumbotron without rounded borders, add the .jumbotron-
fluid class and a .container or .container-fluid inside of it:
Example
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1>Bootstrap Tutorial</h1>
<p>Bootstrap is the most popular HTML, CSS...</p>
</div>
</div>
Bootstrap 4 Alerts
❮ PreviousNext ❯
Bootstrap 4 Alerts
Bootstrap 4 provides an easy way to create predefined alert messages:
Try it Yourself »
ADVERTISEMENT
Alert Links
Add the alert-link class to any links inside the alert box to create "matching
colored links":
Example
<div class="alert alert-success">
<strong>Success!</strong> You should <a href="#" class="alert-
link">read this message</a>.
</div>
Try it Yourself »
Closing Alerts
×Click on the "x" symbol to the right to close me.
Example
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-
dismiss="alert">×</button>
<strong>Success!</strong> Indicates a successful or positive action.
</div>
Try it Yourself »
Tip: × (×) is an HTML entity that is the preferred icon for close buttons,
rather than the letter "x".
Animated Alerts
×Click on the "x" symbol to the right to close me. I will "fade" out.
Example
<div class="alert alert-danger alert-dismissible fade show">
Try it Yourself »
Bootstrap 4 Buttons
❮ PreviousNext ❯
Button Styles
Bootstrap 4 provides different styles of buttons:
Basic Primary Secondary Success Info Warning Danger Dark Light Link
Example
<button type="button" class="btn">Basic</button>
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-dark">Dark</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-link">Link</button>
Try it Yourself »
Example
<a href="#" class="btn btn-info" role="button">Link Button</a>
<button type="button" class="btn btn-info">Button</button>
<input type="button" class="btn btn-info" value="Input Button">
<input type="submit" class="btn btn-info" value="Submit Button">
Try it Yourself »
Why do we put a # in the href attribute of the link?
Since we do not have any page to link it to, and we do not want to get a "404"
message, we put # as the link. In real life it should of course been a real URL to
the "Search" page.
Button Outline
Bootstrap 4 provides eight outline/bordered buttons:
Primary Secondary Success Info Warning Danger Dark Light
Example
<button type="button" class="btn btn-outline-primary">Primary</button>
<button type="button" class="btn btn-outline-
secondary">Secondary</button>
<button type="button" class="btn btn-outline-success">Success</button>
<button type="button" class="btn btn-outline-info">Info</button>
<button type="button" class="btn btn-outline-warning">Warning</button>
<button type="button" class="btn btn-outline-danger">Danger</button>
<button type="button" class="btn btn-outline-dark">Dark</button>
<button type="button" class="btn btn-outline-light text-
dark">Light</button>
Try it Yourself »
Button Sizes
Use the .btn-lg class for large buttons or .btn-sm class for small buttons:
Large Default Small
Example
<button type="button" class="btn btn-primary btn-lg">Large</button>
<button type="button" class="btn btn-primary">Default</button>
<button type="button" class="btn btn-primary btn-sm">Small</button>
Try it Yourself »
Full-Width Button
Example
<button type="button" class="btn btn-primary btn-block">Full-Width
Button</button>
Try it Yourself »
Active/Disabled Buttons
A button can be set to an active (appear pressed) or a disabled (unclickable)
state:
Example
<button type="button" class="btn btn-primary active">Active
Primary</button>
<button type="button" class="btn btn-primary" disabled>Disabled
Primary</button>
<a href="#" class="btn btn-primary disabled">Disabled Link</a>
Try it Yourself »
Spinner Buttons
You can also add "spinners" to a button, which you will learn more about in
our BS4 Spinners Tutorial:
Loading.. Loading.. Loading..
Example
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
</button>
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
<button class="btn btn-primary" disabled>
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
<button class="btn btn-primary" disabled>
<span class="spinner-grow spinner-grow-sm"></span>
Loading..
</button>
Button Groups
Bootstrap 4 allows you to group a series of buttons together (on a single line) in
a button group:
AppleSamsungSony
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
Try it Yourself »
Large Buttons:
AppleSamsungSony
Default Buttons:
AppleSamsungSony
Small Buttons:
AppleSamsungSony
Example
<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
Try it Yourself »
AppleSamsungSony
Example
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
Try it Yourself »
Sony
Nest button groups to create dropdown menus (you will learn more about
dropdowns in a later chapter):
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-
toggle="dropdown">
Sony
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Tablet</a>
<a class="dropdown-item" href="#">Smartphone</a>
</div>
</div>
</div>
Try it Yourself »
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Sony</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-
toggle-split" data-toggle="dropdown">
<span class="caret"></span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Tablet</a>
<a class="dropdown-item" href="#">Smartphone</a>
</div>
</div>
Try it Yourself »
Sony
Example
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-
toggle="dropdown">
Sony
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Tablet</a>
<a class="dropdown-item" href="#">Smartphone</a>
</div>
</div>
</div>
Try it Yourself »
AppleSamsungSony
BMWMercedesVolvo
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<button type="button" class="btn btn-primary">Sony</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary">BMW</button>
<button type="button" class="btn btn-primary">Mercedes</button>
<button type="button" class="btn btn-primary">Volvo</button>
</div>
Bootstrap 4 Badges
❮ PreviousNext ❯
Example heading New
Example heading New
Example heading New
Example heading New
Example heading New
Example heading New
Example
<h1>Example heading <span class="badge badge-secondary">New</span></h1>
<h2>Example heading <span class="badge badge-secondary">New</span></h2>
<h3>Example heading <span class="badge badge-secondary">New</span></h3>
<h4>Example heading <span class="badge badge-secondary">New</span></h4>
<h5>Example heading <span class="badge badge-secondary">New</span></h5>
<h6>Example heading <span class="badge badge-secondary">New</span></h6>
Try it Yourself »
Contextual Badges
Primary Secondary Success Danger Warning Info Light Dark
Use any of the contextual classes (.badge-*) to change the color of a badge:
Example
<span class="badge badge-primary">Primary</span>
<span class="badge badge-secondary">Secondary</span>
<span class="badge badge-success">Success</span>
<span class="badge badge-danger">Danger</span>
<span class="badge badge-warning">Warning</span>
<span class="badge badge-info">Info</span>
<span class="badge badge-light">Light</span>
<span class="badge badge-dark">Dark</span>
Try it Yourself »
Pill Badges
Primary Secondary Success Danger Warning Info Light Dark
Example
<span class="badge badge-pill badge-primary">Primary</span>
<span class="badge badge-pill badge-secondary">Secondary</span>
<span class="badge badge-pill badge-success">Success</span>
<span class="badge badge-pill badge-danger">Danger</span>
<span class="badge badge-pill badge-warning">Warning</span>
<span class="badge badge-pill badge-info">Info</span>
<span class="badge badge-pill badge-light">Light</span>
<span class="badge badge-pill badge-dark">Dark</span>
Try it Yourself »
Messages 4
Example
<button type="button" class="btn btn-primary">
Messages <span class="badge badge-light">4</span>
</button>
25% Complete
50% Complete
100% Complete
Example
<div class="progress">
<div class="progress-bar" style="width:70%"></div>
</div>
Try it Yourself »
Example
<div class="progress" style="height:20px">
<div class="progress-bar" style="width:40%;height:20px"></div>
</div>
Try it Yourself »
70%
Example
<div class="progress">
<div class="progress-bar" style="width:70%">70%</div>
</div>
Try it Yourself »
Example
<!-- Blue -->
<div class="progress">
<div class="progress-bar" style="width:10%"></div>
</div>
Try it Yourself »
Example
<div class="progress">
<div class="progress-bar progress-bar-striped" style="width:40%"></div>
</div>
Try it Yourself »
Example
<div class="progress-bar progress-bar-striped progress-bar-
animated" style="width:40%"></div>
Try it Yourself »
Free Space
Warning
Danger
Example
<div class="progress">
<div class="progress-bar bg-success" style="width:40%">
Free Space
</div>
<div class="progress-bar bg-warning" style="width:10%">
Warning
</div>
<div class="progress-bar bg-danger" style="width:20%">
Danger
</div>
</div>
Bootstrap 4 Spinners
❮ PreviousNext ❯
Spinners
To create a spinner/loader, use the .spinner-border class:
Loading..
Example
<div class="spinner-border"></div>
Try it Yourself »
Colored Spinners
Use any text color utilites to add a color to the spinner:
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Example
<div class="spinner-border text-muted"></div>
<div class="spinner-border text-primary"></div>
<div class="spinner-border text-success"></div>
<div class="spinner-border text-info"></div>
<div class="spinner-border text-warning"></div>
<div class="spinner-border text-danger"></div>
<div class="spinner-border text-secondary"></div>
<div class="spinner-border text-dark"></div>
<div class="spinner-border text-light"></div>
Try it Yourself »
Growing Spinners
Use the .spinner-grow class if you want the spinner/loader to grow instead of
"spin":
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Loading..
Example
<div class="spinner-grow text-muted"></div>
<div class="spinner-grow text-primary"></div>
<div class="spinner-grow text-success"></div>
<div class="spinner-grow text-info"></div>
<div class="spinner-grow text-warning"></div>
<div class="spinner-grow text-danger"></div>
<div class="spinner-grow text-secondary"></div>
<div class="spinner-grow text-dark"></div>
<div class="spinner-grow text-light"></div>
Try it Yourself »
Spinner Size
Use .spinner-border-sm or .spinner-grow-sm to create a smaller spinner:
Loading..
Loading..
Example
<div class="spinner-border spinner-border-sm"></div>
<div class="spinner-grow spinner-grow-sm"></div>
Try it Yourself »
Spinner Buttons
You can also add spinners to a button, with or without text:
Loading.. Loading.. Loading..
Example
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
</button>
<button class="btn btn-primary">
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
<button class="btn btn-primary" disabled>
<span class="spinner-border spinner-border-sm"></span>
Loading..
</button>
<button class="btn btn-primary" disabled>
<span class="spinner-grow spinner-grow-sm"></span>
Loading..
</button>
Bootstrap 4 Pagination
❮ PreviousNext ❯
Basic Pagination
If you have a web site with lots of pages, you may wish to add some sort of
pagination to each page.
Previous
1
2
3
Next
Example
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><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>
Try it Yourself »
Active State
The .active class is used to "highlight" the current page:
Previous
1
2
3
Next
Example
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item active"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
Try it Yourself »
ADVERTISEMENT
Disabled State
The .disabled class is used for un-clickable links:
Previous
1
2
3
Next
Example
<ul class="pagination">
<li class="page-item disabled"><a class="page-
link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
Try it Yourself »
Pagination Sizing
Pagination blocks can also be sized to a larger or a smaller size:
Previous
1
2
3
Next
Previous
1
2
3
Next
Example
<ul class="pagination pagination-lg">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
<ul class="pagination pagination-sm">
<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>
Try it Yourself »
Pagination Alignment
Use utility classes to change the alignment of the pagination:
Previous
1
2
3
Next
Previous
1
2
3
Next
Previous
1
2
3
Next
Example
<!-- Default (left-aligned) -->
<ul class="pagination" style="margin:20px 0">
<li class="page-item">...</li>
</ul>
Try it Yourself »
Photos
Summer 2017
Italy
Rome
Example
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Photos</a></li>
<li class="breadcrumb-item"><a href="#">Summer 2017</a></li>
<li class="breadcrumb-item"><a href="#">Italy</a></li>
<li class="breadcrumb-item active">Rome</li>
</ul>
First item
Second item
Third item
To create a basic list group, use an <ul> element with class .list-group,
and <li> elements with class .list-group-item:
Example
<ul class="list-group">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
Try it Yourself »
Active State
Active item
Second item
Third item
Example
<ul class="list-group">
<li class="list-group-item active">Active item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
</ul>
Try it Yourself »
Example
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">First
item</a>
<a href="#" class="list-group-item list-group-item-action">Second
item</a>
<a href="#" class="list-group-item list-group-item-action">Third
item</a>
</div>
Try it Yourself »
Disabled Item
The .disabled class adds a lighter text color to the disabled item. And when used
on links, it will remove the hover effect:
Example
<div class="list-group">
<a href="#" class="list-group-item disabled">Disabled item</a>
<a href="#" class="list-group-item disabled">Disabled item</a>
<a href="#" class="list-group-item">Third item</a>
</div>
Try it Yourself »
First item
Second item
Third item
Fourth item
Example
<ul class="list-group list-group-flush">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
<li class="list-group-item">Fourth item</li>
</ul>
Try it Yourself »
First item
Second item
Third item
Fourth item
Example
<ul class="list-group list-group-horizontal">
<li class="list-group-item">First item</li>
<li class="list-group-item">Second item</li>
<li class="list-group-item">Third item</li>
<li class="list-group-item">Fourth item</li>
</ul>
Try it Yourself »
Contextual Classes
Contextual classes can be used to color list items:
Success item
Secondary item
Info item
Warning item
Danger item
Primary item
Dark item
Light item
Example
<ul class="list-group">
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-secondary">Secondary
item</li>
<li class="list-group-item list-group-item-info">Info item</li>
<li class="list-group-item list-group-item-warning">Warning item</li>
<li class="list-group-item list-group-item-danger">Danger item</li>
<li class="list-group-item list-group-item-primary">Primary item</li>
<li class="list-group-item list-group-item-dark">Dark item</li>
<li class="list-group-item list-group-item-light">Light item</li>
</ul>
Try it Yourself »
Try it Yourself »
Inbox12
Ads50
Junk99
Example
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-
center">
Inbox
<span class="badge badge-primary badge-pill">12</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-
center">
Ads
<span class="badge badge-primary badge-pill">50</span>
</li>
<li class="list-group-item d-flex justify-content-between align-items-
center">
Junk
<span class="badge badge-primary badge-pill">99</span>
</li>
</ul>
Bootstrap 4 Cards
❮ PreviousNext ❯
Cards
A card in Bootstrap 4 is a bordered box with some padding around its content.
It includes options for headers, footers, content, colors, etc.
John Doe
Some example text some example text. John Doe is an architect and engineer
See Profile
Basic Card
A basic card is created with the .card class, and content inside the card has
a .card-body class:
Basic card
Example
<div class="card">
<div class="card-body">Basic card</div>
</div>
Try it Yourself »
If you are familiar with Bootstrap 3, cards replace old panels, wells, and
thumbnails.
Footer
Example
<div class="card">
<div class="card-header">Header</div>
<div class="card-body">Content</div>
<div class="card-footer">Footer</div>
</div>
Try it Yourself »
Contextual Cards
To add a background color the card, use contextual classes (.bg-primary, .bg-
success, .bg-info, .bg-warning, .bg-danger, .bg-secondary, .bg-dark and .bg-light.
Example
Basic card
Primary card
Success card
Info card
Warning card
Danger card
Secondary card
Dark card
Light card
Try it Yourself »
ADVERTISEMENT
Try it Yourself »
Card Images
John Doe
Some example text some example text. John Doe is an architect and engineer
See Profile
Jane Doe
Some example text some example text. Jane Doe is an architect and engineer
See Profile
Try it Yourself »
Stretched Link
Add the .stretched-link class to a link inside the card, and it will make the whole
card clickable and hoverable (the card will act as a link):
John Doe
Some example text some example text. John Doe is an architect and engineer
See Profile
Jane Doe
Some example text some example text. Jane Doe is an architect and engineer
See Profile
Example
<a href="#" class="btn btn-primary stretched-link">See Profile</a>
Try it Yourself »
Some example text some example text. Some example text some example text.
Some example text some example text. Some example text some example text.
See Profile
Example
<div class="card" style="width:500px">
<img class="card-img-top" src="img_avatar1.png" alt="Card image">
<div class="card-img-overlay">
<h4 class="card-title">John Doe</h4>
<p class="card-text">Some example text.</p>
<a href="#" class="btn btn-primary">See Profile</a>
</div>
</div>
Try it Yourself »
Card Columns
Some text inside the first card
Note: The cards are displayed vertically on small screens (less than 576px):
Example
<div class="card-columns">
<div class="card bg-primary">
<div class="card-body text-center">
<p class="card-text">Some text inside the first card</p>
</div>
</div>
<div class="card bg-warning">
<div class="card-body text-center">
<p class="card-text">Some text inside the second card</p>
</div>
</div>
<div class="card bg-success">
<div class="card-body text-center">
<p class="card-text">Some text inside the third card</p>
</div>
</div>
<div class="card bg-danger">
<div class="card-body text-center">
<p class="card-text">Some text inside the fourth card</p>
</div>
</div>
<div class="card bg-light">
<div class="card-body text-center">
<p class="card-text">Some text inside the fifth card</p>
</div>
</div>
<div class="card bg-info">
<div class="card-body text-center">
<p class="card-text">Some text inside the sixth card</p>
</div>
</div>
</div>
Try it Yourself »
Card Deck
Some text inside the first card
Note: The cards are displayed vertically on small screens (less than 576px):
Example
<div class="card-deck">
<div class="card bg-primary">
<div class="card-body text-center">
<p class="card-text">Some text inside the first card</p>
</div>
</div>
<div class="card bg-warning">
<div class="card-body text-center">
<p class="card-text">Some text inside the second card</p>
</div>
</div>
<div class="card bg-success">
<div class="card-body text-center">
<p class="card-text">Some text inside the third card</p>
</div>
</div>
<div class="card bg-danger">
<div class="card-body text-center">
<p class="card-text">Some text inside the fourth card</p>
</div>
</div>
</div>
Try it Yourself »
Card Group
Some text inside the first card
Example
<div class="card-group">
<div class="card bg-primary">
<div class="card-body text-center">
<p class="card-text">Some text inside the first card</p>
</div>
</div>
<div class="card bg-warning">
<div class="card-body text-center">
<p class="card-text">Some text inside the second card</p>
</div>
</div>
<div class="card bg-success">
<div class="card-body text-center">
<p class="card-text">Some text inside the third card</p>
</div>
</div>
<div class="card bg-danger">
<div class="card-body text-center">
<p class="card-text">Some text inside the fourth card</p>
</div>
</div>
</div>
Bootstrap 4 Dropdowns
❮ PreviousNext ❯
Basic Dropdown
A dropdown menu is a toggleable menu that allows the user to choose one
value from a predefined list:
Dropdown button
Example
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-
toggle="dropdown">
Dropdown button
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
</div>
</div>
Try it Yourself »
Example Explained
The .dropdown class indicates a dropdown menu.
To open the dropdown menu, use a button or a link with a class of .dropdown-
toggle and the data-toggle="dropdown" attribute.
Dropdown Divider
Dropdown button
Example
<div class="dropdown-divider"></div>
Try it Yourself »
ADVERTISEMENT
Dropdown Header
Dropdown button
Example
<div class="dropdown-header">Dropdown header 1</div>
Try it Yourself »
Example
<a class="dropdown-item active" href="#">Active</a>
<a class="dropdown-item disabled" href="#">Disabled</a>
Try it Yourself »
Dropdown Position
Dropright
Dropleft
Dropright
<div class="dropdown dropright">
Try it Yourself »
Dropleft
<div class="dropdown dropleft">
Try it Yourself »
Example
<div class="dropdown-menu dropdown-menu-right">
Try it Yourself »
Dropup
Dropdown button
Try it Yourself »
Dropdown Text
Dropdown button
Example
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item-text" href="#">Text Link</a>
<span class="dropdown-item-text">Just Text</span>
</div>
Try it Yourself »
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-
toggle="dropdown">
Sony
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Tablet</a>
<a class="dropdown-item" href="#">Smartphone</a>
</div>
</div>
</div>
Try it Yourself »
Secondary
Success
Info
Warning
Danger
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-
toggle-split" data-toggle="dropdown">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
</div>
</div>
Try it Yourself »
Vertical Button Group w/ Dropdown
AppleSamsung
Sony
Example
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Samsung</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-
toggle="dropdown">
Sony
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Tablet</a>
<a class="dropdown-item" href="#">Smartphone</a>
</div>
</div>
</div>
Bootstrap 4 Collapse
❮ PreviousNext ❯
Basic Collapsible
Collapsibles are useful when you want to hide and show large amount of
content:
Click Me
Example
<button data-toggle="collapse" data-target="#demo">Collapsible</button>
<div id="demo" class="collapse">
Lorem ipsum dolor text....
</div>
Try it Yourself »
Example Explained
The .collapse class indicates a collapsible element (a <div> in our example);
this is the content that will be shown or hidden with a click of a button.
Example
<a href="#demo" data-toggle="collapse">Collapsible</a>
<div id="demo" class="collapse">
Lorem ipsum dolor text....
</div>
Try it Yourself »
Example
<div id="demo" class="collapse show">
Lorem ipsum dolor text....
</div>
Try it Yourself »
ADVERTISEMENT
Accordion
Collapsible Group Item #1
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Example
<div id="accordion">
<div class="card">
<div class="card-header">
<a class="card-link" data-toggle="collapse" href="#collapseOne">
Collapsible Group Item #1
</a>
</div>
<div id="collapseOne" class="collapse show" data-parent="#accordion">
<div class="card-body">
Lorem ipsum..
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<a class="collapsed card-link" data-
toggle="collapse" href="#collapseTwo">
Collapsible Group Item #2
</a>
</div>
<div id="collapseTwo" class="collapse" data-parent="#accordion">
<div class="card-body">
Lorem ipsum..
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<a class="collapsed card-link" data-
toggle="collapse" href="#collapseThree">
Collapsible Group Item #3
</a>
</div>
<div id="collapseThree" class="collapse" data-parent="#accordion">
<div class="card-body">
Lorem ipsum..
</div>
</div>
</div>
</div>
Try it Yourself »
Bootstrap 4 Navs
❮ PreviousNext ❯
Nav Menus
LinkLinkLinkDisabled
Example
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Try it Yourself »
Aligned Nav
LinkLinkLinkDisabledLinkLinkLinkDisabled
Example
<!-- Centered nav -->
<ul class="nav justify-content-center">
Vertical Nav
LinkLinkLinkDisabled
Example
<ul class="nav flex-column">
Try it Yourself »
Tabs
Active LinkLinkDisabled
Turn the nav menu into navigation tabs with the .nav-tabs class. Add
the .active class to the active/current link. If you want the tabs to be togglable,
see the last example on this page.
Example
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Try it Yourself »
Pills
ActiveLinkLinkDisabled
Turn the nav menu into navigation pills with the .nav-pills class. If you want the
pills to be togglable, see the last example on this page.
Example
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Try it Yourself »
Justified Tabs/pills
Justify the tabs/pills with the .nav-justified class (equal width):
Active
Link
Link
Disabled
Active
Link
Link
Disabled
Example
<ul class="nav nav-pills nav-justified">..</ul>
<ul class="nav nav-tabs nav-justified">..</ul>
Try it Yourself »
Example
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-
toggle="dropdown" href="#">Dropdown</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Try it Yourself »
Example
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-
toggle="dropdown" href="#">Dropdown</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Try it Yourself »
Toggleable / Dynamic Tabs
Home
Menu 1
Menu 2
HOME
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
If you want the tabs to fade in and out when clicking on them, add
the .fade class to .tab-pane:
Example
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu1">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2">Menu 2</a>
</li>
</ul>
HOME
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
The same code applies to pills; only change the data-toggle attribute to data-
toggle="pill":
Example
<!-- Nav pills -->
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" data-toggle="pill" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#menu1">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="pill" href="#menu2">Menu 2</a>
</li>
</ul>
Navigation Bars
A navigation bar is a navigation header that is placed at the top of the page:
Logo
Link
Link
Disabled
Search
Basic Navbar
With Bootstrap, a navigation bar can extend or collapse, depending on the
screen size.
Link 1
Link 2
Link 3
Example
<!-- A grey horizontal navbar that becomes vertical on small screens -->
<nav class="navbar navbar-expand-sm bg-light">
</nav>
Try it Yourself »
Vertical Navbar
Remove the .navbar-expand-xl|lg|md|sm class to create a vertical navigation bar:
Link 1
Link 2
Link 3
Example
<!-- A vertical navbar -->
<nav class="navbar bg-light">
</nav>
Try it Yourself »
Centered Navbar
Add the .justify-content-center class to center the navigation bar.
The following example will center the navigation bar on medium, large and
extra large screens. On small screens it will be displayed vertically and left-
aligned (because of the .navbar-expand-sm class):
Link 1
Link 2
Link 3
Example
<nav class="navbar navbar-expand-sm bg-light justify-content-center">
...
</nav>
Try it Yourself »
Colored Navbar
Active
Link
Link
Disabled
Active
Link
Link
Disabled
Active
Link
Link
Disabled
Example
<!-- Grey with black text -->
<nav class="navbar navbar-expand-sm bg-light navbar-light">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</nav>
<!-- Black with white text -->
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">...</nav>
Try it Yourself »
Brand / Logo
The .navbar-brand class is used to highlight the brand/logo/project name of your
page:
Logo
Link 1
Link 2
Link 3
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="#">Logo</a>
...
</nav>
Try it Yourself »
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a class="navbar-brand" href="#">
<img src="bird.jpg" alt="Logo" style="width:40px;">
</a>
...
</nav>
Try it Yourself »
Very often, especially on small screens, you want to hide the navigation links
and replace them with a button that should reveal them when clicked on.
To create a collapsible navigation bar, use a button with class="navbar-toggler",
data-toggle="collapse" and data-target="#thetarget". Then wrap the navbar
content (links, etc) inside a div element with class="collapse navbar-collapse",
followed by an id that matches the data-target of the button: "thetarget".
Example
<nav class="navbar navbar-expand-md bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="#">Navbar</a>
Try it Yourself »
Tip: You can also remove the .navbar-expand-md class to ALWAYS hide navbar
links and display the toggler button.
Link 1
Link 2
Dropdown link
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<!-- Brand -->
<a class="navbar-brand" href="#">Logo</a>
Try it Yourself »
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<form class="form-inline" action="/action_page.php">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-success" type="submit">Search</button>
</form>
</nav>
Try it Yourself »
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<form class="form-inline" action="/action_page.php">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">@</span>
</div>
<input type="text" class="form-control" placeholder="Username">
</div>
</form>
</nav>
Try it Yourself »
Navbar Text
Link 1
Link 2
Navbar text
Use the .navbar-text class to vertical align any elements inside the navbar
that are not links (ensures proper padding and text color).
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
</nav>
Bootstrap 4 Forms
❮ PreviousNext ❯
Password:
Remember me
Submit
The following example creates a stacked form with two input fields, one
checkbox, and a submit button.
Example
<form action="/action_page.php">
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" placeholder="Enter
email" id="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" placeholder="Enter
password" id="pwd">
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Try it Yourself »
Remember me
Submit
Note: This only applies to forms within viewports that are at least
576px wide. On screens smaller than 576px, it will stack horizontally.
The following example creates an inline form with two input fields, one
checkbox, and one submit button:
Example
<form class="form-inline" action="/action_page.php">
<label for="email">Email address:</label>
<input type="email" class="form-control" placeholder="Enter
email" id="email">
<label for="pwd">Password:</label>
<input type="password" class="form-control" placeholder="Enter
password" id="pwd">
<div class="form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Try it Yourself »
Email: Password:
Remember me
Submit
Example
<form class="form-inline" action="/action_page.php">
<label for="email" class="mr-sm-2">Email address:</label>
<input type="email" class="form-control mb-2 mr-sm-
2" placeholder="Enter email" id="email">
<label for="pwd" class="mr-sm-2">Password:</label>
<input type="password" class="form-control mb-2 mr-sm-
2" placeholder="Enter password" id="pwd">
<div class="form-check mb-2 mr-sm-2">
<label class="form-check-label">
<input class="form-check-input" type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-primary mb-2">Submit</button>
</form>
Try it Yourself »
You will learn more about spacing and other "helper" classes in our Bootstrap 4
Utilities Chapter.
Form Row/Grid
You can also use columns (.col) to control the width and alignment of form
inputs without using spacing utilities. Just remember to put them inside
a .row container.
In the example below, we use two columns that will appear side by side. You
will learn much more about columns and rows in the Bootstrap Grids Chapter.
Example
<form>
<div class="row">
<div class="col">
<input type="text" class="form-control" id="email" placeholde
r="Enter email" name="email">
</div>
<div class="col">
<input type="password" class="form-control" placeholder="Enter
password" name="pswd">
</div>
</div>
</form>
Try it Yourself »
If you want less grid margins (override default column gutters), use .form-
row instead of .row:
Example
<form>
<div class="form-row">
<div class="col">
<input type="text" class="form-control" id="email" placeholde
r="Enter email" name="email">
</div>
<div class="col">
<input type="password" class="form-control" placeholder="Enter
password" name="pswd">
</div>
</div>
</form>
Try it Yourself »
Form Validation
Username:
Please fill out this field.
Password:
Please fill out this field.
I agree on blabla.
Check this checkbox to continue.
You can use different validation classes to provide valuable feedback to users.
Add either .was-validated or .needs-validation to the <form> element, depending on
whether you want to provide validation feedback before or after submitting the
form. The input fields will have a green (valid) or red (invalid) border to indicate
what's missing in the form. You can also add a .valid-feedback or .invalid-
feedback message to tell the user explicitly what's missing, or needs to be done
before submitting the form.
Example
In this example, we use .was-validated to indicate what's missing before
submitting the form:
<form action="/action_page.php" class="was-validated">
<div class="form-group">
<label for="uname">Username:</label>
<input type="text" class="form-control" id="uname" placeholder="Enter
username" name="uname" required>
<div class="valid-feedback">Valid.</div>
<div class="invalid-feedback">Please fill out this field.</div>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholde
r="Enter password" name="pswd" required>
<div class="valid-feedback">Valid.</div>
<div class="invalid-feedback">Please fill out this field.</div>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember" req
uired> I agree on blabla.
<div class="valid-feedback">Valid.</div>
<div class="invalid-feedback">Check this checkbox to
continue.</div>
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
Try it Yourself »
Example
In this example, we use .needs-validation, which will add the validation effect
AFTER the form has been submitting (if there's anything missing). Note that you
will also have to add some jQuery code for this example to work properly:
<form action="/action_page.php" class="needs-validation" novalidate>
<div class="form-group">
<label for="uname">Username:</label>
<input type="text" class="form-control" id="uname" placeholder="Enter
username" name="uname" required>
<div class="valid-feedback">Valid.</div>
<div class="invalid-feedback">Please fill out this field.</div>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholde
r="Enter password" name="pswd" required>
<div class="valid-feedback">Valid.</div>
<div class="invalid-feedback">Please fill out this field.</div>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember" req
uired> I agree on blabla.
<div class="valid-feedback">Valid.</div>
<div class="invalid-feedback">Check this checkbox to
continue.</div>
</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<script>
// Disable form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
// Get the forms we want to add validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
input
textarea
checkbox
radio
select
Bootstrap Input
Bootstrap supports all the HTML5 input types: text, password, datetime,
datetime-local, date, month, time, week, number, email, url, search, tel, and
color.
Note: Inputs will NOT be fully styled if their type is not properly declared!
Name:
Password:
The following example contains two input elements; one of type="text" and one
of type="password". As we mentioned in the Forms chapter, we use the .form-
control class to style inputs with full-width and proper padding, etc:
Example
<div class="form-group">
<label for="usr">Name:</label>
<input type="text" class="form-control" id="usr">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
Try it Yourself »
Bootstrap Textarea
Comment:
Example
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5" id="comment"></textarea>
</div>
Try it Yourself »
ADVERTISEMENT
Bootstrap Checkboxes
Option 1
Option 2
Option 3
Checkboxes are used if you want the user to select any number of options from
a list of preset options.
The following example contains three checkboxes. The last option is disabled:
Example
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="">Option 1
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="">Option 2
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="" disable
d>Option 3
</label>
</div>
Try it Yourself »
Example explained
Use a wrapper element with class="form-check" to ensure proper margins for
labels and checkboxes.
Inline Checkboxes
Use the .form-check-inline class if you want the checkboxes to appear on the
same line:
Option 1
Option 2
Option 3
Example
<div class="form-check-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="">Option 1
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="">Option 2
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" value="" disable
d>Option 3
</label>
</div>
Try it Yourself »
Option 2
Option 3
Radio buttons are used if you want to limit the user to just one selection from a
list of preset options.
The following example contains three radio buttons. The last option is disabled:
Example
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio">Option 1
</label>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio">Option 2
</label>
</div>
<div class="form-check disabled">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio" disable
d>Option 3
</label>
</div>
Try it Yourself »
Option 1
Option 2
Option 3
Example
<div class="form-check-inline">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio">Option 1
</label>
</div>
<div class="form-check-inline">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio">Option 2
</label>
</div>
<div class="form-check-inline disabled">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="optradio" disable
d>Option 3
</label>
</div>
Try it Yourself »
Bootstrap Select List
Select list (select one):
Multiple select list (hold ctrl or shift (or drag with the mouse) to select more
than one):
Select lists are used if you want to allow the user to pick from multiple options.
Example
<div class="form-group">
<label for="sel1">Select list:</label>
<select class="form-control" id="sel1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</div>
Try it Yourself »
Example
<input type="text" class="form-control form-control-sm">
<input type="text" class="form-control form-control">
<input type="text" class="form-control form-control-lg">
Try it Yourself »
Form Control with Plain Text
Use the .form-control-plaintext if you want to style the input field as plain text:
Example
<input type="text" class="form-control-plaintext">
Try it Yourself »
Example
<input type="range" class="form-control-range">
<input type="file" class="form-control-file border">
@example.com
Example
<form>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">@</span>
</div>
<input type="text" class="form-control" placeholder="Username">
</div>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Your Email">
<div class="input-group-append">
<span class="input-group-text">@example.com</span>
</div>
</div>
</form>
Try it Yourself »
Tip: We use the .mb-3 utility class to ensure that the input group gets a proper
margin bottom. Read more about utility classes in our BS4 Utilities Chapter.
Small
Default
Large
Example
<form>
<div class="input-group mb-3 input-group-sm">
<div class="input-group-prepend">
<span class="input-group-text">Small</span>
</div>
<input type="text" class="form-control">
</div>
</form>
<form>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Default</span>
</div>
<input type="text" class="form-control">
</div>
</form>
<form>
<div class="input-group mb-3 input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text">Large</span>
</div>
<input type="text" class="form-control">
</div>
</form>
Try it Yourself »
Person
OneTwoThree
Example
<!-- Multiple inputs -->
<form>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text">Person</span>
</div>
<input type="text" class="form-control" placeholder="First Name">
<input type="text" class="form-control" placeholder="Last Name">
</div>
</form>
Try it Yourself »
<div class="input-group mb-3">
<div class="input-group-prepend">
<div class="input-group-text">
<input type="radio">
</div>
</div>
<input type="text" class="form-control" placeholder="Some text">
</div>
Try it Yourself »
Go
OKCancel
Example
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-primary" type="button">Basic
Button</button>
</div>
<input type="text" class="form-control" placeholder="Some text">
</div>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Search">
<div class="input-group-append">
<button class="btn btn-success" type="submit">Go</button>
</div>
</div>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Something
clever..">
<div class="input-group-append">
<button class="btn btn-primary" type="button">OK</button>
<button class="btn btn-danger" type="button">Cancel</button>
</div>
</div>
Try it Yourself »
Dropdown button
Example
<div class="input-group mt-3 mb-3">
<div class="input-group-prepend">
<button type="button" class="btn btn-outline-secondary dropdown-
toggle" data-toggle="dropdown">
Dropdown button
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Link 1</a>
<a class="dropdown-item" href="#">Link 2</a>
<a class="dropdown-item" href="#">Link 3</a>
</div>
</div>
<input type="text" class="form-control" placeholder="Username">
</div>
Try it Yourself »
@example.com
Example
<label for="demo">Write your email here:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Email" id="demo" n
ame="email">
<div class="input-group-append">
<span class="input-group-text">@example.com</span>
</div>
</div>
Custom checkbox
Default checkbox
Custom radio
Default radio
Custom Range:
Default Range:
Custom Checkbox
To create a custom checkbox, wrap a container element, like <div>, with a
class of .custom-control and .custom-checkbox around the checkbox. Then add
the .custom-control-input to the input with type="checkbox".
Custom checkbox
Default checkbox
Example
<form>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck"
name="example1">
<label class="custom-control-label" for="customCheck">Check this
custom checkbox</label>
</div>
</form>
Try it Yourself »
Custom Switch
To create a custom "toggle switch", wrap a container element, like <div>, with
a class of .custom-control and .custom-switch around a checkbox. Then add
the .custom-control-input class to the checkbox:
Toggle me
Example
<form>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="switch1">
<label class="custom-control-label" for="switch1">Toggle me</label>
</div>
</form>
Try it Yourself »
Custom radio
Default radio
Example
<form>
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="customRadio" nam
e="example1" value="customEx">
<label class="custom-control-label" for="customRadio">Custom
radio</label>
</div>
</form>
Try it Yourself »
Custom radio
Custom radio
Example
<form>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="customRadio" nam
e="example" value="customEx">
<label class="custom-control-label" for="customRadio">Custom radio
1</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" class="custom-control-input" id="customRadio2" na
me="example" value="customEx">
<label class="custom-control-label" for="customRadio2">Custom radio
2</label>
</div>
</form>
Try it Yourself »
Example
<form>
<select name="cars" class="custom-select">
<option selected>Custom Select Menu</option>
<option value="volvo">Volvo</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</form>
Try it Yourself »
Example
<form>
<!-- Small -->
<select name="cars" class="custom-select-sm">
<option selected>Small Custom Select Menu</option>
<option value="volvo">Volvo</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
Try it Yourself »
Custom Range
To create a custom range menu, add the .custom-range class to an input with
type="<range>":
Custom range
Default range
Example
<form>
<label for="customRange">Custom range</label>
<input type="range" class="custom-range" id="customRange" nam
e="points1">
</form>
Try it Yourself »
Choose file
Default file:
Note that you also have to include some jQuery code if you want the name of
the file to appear when you select a specific file:
Example
<form>
<div class="custom-file">
<input type="file" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</form>
<script>
// Add the following code if you want the name of the file appear on
select
$(".custom-file-input").on("change", function() {
var fileName = $(this).val().split("\\").pop();
$(this).siblings(".custom-file-
label").addClass("selected").html(fileName);
});
</script>
Bootstrap 4 Carousel
❮ PreviousNext ❯
Bootstrap 4 Carousel
The Carousel is a slideshow for cycling through elements.
How To Create a Carousel
The following example shows how to create a basic carousel with indicators and
controls:
Example
<div id="demo" class="carousel slide" data-ride="carousel">
</div>
Try it Yourself »
Example explained
A description of what each class from the example above do:
Class Description
.carousel- Adds indicators for the carousel. These are the little dots at the
indicators bottom of each slide (which indicates how many slides there are
in the carousel, and which slide the user are currently viewing)
.carousel- Adds a left (previous) button to the carousel, which allows the
control-prev user to go back between the slides
.carousel- Adds a right (next) button to the carousel, which allows the user
control-next to go forward between the slides
.slide Adds a CSS transition and animation effect when sliding from one
item to the next. Remove this class if you do not want this effect
Example
<div class="carousel-item">
<img src="la.jpg" alt="Los Angeles">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>We had such a great time in LA!</p>
</div>
</div>
Bootstrap 4 Modal
❮ PreviousNext ❯
Bootstrap 4 Modal
The Modal component is a dialog box/popup window that is displayed on top of
the current page:
Open modal
Example
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-
target="#myModal">
Open modal
</button>
</div>
</div>
</div>
Try it Yourself »
Add animation
Use the .fade class to add a fading effect when opening and closing the modal:
Example
<!-- Fading modal -->
<div class="modal fade"></div>
Try it Yourself »
Modal Size
Change the size of the modal by adding the .modal-sm class for small
modals, .modal-lg class for large modals, or .modal-xl for extra large modals.
Add the size class to the <div> element with class .modal-dialog:
Small Modal
<div class="modal-dialog modal-sm">
Try it Yourself »
Large Modal
<div class="modal-dialog modal-lg">
Try it Yourself »
Try it Yourself »
Centered Modal
Center the modal vertically and horizontally within the page, with the .modal-
dialog-centered class:
Example
<div class="modal-dialog modal-dialog-centered">
Try it Yourself »
Scrolling Modal
When you have alot of content inside the modal, a scrollbar is added to the
page. See the examples below to understand it:
Example
<div class="modal-dialog">
Try it Yourself »
However, it is possible to only scroll inside the modal, instead of the page itself,
by adding .modal-dialog-scrollable to .modal-dialog:
Example
<div class="modal-dialog modal-dialog-scrollable">
Bootstrap 4 Tooltip
❮ PreviousNext ❯
Bootstrap 4 Tooltip
The Tooltip component is small pop-up box that appears when the user moves
the mouse pointer over an element:
Use the title attribute to specify the text that should be displayed inside the
tooltip:
Note: Tooltips must be initialized with jQuery: select the specified element and
call the tooltip() method.
Try it Yourself »
Positioning Tooltips
By default, the tooltip will appear on top of the element.
Example
<a href="#" data-toggle="tooltip" data-placement="top" titl
e="Hooray!">Hover</a>
<a href="#" data-toggle="tooltip" data-placement="bottom" titl
e="Hooray!">Hover</a>
<a href="#" data-toggle="tooltip" data-placement="left" titl
e="Hooray!">Hover</a>
<a href="#" data-toggle="tooltip" data-placement="right" titl
e="Hooray!">Hover</a>
Bootstrap 4 Popover
❮ PreviousNext ❯
Bootstrap 4 Popover
The Popover component is similar to tooltips; it is a pop-up box that appears
when the user clicks on an element. The difference is that the popover can
contain much more content.
Use the title attribute to specify the header text of the popover, and use
the data-content attribute to specify the text that should be displayed inside the
popover's body:
<a href="#" data-toggle="popover" title="Popover Header" data-
content="Some content inside the popover">Toggle popover</a>
Example
<script>
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
Try it Yourself »
Positioning Popovers
By default, the popover will appear on the right side of the element.
Use the data-placement attribute to set the position of the popover on top,
bottom, left or the right side of the element:
Example
<a href="#" title="Header" data-toggle="popover" data-placement="top" dat
a-content="Content">Click</a>
<a href="#" title="Header" data-toggle="popover" data-placement="bottom"
data-content="Content">Click</a>
<a href="#" title="Header" data-toggle="popover" data-placement="left" da
ta-content="Content">Click</a>
<a href="#" title="Header" data-toggle="popover" data-placement="right" d
ata-content="Content">Click</a>
Try it Yourself »
Closing Popovers
By default, the popover is closed when you click on the element again.
However, you can use the data-trigger="focus" attribute which will close the
popover when clicking outside the element:
Example
<a href="#" title="Dismissible popover" data-toggle="popover" data-
trigger="focus" data-content="Click anywhere in the document to close
this popover">Click me</a>
Try it Yourself »
Tip: If you want the popover to be displayed when you move the mouse pointer
over the element, use the data-trigger attribute with a value of "hover":
Example
<a href="#" title="Header" data-toggle="popover" data-trigger="hover" dat
a-content="Some content">Hover over me</a>
-
Bootstrap 4 Toast
❮ PreviousNext ❯
Bootstrap 4 Toast
The toast component is like an alert box that is only shown for a couple of
seconds when something happens (i.e. when the user clicks on a button,
submits a form, etc.).
<div class="toast">
<div class="toast-header">
Toast Header
</div>
<div class="toast-body">
Some text inside the toast body
</div>
</div>
Note: Toasts must be initialized with jQuery: select the specified element and
call the toast() method.
Example
<script>
$(document).ready(function(){
$('.toast').toast('show');
});
</script>
Try it Yourself »
Example
<div class="toast" data-autohide="false">
<div class="toast-header">
<strong class="mr-auto text-primary">Toast Header</strong>
<small class="text-muted">5 mins ago</small>
<button type="button" class="ml-2 mb-1 close" data-
dismiss="toast">×</button>
</div>
<div class="toast-body">
Some text inside the toast body
</div>
</div>
Try it Yourself »
-
Bootstrap 4 Scrollspy
(Advanced)
❮ PreviousNext ❯
Bootstrap 4 Scrollspy
Scrollspy is used to automatically update links in a navigation list based
on scroll position.
Example
<!-- The scrollable area -->
<body data-spy="scroll" data-target=".navbar" data-offset="50">
<!-- The navbar - The <a> elements are used to jump to a section in the
scrollable area -->
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
...
<ul class="navbar-nav">
<li><a href="#section1">Section 1</a></li>
...
</nav>
</body>
Try it Yourself »
Example Explained
Add data-spy="scroll" to the element that should be used as the scrollable area
(often this is the <body> element).
Then add the data-target attribute with a value of the id or the class name of the
navigation bar (.navbar). This is to make sure that the navbar is connected with
the scrollable area.
Note that scrollable elements must match the ID of the links inside the navbar's
list items (<div id="section1"> matches <a href="#section1">).
ADVERTISEMENT
Example
<body data-spy="scroll" data-target="#myScrollspy" data-offset="1">
<div class="container-fluid">
<div class="row">
<nav class="col-sm-3 col-4" id="myScrollspy">
<ul class="nav nav-pills flex-column">
<li class="nav-item">
<a class="nav-link active" href="#section1">Section 1</a>
</li>
...
</ul>
</nav>
<div class="col-sm-9 col-8">
<div id="section1">
<h1>Section 1</h1>
<p>Try to scroll this page and look at the menu while
scrolling!</p>
</div>
...
</div>
</div>
</div>
</body>
Try it Yourself »
Bootstrap 4 Utilities
❮ PreviousNext ❯
Bootstrap 4 Utilities
Bootstrap 4 has a lot of utility/helper classes to quickly style elements without
using any CSS code.
Borders
Use the border classes to add or remove borders from an element:
Example
Example
<span class="border"></span>
<span class="border border-0"></span>
<span class="border border-top-0"></span>
<span class="border border-right-0"></span>
<span class="border border-bottom-0"></span>
<span class="border border-left-0"></span>
Try it Yourself »
Border Color
Add a color to the border with any of the contextual border color classes:
Example
Example
<span class="border border-primary"></span>
<span class="border border-secondary"></span>
<span class="border border-success"></span>
<span class="border border-danger"></span>
<span class="border border-warning"></span>
<span class="border border-info"></span>
<span class="border border-light"></span>
<span class="border border-dark"></span>
<span class="border border-white"></span>
Try it Yourself »
Border Radius
Add rounded corners to an element with the rounded classes:
Example
Example
<span class="rounded-sm"></span>
<span class="rounded"></span>
<span class="rounded-lg"></span>
<span class="rounded-top"></span>
<span class="rounded-right"></span>
<span class="rounded-bottom"></span>
<span class="rounded-left"></span>
<span class="rounded-circle"></span>
<span class="rounded-0"></span>
Try it Yourself »
Example
Float leftFloat right
Example
<div class="clearfix">
<span class="float-left">Float left</span>
<span class="float-right">Float right</span>
</div>
Try it Yourself »
Responsive Floats
Float an element to the left or to the right depending on screen width, with the
responsive float classes (.float-*-left|right - where *
is sm (>=576px), md (>=768px), lg (>=992px) or xl (>=1200px)):
Example
Float right on small screens or wider
Float none
Example
<div class="float-sm-right">Float right on small screens or
wider</div><br>
<div class="float-md-right">Float right on medium screens or
wider</div><br>
<div class="float-lg-right">Float right on large screens or
wider</div><br>
<div class="float-xl-right">Float right on extra large screens or
wider</div><br>
<div class="float-none">Float none</div>
Try it Yourself »
Center Align
Center an element with the .mx-auto class (adds margin-left and margin-right:
auto):
Example
Centered
Example
<div class="mx-auto bg-warning" style="width:150px">Centered</div>
Try it Yourself »
Width
Set the width of an element with the w-* classes (.w-25, .w-50, .w-75, .w-100, .mw-
100):
Example
Width 25%
Width 50%
Width 75%
Width 100%
Max Width 100%
Example
<div class="w-25 bg-warning">Width 25%</div>
<div class="w-50 bg-warning">Width 50%</div>
<div class="w-75 bg-warning">Width 75%</div>
<div class="w-100 bg-warning">Width 100%</div>
<div class="mw-100 bg-warning">Max Width 100%</div>
Try it Yourself »
Height
Set the height of an element with the h-* classes ( .h-25, .h-50, .h-75, .h-100, .mh-
100):
Example
Height 25%
Height 50%
Height 75%
Height 100%
Example
<div style="height:200px;background-color:#ddd">
<div class="h-25 bg-warning">Height 25%</div>
<div class="h-50 bg-warning">Height 50%</div>
<div class="h-75 bg-warning">Height 75%</div>
<div class="h-100 bg-warning">Height 100%</div>
<div class="mh-100 bg-warning" style="height:500px">Max Height
100%</div>
</div>
Try it Yourself »
Spacing
Bootstrap 4 has a wide range of responsive margin and padding utility classes.
They work for all
breakpoints: xs (<=576px), sm (>=576px), md (>=768px), lg (>=992px)
or xl (>=1200px)):
m - sets margin
p - sets padding
t - sets margin-top or padding-top
b - sets margin-bottom or padding-bottom
l - sets margin-left or padding-left
r - sets margin-right or padding-right
x - sets both padding-left and padding-right or margin-
left and margin-right
y - sets both padding-top and padding-bottom or margin-
top and margin-bottom
blank - sets a margin or padding on all 4 sides of the element
0 - sets margin or padding to 0
1 - sets margin or padding to .25rem (4px if font-size is 16px)
2 - sets margin or padding to .5rem (8px if font-size is 16px)
3 - sets margin or padding to 1rem (16px if font-size is 16px)
4 - sets margin or padding to 1.5rem (24px if font-size is 16px)
5 - sets margin or padding to 3rem (48px if font-size is 16px)
auto - sets margin to auto
Example
I only have a top padding (1.5rem = 24px)
I have a padding on all sides (3rem = 48px)
I have a margin on all sides (3rem = 48px) and a bottom padding (3rem =
48px)
Example
<div class="pt-4 bg-warning">I only have a top padding (1.5rem =
24px)</div>
<div class="p-5 bg-success">I have a padding on all sides (3rem =
48px)</div>
<div class="m-5 pb-5 bg-info">I have a margin on all sides (3rem = 48px)
and a bottom padding (3rem = 48px)</div>
Try it Yourself »
More Spacing Examples
Shadows
Use the shadow- classes to add shadows to an element:
Example
No shadow
Small shadow
Default shadow
Large shadow
Example
<div class="shadow-none p-4 mb-4 bg-light">No shadow</div>
<div class="shadow-sm p-4 mb-4 bg-white">Small shadow</div>
<div class="shadow p-4 mb-4 bg-white">Default shadow</div>
<div class="shadow-lg p-4 mb-4 bg-white">Large shadow</div>
Try it Yourself »
Vertical Align
Use the align- classes to change the alignment of elements (only works on
inline, inline-block, inline-table and table cell elements):
Example
baseline top middle bottom text-top text-bottom
Example
<span class="align-baseline">baseline</span>
<span class="align-top">top</span>
<span class="align-middle">middle</span>
<span class="align-bottom">bottom</span>
<span class="align-text-top">text-top</span>
<span class="align-text-bottom">text-bottom</span>
Try it Yourself »
Responsive Embeds
Create responsive video or slideshow embeds based on the width of the parent.
Example
Example
<!-- 21:9 aspect ratio -->
<div class="embed-responsive embed-responsive-21by9">
<iframe class="embed-responsive-item" src="..."></iframe>
</div>
Try it Yourself »
Visibility
Use the .visible or .invisible classes to control the visibility of
elements. Note: These classes do not change the CSS display value. They only
add visibility:visible or visibility:hidden:
Example
I am visible
Example
<div class="visible">I am visible</div>
<div class="invisible">I am invisible</div>
Try it Yourself »
Position
Use the .fixed-top class to make any element fixed/stay at the top of the page:
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
...
</nav>
Try it Yourself »
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-bottom">
...
</nav>
Try it Yourself »
Example
<nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top">
...
</nav>
Try it Yourself »
Close icon
Use the .close class to style a close icon. This is often used for alerts and
modals. Note that we use the × symbol to create the actual icon (a better
looking "x"). Also note that it floats right by default:
Example
×
Example
<button type="button" class="close">×</button>
Try it Yourself »
Screenreaders
Use the .sr-only class to hide an element on all devices, except screen readers:
Example
<span class="sr-only">I will be hidden on all screens except for screen
readers.</span>
Try it Yourself »
Colors
As described in the Colors chapter, here is a list of all text and background color
classes:
Example
This text is muted.
Secondary text.
Body text.
Contextual text classes can also be used on links, which will add a darker hover
color:
Example
Muted link. Primary link. Success link. Info link. Warning link. Danger link. Secondary
link. Dark grey link. Body/black link. Light grey link.
Try it Yourself »
You can also add 50% opacity for black or white text with the .text-black-
50 or .text-white-50 classes:
Example
Black text with 50% opacity on white background
Background Colors
The classes for background colors are: .bg-primary, .bg-success, .bg-info, .bg-
warning, .bg-danger, .bg-secondary, .bg-dark and .bg-light.
Note that background colors do not set the text color, so in some cases you'll
want to use them together with a .text-* class.
Example
This text is important.
Typography/Text Classes
As described in the Typography chapter, here is a list of all typography/text classes:
Class Description Example
.display-* Display headings are used to stand out more than normal Try it
headings (larger font-size and lighter font-weight), and
there are four classes to choose from: .display-
1, .display-2, .display-3, .display-4
.small Indicates smaller text (set to 85% of the size of the Try it
parent)
.text-reset Resets the color of a text or a link (inherits the color Try it
from its parent)
.list- Removes the default list-style and left margin on list Try it
unstyled items (works on both <ul> and <ol>). This class only
applies to immediate children list items (to remove the
default list-style from any nested lists, apply this class to
any nested lists as well)
.list-inline Places all list items on a single line (used together Try it
with .list-inline-item on each <li> elements)
Block Elements
To make an element into a block element, add the .d-block class. Use any of
the d-*-block classes to control WHEN the element should be a block element on
a specific screen width:
Example
d-blockd-sm-blockd-md-blockd-lg-blockd-xl-block
Example
<span class="d-block bg-success">d-block</span>
<span class="d-sm-block bg-success">d-sm-block</span>
<span class="d-md-block bg-success">d-md-block</span>
<span class="d-lg-block bg-success">d-lg-block</span>
<span class="d-xl-block bg-success">d-xl-block</span>
Try it Yourself »
Flex
Use .flex-* classes to control the layout with flexbox.
Example
Horizontal:
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Vertical:
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Bootstrap 4 Flex
❮ PreviousNext ❯
Bootstrap 4 Flex
Use flex classes to control the layout of Bootstrap 4 components.
Flexbox
The biggest difference between Bootstrap 3 and Bootstrap 4 is that Bootstrap 4
now uses flexbox, instead of floats, to handle the layout.
The Flexible Box Layout Module, makes it easier to design flexible responsive
layout structure without using float or positioning. If you are new to flex, you
can read about it in our CSS Flexbox Tutorial.
To create a flexbox container and to transform direct children into flex items,
use the d-flex class:
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex p-3 bg-secondary text-white">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Try it Yourself »
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-inline-flex p-3 bg-secondary text-white">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Try it Yourself »
Horizontal Direction
Use .flex-row to display the flex items horizontally (side by side). This is default.
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex flex-row bg-secondary">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Try it Yourself »
Vertical Direction
Use .flex-column to display the flex items vertically (on top of each other),
or .flex-column-reverse to reverse the vertical direction:
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex flex-column">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
<div class="d-flex flex-column-reverse">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
Try it Yourself »
Justify Content
Use the .justify-content-* classes to change the alignment of flex items. Valid
classes are start (default), end, center, between or around:
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex justify-content-start">...</div>
<div class="d-flex justify-content-end">...</div>
<div class="d-flex justify-content-center">...</div>
<div class="d-flex justify-content-between">...</div>
<div class="d-flex justify-content-around">...</div>
Try it Yourself »
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex">
<div class="p-2 bg-info flex-fill">Flex item 1</div>
<div class="p-2 bg-warning flex-fill">Flex item 2</div>
<div class="p-2 bg-primary flex-fill">Flex item 3</div>
</div>
Try it Yourself »
Grow
Use .flex-grow-1 on a flex item to take up the rest of the space. In the example
below, the first two flex items take up their necessary space, while the last item
takes up the rest of the available space:
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary flex-grow-1">Flex item 3</div>
</div>
Try it Yourself »
Order
Change the visual order of a specific flex item(s) with the .order classes. Valid
classes are from 0 to 12, where the lowest number has highest priority (order-1
is shown before order-2, etc..):
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex bg-secondary">
<div class="p-2 bg-info order-3">Flex item 1</div>
<div class="p-2 bg-warning order-2">Flex item 2</div>
<div class="p-2 bg-primary order-1">Flex item 3</div>
</div>
Try it Yourself »
Auto Margins
Easily add auto margins to flex items with .mr-auto (push items to the right), or
by using .ml-auto (push items to the left):
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex bg-secondary">
<div class="p-2 mr-auto bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 bg-primary">Flex item 3</div>
</div>
<div class="d-flex bg-secondary">
<div class="p-2 bg-info">Flex item 1</div>
<div class="p-2 bg-warning">Flex item 2</div>
<div class="p-2 ml-auto bg-primary">Flex item 3</div>
</div>
Try it Yourself »
Wrap
Control how flex items wrap in a flex container with .flex-nowrap (default), .flex-
wrap or .flex-wrap-reverse.
Click on the buttons below to see the difference between the three classes, by
changing the wrapping of the flex items in the example box:
flex-wrap flex-wrap-reverse flex-nowrap
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 4
Flex item 5
Flex item 6
Flex item 7
Flex item 8
Flex item 9
Flex item 10
Flex item 11
Flex item 12
Flex item 13
Flex item 14
Flex item 15
Flex item 16
Flex item 17
Flex item 18
Flex item 19
Flex item 20
Flex item 21
Flex item 22
Flex item 23
Flex item 24
Flex item 25
Example
<div class="d-flex flex-wrap">..</div>
<div class="d-flex flex-wrap-reverse">..</div>
<div class="d-flex flex-nowrap">..</div>
Try it Yourself »
Align Content
Control the vertical alignment of gathered flex items with the .align-content-
* classes. Valid classes are .align-content-start (default), .align-content-
end, .align-content-center, .align-content-between, .align-content-around and .align-
content-stretch.
Click on the buttons below to see the difference between the five classes, by
changing the vertical alignment of the flex items in the example box:
align-content-start align-content-end align-content-center align-content-around
align-content-stretch
Example
Flex item 1
Flex item 2
Flex item 3
Flex item 4
Flex item 5
Flex item 6
Flex item 7
Flex item 8
Flex item 9
Flex item 10
Flex item 11
Flex item 12
Flex item 13
Flex item 14
Flex item 15
Flex item 16
Flex item 17
Flex item 18
Flex item 19
Flex item 20
Flex item 21
Flex item 22
Flex item 23
Flex item 24
Flex item 25
Example
<div class="d-flex flex-wrap align-content-start">..</div>
<div class="d-flex flex-wrap align-content-center">..</div>
<div class="d-flex flex-wrap align-content-around">..</div>
<div class="d-flex flex-wrap align-content-stretch">..</div>
Try it Yourself »
Align Items
Control the vertical alignment of single rows of flex items with the .align-
items-* classes. Valid classes are .align-items-start, .align-items-end, .align-items-
center, .align-items-baseline, and .align-items-stretch (default).
Click on the buttons below to see the difference between the five classes:
align-items-start align-items-end align-items-center align-items-baseline align-
items-stretch
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex align-items-start">..</div>
<div class="d-flex align-items-end">..</div>
<div class="d-flex align-items-center">..</div>
<div class="d-flex align-items-baseline">..</div>
<div class="d-flex align-items-stretch">..</div>
Try it Yourself »
Align Self
Control the vertical alignment of a specified flex item with the .align-self-
* classes. Valid classes are .align-self-start, .align-self-end, .align-self-
center, .align-self-baseline, and .align-self-stretch (default).
Click on the buttons below to see the difference between the five classes:
align-self-start align-self-end align-self-center align-self-baseline align-self-
stretch
Example
Flex item 1
Flex item 2
Flex item 3
Example
<div class="d-flex bg-light" style="height:150px">
<div class="p-2 border">Flex item 1</div>
<div class="p-2 border align-self-start">Flex item 2</div>
<div class="p-2 border">Flex item 3</div>
</div>
Try it Yourself »
The * symbol can be replaced with sm, md, lg or xl, which represents small,
medium, large or xlarge screens.
Class Description Example
Flex Container
Direction
Justified Content
.justify-content-*-start Display flex items from the start (left-aligned) on different Try it
screens
.flex-*-fill Force flex items into equal widths on different screens Try it
Grow
Order
Wrap
Align Content
.align-content-*-start Align gathered items from the start on different screens Try it
.align-content-*-end Align gathered items at the end on different screens Try it
Align Items
.align-items-*-start Align single rows of items from the start on different Try it
screens
.align-items-*-end Align single rows of items at the end on different screens Try it
Align Self
.align-self-*-start Align a flex item from the start on different screens Try it
Bootstrap 4 Icons
❮ PreviousNext ❯
Bootstrap 4 Icons
Bootstrap 4 does not have its own icon library (Glyphicons from Bootstrap 3 are
not supported in BS4). However, there are many free icon libraries to choose
from, such as Font Awesome and Google Material Design Icons.
To use Font Awesome icons, add the following to your HTML page (No
downloading or installation is required):
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/
css/all.css" integrity="sha384-
lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossor
igin="anonymous">
Then, add the name of the icon class to any inline HTML element
(like <i> or <span>):
Example
<i class="fas fa-cloud"></i>
<i class="fas fa-coffee"></i>
<i class="fas fa-car"></i>
<i class="fas fa-file"></i>
<i class="fas fa-bars"></i>
Media Objects
Bootstrap provides an easy way to align media objects (like images or videos)
together with content. Media objects are often used to display blog comments,
tweets and so on:
John Doe Posted on February 19, 2016
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
John Doe Posted on February 20, 2016
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Example
<div class="media border p-3">
<img src="img_avatar3.png" alt="John Doe" class="mr-3 mt-3 rounded-
circle" style="width:60px;">
<div class="media-body">
<h4>John Doe <small><i>Posted on February 19, 2016</i></small></h4>
<p>Lorem ipsum...</p>
</div>
</div>
Try it Yourself »
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Jane Doe Posted on February 20, 2016
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Example
<div class="media border p-3">
<img src="img_avatar3.png" alt="John Doe" class="mr-3 mt-3 rounded-
circle" style="width:60px;">
<div class="media-body">
<h4>John Doe <small><i>Posted on February 19, 2016</i></small></h4>
<p>Lorem ipsum...</p>
<div class="media p-3">
<img src="img_avatar2.png" alt="Jane Doe" class="mr-3 mt-3 rounded-
circle" style="width:45px;">
<div class="media-body">
<h4>Jane Doe <small><i>Posted on February 20
2016</i></small></h4>
<p>Lorem ipsum...</p>
</div>
</div>
</div>
</div>
Try it Yourself »
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
To right-align the media image, add the image after the .media-body container:
Example
<div class="media border p-3">
<div class="media-body">
<h4>John Doe <small><i>Posted on February 19, 2016</i></small></h4>
<p>Lorem ipsum...</p>
</div>
<img src="img_avatar3.png" alt="John Doe" class="ml-3 mt-3 rounded-
circle" style="width:60px;">
</div>
Try it Yourself »
Top, Middle or Bottom Alignment
Use the flex utilities, align-self-* classes to place the media object on the top,
middle or at the bottom:
Media Top
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Media Middle
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Media Bottom
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Example
<!-- Media top -->
<div class="media">
<img src="img_avatar1.png" class="align-self-start mr-
3" style="width:60px">
<div class="media-body">
<h4>Media Top</h4>
<p>Lorem ipsum...</p>
</div>
</div>
Bootstrap 4 Filters
Bootstrap does not have a component that allows filtering. However, we can
use jQuery to filter / search for elements.
Filter Tables
Perform a case-insensitive search for items in a table:
Example
Type something in the input field to search the table for first names, last names
or emails:
jQuery
<script>
$(document).ready(function(){
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myTable tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
Try it Yourself »
Example explained: We use jQuery to loop through each table rows to check if
there are any text values that matches the value of the input field.
The toggle method hides the row (display:none) that does not match the search.
We use the toLowerCase() method to convert the text to lower case, which makes
the search case insensitive (allows "john", "John", and even "JOHN" on search).
Filter Lists
Perform a case-insensitive search for items in a list:
Example
Type something in the input field to search the list for items:
First item
Second item
Third item
Fourth
Try it Yourself »
Filter Anything
Perform a case-insensitive search for text inside a div element:
Example
I am a paragraph.
Another paragraph
Bootstrap 4 Grid System
❮ PreviousNext ❯
If you do not want to use all 12 column individually, you can group the columns
together to create wider columns:
span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1 span 1
span 4 span 8
span 6 span 6
span 12
Grid Classes
The Bootstrap 4 grid system has five classes:
The classes above can be combined to create more dynamic and flexible
layouts.
Tip: Each class scales up, so if you wish to set the same widths for sm and md,
you only need to specify sm.
If you require IE8-9 support, use Bootstrap 3. It is the most stable version
of Bootstrap, and it is still supported by the team for critical bugfixes and
documentation changes. However, no new features will be added to it.
ADVERTISEMENT
<!-- Control the column width, and how they should appear on different
devices -->
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<div class="col-*-*"></div>
</div>
Try it Yourself »
First example: create a row (<div class="row">). Then, add the desired number of
columns (tags with appropriate .col-*-* classes). The first star (*) represents
the responsiveness: sm, md, lg or xl, while the second star represents a
number, which should always add up to 12 for each row.
Extra small Small (>=576px) Medium (>=768px) Large (>=992px) Extra Large
(<576px) (>=1200px)
Grid Horizontal at all Collapsed to start, Collapsed to start, Collapsed to start, Collapsed to start,
behaviour times horizontal above horizontal above horizontal above horizontal above
breakpoints breakpoints breakpoints breakpoints
Suitable for Portrait phones Landscape phones Tablets Laptops Laptops and
Desktops
# of 12 12 12 12 12
columns
Gutter 30px (15px on 30px (15px on each 30px (15px on each 30px (15px on each 30px (15px on each
width each side of a side of a column) side of a column) side of a column) side of a column)
column)
Examples
The next chapters shows examples of grid systems for different devices and
screen widths:
Stacked-to-horizontal
Auto Layout
Small devices
Medium devices
Large devices
Extra large devices
More grid examples
Bootstrap 4 Grid Stacked-to-
horizontal
❮ PreviousNext ❯
col-sm-6
col-sm-6
Example: Stacked-to-horizontal
<div class="container">
<div class="row">
<div class="col-sm-6 bg-success">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-6 bg-warning">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Try it Yourself »
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
Try it Yourself »
<!-- Two columns: 50% width on all screens, except for extra small (100%
width) -->
<div class="row">
<div class="col-sm">1 of 2</div>
<div class="col-sm">2 of 2</div>
</div>
<!-- Four columns: 25% width on all screens, except for extra small (100%
width)-->
<div class="row">
<div class="col-sm">1 of 4</div>
<div class="col-sm">2 of 4</div>
<div class="col-sm">3 of 4</div>
<div class="col-sm">4 of 4</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
Try it Yourself »
Bootstrap 4 Grid Small
❮ PreviousNext ❯
Assume we have a simple layout with two columns. We want the columns to be
split 25%/75% for small devices.
Small devices are defined as having a screen width from 576 pixels to 767
pixels.
<div class="col-sm-3">....</div>
<div class="col-sm-9">....</div>
Now Bootstrap is going to say "at the small size, look for classes with -sm- in
them and use those".
The following example will result in a 25%/75% split on small (and medium,
large and xlarge) devices. On extra small devices, it will automatically stack
(100%):
.col-sm-3
.col-sm-9
Example
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 bg-success">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 bg-warning">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Try it Yourself »
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
.col-sm-4
.col-sm-8
.col-sm-6
.col-sm-6
Example
<!-- 33.3/66.6% split: -->
<div class="container-fluid">
<div class="row">
<div class="col-sm-4 bg-success">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-8 bg-warning">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Try it Yourself »
If the screen size is less than 576px, the columns will stack horizontally:
<!-- Two columns: 50% width on all screens, except for extra small (100%
width) -->
<div class="row">
<div class="col-sm">1 of 2</div>
<div class="col-sm">2 of 2</div>
</div>
<!-- Four columns: 25% width on all screens, except for extra small (100%
width)-->
<div class="row">
<div class="col-sm">1 of 4</div>
<div class="col-sm">2 of 4</div>
<div class="col-sm">3 of 4</div>
<div class="col-sm">4 of 4</div>
</div>
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
Try it Yourself »
In the previous chapter, we presented a grid example with classes for small and
medium devices. We used two divs (columns) and we gave them a 25%/75%
split on small devices, and a 50%/50% split on medium devices:
<div class="col-sm-3 col-md-6">....</div>
<div class="col-sm-9 col-md-6">....</div>
Large devices are defined as having a screen width from 992 pixels to 1199
pixels.
<div class="col-sm-3 col-md-6 col-lg-4">....</div>
<div class="col-sm-9 col-md-6 col-lg-8">....</div>
Now Bootstrap is going to say "at the small size, look at classes with -sm- in
them and use those. At the medium size, look at classes with -md- in them and
use those. At the large size, look at classes with the word -lg- in them and use
those".
Example
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Try it Yourself »
Note: Make sure that the sum adds up to 12 or fewer (it is not required that
you use all 12 available columns):
Using Only Large
In the example below, we only specify the .col-lg-6 class (without .col-md-
* and/or .col-sm-*). This means that large and xlarge devices will split
50%/50%. However, for medium, small AND extra small devices, it will stack
vertically (100% width):
Example
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<p>Lorem ipsum...</p>
</div>
<div class="col-lg-6">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Try it Yourself »
If the screen size is less than 992px, the columns will stack horizontally:
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
col
col
col
Example
<div class="row">
<div class="col">col</div>
<div class="col">col</div>
<div class="col">col</div>
</div>
Try it Yourself »
col-4
col-4
col-4
Example
<div class="row">
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
<div class="col-4">col-4</div>
</div>
Try it Yourself »
col-3
col-6
col-3
Example
<div class="row">
<div class="col-3">col-3</div>
<div class="col-6">col-6</div>
<div class="col-3">col-3</div>
</div>
Try it Yourself »
ADVERTISEMENT
col
col-6
col
Example
<div class="row">
<div class="col">col</div>
<div class="col-6">col-6</div>
<div class="col">col</div>
</div>
Try it Yourself »
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
1 of 6
2 of 6
3 of 6
4 of 6
5 of 6
6 of 6
Example
<!-- Two equal columns -->
<div class="row">
<div class="col">1 of 2</div>
<div class="col">2 of 2</div>
</div>
Try it Yourself »
Row Cols
You can also control how many columns that should appear next to each other
(regardless of how many cols), with the .row-cols-* classes:
1 of 2
2 of 2
1 of 4
2 of 4
3 of 4
4 of 4
1 of 6
2 of 6
3 of 6
4 of 6
5 of 6
6 of 6
Example
<div class="row row-cols-1">
<div class="col">1 of 2</div>
<div class="col">2 of 2</div>
</div>
<div class="row row-cols-2">
<div class="col">1 of 4</div>
<div class="col">2 of 4</div>
<div class="col">3 of 4</div>
<div class="col">4 of 4</div>
</div>
<div class="row row-cols-3">
<div class="col">1 of 6</div>
<div class="col">2 of 6</div>
<div class="col">3 of 6</div>
<div class="col">4 of 6</div>
<div class="col">5 of 6</div>
<div class="col">6 of 6</div>
</div>
Try it Yourself »
1 of 4
2 of 4
3 of 4
4 of 4
1 of 4
2 of 4
3 of 4
4 of 4
Example
<!-- Two Unequal Columns -->
<div class="row">
<div class="col-8">1 of 2</div>
<div class="col-4">2 of 2</div>
</div>
Try it Yourself »
Equal Height
If one of the column is taller than the other (due to text or CSS height), the rest
will follow:
Lorem ipsum dolor sit amet, cibo sensibus interesset no sit. Et dolor possim
volutpat qui. No malis tollit iriure eam, et vel tale zril blandit, rebum vidisse
nostrum qui eu. No nostrud dolorem legendos mea, ea eum mucius oporteat
platonem.Eam an case scribentur, ei clita causae cum, alia debet eu vel.
col
col
Example
<div class="row">
<div class="col">Lorem ipsum...</div>
<div class="col">col</div>
<div class="col">col</div>
</div>
Try it Yourself »
Nested Columns
col-8
col-6
col-6
col-4
The following example shows how to create a two column layout, with another
two columns inside one of the columns:
Example
<div class="row">
<div class="col-8">
.col-8
<div class="row">
<div class="col-6">.col-6</div>
<div class="col-6">.col-6</div>
</div>
</div>
<div class="col-4">.col-4</div>
</div>
Try it Yourself »
Responsive Classes
The Bootstrap 4 grid system has five classes:
The classes above can be combined to create more dynamic and flexible
layouts.
Tip: Each class scales up, so if you wish to set the same widths for sm and md,
you only need to specify sm.
Stacked to Horizontal
col-sm-9
col-sm-3
col-sm
col-sm
col-sm
The following example shows how to create a column layout that starts out
stacked on extra small devices, before becoming horizontal on larger devices
(sm, md, lg and xl):
Example
<div class="row">
<div class="col-sm-9">col-sm-9</div>
<div class="col-sm-3">col-sm-3</div>
</div>
<div class="row">
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
<div class="col-sm">col-sm</div>
</div>
Try it Yourself »
col-6 col-sm-3
col-7 col-lg-8
col-5 col-lg-4
col-sm-3 col-md-6 col-lg-4
Example
<!-- 50%/50% split on extra small devices and 75%/25% split on larger
devices -->
<div class="row">
<div class="col-6 col-sm-9">col-6 col-sm-9</div>
<div class="col-6 col-sm-3">col-6 col-sm-3</div>
</div>
<!-- 58%/42% split on extra small, small and medium devices and
66.3%/33.3% split on large and xlarge devices -->
<div class="row">
<div class="col-7 col-lg-8">col-7 col-lg-8</div>
<div class="col-5 col-lg-4">col-5 col-lg-4</div>
</div>
Try it Yourself »
No Gutters
Add the .no-gutters class to the .row container to remove gutters (extra space):
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat.
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt explicabo.
Example
<div class="row no-gutters">
Bootstrap 4 Templates
❮ PreviousNext ❯
You are free to modify, save, share, and use it in your projects:
Bootstrap 4 Class Reference
❮ PreviousNext ❯
.active Adds a white text color to the active link in a navbar. Try it Navbar
.active Adds a blue background color to the active list item in a list Try it List Groups
Class Description Example Category
group
.active Adds a blue background color to the active dropdown item in Try it Dropdowns
a dropdown
.active Adds a blue background color to the active pagination link (to Try it Pagination
highlight the current page)
.alert-info Teal alert. Indicates a neutral informative change or action Try it Alerts
.alert-link Used on links inside alerts to provide matching colored links Try it Alerts
.alert- Yellow alert. Indicates caution should be taken with this Try it Alerts
warning action
.align- The element is aligned with the baseline of the parent. This is Try it Utilities
baseline default
Class Description Example Category
.align- The element is aligned with the lowest element on the line Try it Utilities
bottom
.align- The element is placed in the middle of the parent element Try it Utilities
middle
.align-top The element is aligned with the top of the tallest element on Try it Utilities
the line
.align-text- The element is aligned with the top of the parent element's Try it Utilities
top font
.align-text- The element is aligned with the bottom of the parent Try it Utilities
bottom element's font
.align- Align gathered items in the center on different screens Try it Flex
content-*-
center
.align- Align gathered items at the end on different screens Try it Flex
content-*-
end
.align- Align gathered items from the start on different screens Try it Flex
content-*-
start
.align- Align single rows of items from the start Try it Flex
items-start
.align- Align single rows of items from the start on different screens Try it Flex
items-*-
start
.align- Align single rows of items at the end on different screens Try it Flex
items-*-end
.align- Align single rows of items in the center on different screens Try it Flex
items-*-
center
baseline
.align- Align single rows of items at the baseline on different screens Try it Flex
items-*-
baseline
.align-self- Align a flex item from the start on different screens Try it Flex
*-start
.align-self- Align a flex item at the end on different screens Try it Flex
*-end
Class Description Example Category
.align-self- Align a flex item in the center on different screens Try it Flex
*-center
.align-self- Align a flex item at the baseline on different screens Try it Flex
*-baseline
.badge Creates a circular badge (grey circle - often used as a Try it Badges
numerical indicator)
.badge-info Teal badge. Indicates a neutral informative change or action Try it Badges
.badge- Yellow badge. Indicates caution should be taken with this Try it Badges
warning action
.blockquote Styles quoted blocks of content from another source (adds a Try it Typography
larger font-size (1.25rem))
Class Description Example Category
.blockquote- Styles the source title inside the blockquote (light grey text Try it Typography
footer with indentation)
.breadcrumb A pagination. Indicates the current page's location within a Try it Pagination
navigational hierarchy
.breadcrumb- Styles list items or links inside the breadcrumb Try it Pagination
Class Description Example Category
item
.btn Creates a basic button (gray background and rounded Try it Buttons
corners)
.btn-block Creates a block level button that spans the entire width of Try it Buttons
the parent element
.btn-group- Large button group (makes all buttons in a button group Try it Button
lg larger - increased font-size and padding) Groups
.btn-group- Small button group (makes all buttons in a button group Try it Button
sm smaller) Groups
.btn-link Makes a button look like a link (get button behavior) Try it Buttons
outline-
primary
.btn-toolbar Combine sets of button groups into button toolbars for more Try it Button
complex components Groups
.card-danger Adds a red background color to the card. Represents danger Try it Cards
or a negative action
.card-deck Container to create a grid of cards that are of equal height Try it Cards
and width
.card-group Container to create a grid of cards that are of equal height Try it Cards
and width, without side margins
.card- Styles navigation tabs inside the card header Try it Cards
header-tabs
.card- Styles navigation pills inside the card header Try it Cards
header-pills
.card-img- Place the image at the bottom inside a card Try it Cards
bottom
.card-img- Turns an image into a card background. Often used to add Try it Cards
overlay text on top of the image
.card-img- Place the image at the top inside a card Try it Cards
top
.card-info Adds a teal background color to the card. Represents some Try it Cards
information
.card-light Adds a light grey background color to the card Try it Cards
Class Description Example Category
.card-link Adds a blue color to any link and a hover effect inside the Try it Cards
card
.card- Adds a blue background color to the card. Represents Try it Cards
primary something important
.card- Adds a grey background color to the card. Represents Try it Cards
secondary something "less" important
.card- Adds a green background color to the card. Indicates success Try it Cards
success or a positive action
.card-text Used to remove bottom margins for a p element if it is the Try it Cards
last child (or the only one), inside .card-body
.card-title Adds a title to any heading element inside the card Try it Cards
.carousel- Creates a caption text for each slide in the carousel Try it Carousel
caption
.carousel- Adds little dots/indicators at the bottom of each slide (which Try it Carousel
indicators indicates how many slides there is in the carousel, and which
slide the user are currently viewing)
Class Description Example Category
.close Styles a close icon. This is often used for alerts and modals. Try it Utilities
Often used together with the × symbol to create the
actual icon (a better looking "x"). It floats right by default
.col-auto Make form columns automatically size themselves based on Try it Forms
their content
.col-* Creates a column layout for extra small devices (and up/all Try it Grid System
devices, if not combined with other column classes).
The * can be a number between 1 and 12
.col-sm-* Creates a column layout for small devices (and up, if not Try it Grid System
combined with other column classes). The * can be a number
between 1 and 12
.col-md-* Creates a column layout for medium devices (and up, if not Try it Grid System
combined with other column classes). The * can be a number
Class Description Example Category
between 1 and 12
.col-lg-* Creates a column layout for large devices (and up, if not Try it Grid System
combined with other column classes). The * can be a number
between 1 and 12
.col-xl-* Creates a column layout for extra large devices. The * can be Try it Grid System
a number between 1 and 12
.collapse Indicates collapsible content - which can be hidden or shown Try it Collapse
on demand
.container Fixed width container with widths determined by screen Try it Containers
sites. Equal margin on the left and right.
.container- A container that spans the full width of the screen Try it Containers
fluid
checkbox
.custom- Inline (horizontally - side by side) customized form controls Try it Custom Forms
control-
inline
.custom- Customized label, when used together with a custom form Try it Custom Forms
control- control
label
.disabled Disables a dropdown item (adds a grey text color and a "no- Try it Dropdowns
parking-sign" icon on hover)
Class Description Example Category
.disabled Disables a list item in a list group (cannot be clicked - adds a Try it List Groups
light grey color and removes the hover effect on list item
links)
.dropdown Creates a toggleable menu that allows the user to choose one Try it Dropdowns
value from a predefined list
.dropdown- Used to separate links in the dropdown menu with a thin Try it Dropdowns
divider horizontal border
.dropdown- Used to add headers inside the dropdown menu Try it Dropdowns
header
.dropdown- Creates a dropdown item (added to links or buttons inside Try it Dropdowns
item .dropdown-menu)
.dropdown- Used to add plain text to a dropdown item, or used on links Try it Dropdowns
item-text for default link styling
.dropdown- Adds the default styles for the dropdown menu container Try it Dropdowns
menu
Class Description Example Category
.dropdown- Used on the button that should hide and show (toggle) the Try it Dropdowns
toggle dropdown menu
.d-*-inline- Makes an element inline block on a specific screen size Try it Utilities
block
.d-flex Creates a flexbox container and transforms direct children Try it Flex
into flex items
.d-*-inline- Creates an inline flexbox container on a specific screen size Try it Flex
flex
.d-*-table Makes an element display as a table on a specific screen size Try it Utilities
.d-*-table- Makes an element display as a table cell on a specific screen Try it Utilities
cell size
.d-*-table- Makes an element display as a table row on a specific screen Try it Utilities
row size
.embed- Container for embedded content. Creates an 16:9 aspect Try it Images
responsive- ratio embedded content
16by9
.embed- Container for embedded content. Creates an 3:4 aspect ratio Try it Images
responsive- embedded content
3by4
Class Description Example Category
.fade Adds a fading effect when closing an alert box Try it Alerts
.fade Adds a fading effect when showing tab/pill content Try it Navs
.fixed- Makes an element stay at the bottom of the screen Try it Utilities
bottom (sticky/fixed)
.fixed-top Makes an element stay at the top of the screen (sticky/fixed) Try it Utilities
.flex-*- Display flex items vertically on different screen sizes: Try it Flex
column
.flex-*- Display flex items vertically, reversed, on different screen Try it Flex
column- sizes
reverse
.flex-fill Used on flex items to force it/them into equal width columns Try it Flex
.flex-*-fill Force flex items into equal widths on different screens Try it Flex
.flex-grow- Used on a single flex item to take up the rest of the available Try it Flex
0|1 space
.flex-*-row Display flex items horizontally on a specific screen size Try it Flex
Class Description Example Category
.flex-*-row- Display flex items right-aligned and horizontally on a specific Try it Flex
reverse screen size
.flex-*- Wrap flex items, in reversed order on different screens Try it Flex
wrap-reverse
.form-check- Makes checkboxes appear on the same line (horizontally) Try it Forms
inline
.form-check- Ensures proper margins for labels used together with Try it Forms
label checkboxes
.form- Used on input, textarea, and select elements to span the Try it Forms
control entire width of the page and make them responsive
.form-inline Makes a <form> left-aligned with inline-block controls (This Try it Forms
only applies to forms within viewports that are at least 768px
wide)
.form-row Container for responsive columns (less left and right margins Try it Forms
than .row/overrides default column gutters)
.h1 - .h6 Makes an element look like a heading of the chosen class (h1- Try it Typography
h6)
.img- Shapes an image to a thumbnail (thin light grey borders) Try it Images
thumbnail
.input-group Container to enhance an input by adding an icon, text or a Try it Input Group
button in front or behind the input field as a "help text"
.input- Input group container for adding help text behind an input Try it Input Group
group-append field
.input- Input group container for adding help text in front of an input Try it Input Group
group- field
prepend
.input- Styles the specified help text in an input group Try it Input Group
group-text
.invalid- Creates a custom validation message used in validated forms Try it Forms
feedback (red text color)
.invalid- Creates a custom validation message used in validated forms Try it Forms
tooltip (red tooltip)
.is-invalid Validates a form element (adds a red border to input fields). Try it Forms
Class Description Example Category
.is-valid Validates a form element (adds a green border to input Try it Forms
fields). Note: for server side
.jumbotron Creates a padded grey heading/box with rounded corners Try it Jumbotron
that enlarges the font sizes of the text inside it. Used for
calling extra attention to some special content or information
.justify- Aligns flex items "around" on different screen sizes Try it Flex
content-*-
around
.justify- Aligns flex items in "between" on different screen sizes Try it Flex
content-*-
between
Class Description Example Category
.justify- Aligns flex items in the center on different screen sizes Try it Flex
content-*-
center
.justify- Aligns flex items at the end on different screen sizes Try it Flex
content-*-
end
.justify- Aligns flex items from the start on different screen sizes Try it Flex
content-*-
start
.lead Increase the font size and line height of a paragraph Try it Typography
.list-group- Removes some borders and rounded corners from list items Try it List Group
flush in a list group
.list-group- Display list items horizontally instead of vertically (side-by- Try it List Group
horizontal side instead of on top of each other)
.list-group- Display list items horizontally instead of vertically on different Try it List Group
horizontal-* screen sizes
Class Description Example Category
.list-group- Added to links inside the list group to make them stand out Try it List Group
item-action on hover (darker background)
.list-group- Red background color for a list item in a list group Try it List Group
item-danger
.list-group- Dark grey background color for a list item in a list group Try it List Group
item-dark
.list-group- Light-blue background color for a list item in a list group Try it List Group
item-info
.list-group- Light grey background color for a list item in a list group Try it List Group
item-light
.list-group- Blue background color for a list item in a list group Try it List Group
item-primary
.list-group- Green background color for a list item in a list group Try it List Group
item-success
Class Description Example Category
.list-group- Yellow background color for a list item in a list group Try it List Group
item-warning
.list-inline Places all list items on a single line (used together Try it Typography
with .list-inline-item on each <li> elements)
.list- Places all list items on a single line (used together Try it Typography
inline-item with .list-inline on the parent <ul> element)
.list- Removes all default list-style (bullets, left margin, etc.) styling Try it Typography
unstyled from a <ul> or <ol> list
.media Aligns media objects together with content (like images or Try it Media Objects
videos - often used for comments in a blog post etc)
.modal Identifies the content as a modal and brings focus to it Try it Modals
.modal-body Defines the style for the body of the modal. Add any HTML Try it Modals
markup here (p, img, etc)
Class Description Example Category
.modal- Styles the modal (border, background-color, etc). Inside this, Try it Modals
content add the modal's header, body and footer, if needed
.modal- Centers the modal vertically and horizontally within the page Try it Modals
dialog-
centered
.modal- The footer of the modal (often contains an action button and Try it Modals
footer a close button)
.modal- The header of the modal (often contains a title and a close Try it Modals
header button)
.m-# / m-*-# Responsive margin classes. * can be sm, md, lg or xl. # can be Try it Utilities
Class Description Example Category
.mt-# / mt- Responsive top margin classes. * can be sm, md, lg or xl. # Try it Utilities
*-# can be a number between 0 and 5
.mb-# / mb- Responsive bottom margin classes. * can be sm, md, lg or xl. Try it Utilities
*-# # can be a number between 0 and 5
.ml-# / ml- Responsive left margin classes. * can be sm, md, lg or xl. # Try it Utilities
*-# can be a number between 0 and 5
.mr-# / mr- Responsive right margin classes. * can be sm, md, lg or xl. # Try it Utilities
*-# can be a number between 0 and 5
.mx-# / mx- Responsive left and right margin auto (horizontal) classes. * Try it Utilities
*-# can be sm, md, lg or xl. # can be a number between 0 and 5
.my-# / my- Responsive top and bottom margin auto (vertical) classes. * Try it Utilities
*-# can be sm, md, lg or xl. # can be a number between 0 and 5
.navbar-nav Container for navigation links inside the .navbar container Try it Navbar
.navbar- Added to a link or a header element inside the navbar to Try it Navbar
brand represent a logo or a header
.navbar- Collapses the navbar (hidden and replaced with a Try it Navbar
collapse menu/hamburger icon on mobile phones and small tablets)
.navbar- Responsive collapsible class - stacks the navbar vertically on Try it Navbar
expand-* small (sm), medium (md), large (lg) or extra large (xl) screens
.navbar-dark Adds a white text color to all links in the navbar Try it Navbar
Class Description Example Category
.navbar- Adds a black text color to all links in the navbar Try it Navbar
light
.navbar-text Vertically align any elements inside the navbar that are not Try it Navbar
links (ensures proper padding)
.navbar- Styles the button that should open the navbar on small Try it Navbar
toggler screens. Automatically styled as a hamburger/three bars
.nav-item Used to style list items inside the navbar Try it Navbar
.pagination Creates a pagination (Useful when you have a web site with Try it Pagination
lots of pages
.pagination- Large pagination (each pagination link gets a bigger font-size Try it Pagination
lg and more padding)
.pagination- Small pagination (each pagination link gets a smaller font size Try it Pagination
sm and less padding)
.progress- Animates the progress bar (used together with stripes) Try it Progress Bars
bar-animated
.p-# / p-*-# Responsive padding classes. * can be sm, md, lg or xl. # can Try it Utilities
Class Description Example Category
.pt-# / pt- Responsive top padding classes. * can be sm, md, lg or xl. # Try it Utilities
*-# can be a number between 0 and 5
.pb-# / pb- Responsive bottom padding classes. * can be sm, md, lg or xl. Try it Utilities
*-# # can be a number between 0 and 5
.pl-# / pl- Responsive left padding classes. * can be sm, md, lg or xl. # Try it Utilities
*-# can be a number between 0 and 5
.pr-# / pr- Responsive right padding classes. * can be sm, md, lg or xl. # Try it Utilities
*-# can be a number between 0 and 5
.py-# / py- Responsive top and bottom padding classes. * can be sm, md, Try it Utilities
*-# lg or xl. # can be a number between 0 and 5
.px-# / px- Responsive left and right padding classes. * can be sm, md, lg Try it Utilities
*-# or xl. # can be a number between 0 and 5
.rounded- Shapes an element to a circle (not supported in IE8 and Try it Utilities
circle earlier)
.row-cols-* Set the number of columns that should appear next to each Try it Grid System
other
.sr-only Hides an element on all devices except for screen readers Try it Utilities
Class Description Example Category
.sr-only- Hides an element on all devices except for screen readers Try it Utilities
focusable
.sticky-top Makes an element stay sticky/fixed at the top of the page Try it Utilities
when you scroll past it
.stretched- Added to a link to make its containing block (parent) clickable Try it Utilities
link (works only for parent elements with position:relative)
.table Adds basic styling to a table (padding, bottom borders, etc) Try it Tables
.table- Adds borders on all sides of the table and cells Try it Tables
bordered
borderless
.table- Makes a table more compact by cutting cell padding in half Try it Tables
condensed
.table-dark Adds a black background with white text to the table Try it Tables
.table-hover Creates a hoverable table (adds a grey background color on Try it Tables
table rows on hover)
.table- Makes a table responsive (adds a horizontal scrollbar when Try it Tables
responsive-* needed). By default, the scrollbar is added to the table on
screens that are less than 992px wide (if needed). There's no
difference when viewing anything lager than 992px wide.
However, you can use sm|md|lg|xl to decide WHEN the
table should get a scrollbar, depending on the screen width
.text-hide Hides text (helps replace an element's text content with a Try it Typography
background image)
.text- Grey text color. Indicates something "less" important Try it Colors
secondary
.text-reset Resets the color of a text or a link (inherits the color from its Try it Typography
parent)
.toast Creates a toast (alert box that disappears after a few Try it Toast
seconds)
.valid- Creates a custom validation message used in validated forms Try it Forms
feedback (green text color)
.valid- Creates a custom validation message used in validated forms Try it Forms
tooltip (green tooltip)
.alert- Yellow alert. Indicates caution should be taken with this Try it
warning action
.close Styles the close button for the alert message (floats Try it
right with a specified font-size, color, etc.)
Close Alerts Via data-* Attributes
Add data-dismiss="alert" to a link or a button element to close the alert message.
Example
<a href="#" class="close" data-dismiss="alert">×</a>
Try it Yourself »
Example
$('.close').alert("close");
Try it Yourself »
Alert Options
None
Alert Methods
The following table lists all available alert methods.
Alert Events
The following table lists all available alert events.
closed.bs.alert Occurs when the alert message has been closed (will wait for CSS transitions to Try it
complete)
The classes below can be used to style any <a>, <button>, or <input> element:
Class Description Example
.btn-block Makes a block-level button (spans the full width of the Try it
parent element)
.btn-link Makes a button look like a link (will still have button Try it
behavior)
.btn- Creates an outlined/bordered button. Use any of the Try it
outline-* contextual classes as * (btn-outline-primary, btn-outline-
success, etc)
.btn- Provides extra visual weight and identifies the primary Try it
primary action in a set of buttons
.btn- Combine sets of button groups into button toolbars for Try it
toolbar more complex components
$('.btn').button();
Button Options
None
Button Methods
The following table lists all available button methods.
Note: Methods can also be passed via data attributes; append the method name to data-, as in
data-toggle or data-dispose.
Class Description
Try it Yourself »
Example
<!-- Carousel -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
Try it Yourself »
Via JavaScript
Enable manually with:
Example
// Activate Carousel
$("#myCarousel").carousel();
Try it Yourself »
Carousel Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option
name to data-, as in data-interval="".
Using
keyboard boolean true Specifies whether the carousel should JSUsing
react to keyboard events: data
pause string, or "hover" Pauses the carousel from going through Using
the the next slide when the mouse pointer JSUsing
boolean enters the carousel, and resumes the data
false sliding when the mouse pointer leaves
the carousel
Carousel Methods
The following table lists all available carousel methods.
Method Description Try it
.carousel("cycle") Goes through the carousel items from left to right Try it
. Destroys a carousel
carousel("dispose")
Carousel Events
The following table lists all available carousel events.
Event Description Try it
slide.bs.carousel Occurs when the carousel is about to slide from one item Try it
to another
slid.bs.carousel Occurs when the carousel has finished sliding from one Try it
item to another
relatedTarget Returns the DOM element that is being slid into place as the Try it
active item
from Returns the index of where the previous item came from, Try it
when moving on to the next one
.collapsing Added when the transition starts, and removed when it Try it
finishes
Example
<button class="btn" data-toggle="collapse" data-
target="#demo">Collapsible</button>
<div id="demo" class="collapse">
Some text..
</div>
Try it Yourself »
Via JavaScript
Enable manually with:
$('.collapse').collapse()
Collapse Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option
name to data-, as in data-parent="".
parent selector false All collapsible elements under the specified parent will be closed Try it
when this collapsible item is shown. (similar to
traditional accordion behavior)
.collapse(options) Activates the collapsible element with an option. See options above for valid
values
Collapse Events
The following table lists all available collapse events.
hidden.bs.collapse Occurs when the collapsible element is fully hidden (after CSS transitions have
completed)
Bootstrap JS Dropdown
❮ PreviousNext ❯
Example
<button type="button" class="dropdown-toggle" data-
toggle="dropdown">Dropdown Example</button>
Try it Yourself »
Via JavaScript
Enable manually with:
Example
$('.dropdown-toggle').dropdown();
Try it Yourself »
Dropdown Options
None
Dropdown Methods
The following table lists all available dropdown methods.
.dropdown("toggle") Toggles the dropdown. If set, it will open the dropdown menu by Try it
default
.dropdown("update") Updates the position of an element's dropdown
Dropdown Events
The following table lists all available dropdown events.
shown.bs.dropdown Occurs when the dropdown is fully shown (after CSS transitions have Try it
completed)
hidden.bs.dropdown Occurs when the dropdown is fully hidden (after CSS transitions have Try it
completed)
Example
$(".dropdown").on("show.bs.dropdown", function(event){
var x = $(event.relatedTarget).text(); // Get the text of the element
alert(x);
});
Bootstrap JS Modal
❮ PreviousNext ❯
Example
<!-- Buttons -->
<button type="button" data-toggle="modal" data-target="#myModal">Open
Modal</button>
Try it Yourself »
Example
$("#myModal").modal()
Try it Yourself »
Modal Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option
name to data-, as in data-backdrop="".
Using
backdrop boolean or true Specifies whether the modal should JSUsing
the string have a dark overlay: data
"static"
Modal Methods
The following table lists all available modal methods.
.modal(options) Activates the content as a modal. See options above for Try it
valid values
Modal Events
The following table lists all available modal events.
shown.bs.modal Occurs when the modal is fully shown (after CSS Try it
transitions have completed)
Bootstrap JS Popover
❮ PreviousNext ❯
JS Popover
The Popover component is similar to tooltips; it is a pop-up box that appears when the user clicks on
an element. The difference is that the popover can contain much more content.
The data-content attribute specifies the text that should be displayed inside the popover's body.
Example
<a href="#" data-toggle="popover" title="Popover Header" data-
content="Some content inside the popover">Toggle popover</a>
Try it Yourself »
Via JavaScript
Popovers are not CSS-only plugins, and must therefore be initialized with jQuery: select the specified
element and call the popover() method.
Example
// Select all elements with data-toggle="popover" in the document
$('[data-toggle="popover"]').popover();
Try it Yourself »
Popover Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option
name to data-, as in data-placement="".
content string "" Specifies the text inside the popover's body Try it
html boolean false Specifies whether to accept HTML tags in the popover: Try it
placement string "right" Specifies the popover position. Possible values: Try it
title string "" Specifies the header text of the popover Try it
trigger string "click" Specifies how the popover is triggered. Possible values: Try it
fallbackPlacement string or "flip" Specifies which position Popper wil use on fallback
an aray
Popover Methods
The following table lists all available popover methods.
.popover(options) Activates the popover with an option. See options above for valid Try it
values
.popover("disable") Removes the ability to show a popover. The popover can only be
shown if it is re-enabled again
Popover Events
The following table lists all available popover events.
shown.bs.popover Occurs when the popover is fully shown (after CSS transitions have Try it
completed)
hidden.bs.popover Occurs when the popover is fully hidden (after CSS transitions have Try it
completed)
inserted.bs.popover Occurs after the show.bs.popover event when the
popover template has been added to the DOM
Bootstrap JS Scrollspy
❮ PreviousNext ❯
JS Scrollspy
Scrollspy is used to automatically update links in a navigation list based on
scroll position.
Then add the data-target attribute with a value of the id or the class name of the
navigation bar (.navbar). This is to make sure that the navbar is connected with
the scrollable area.
Note that scrollable elements must match the ID of the links inside the navbar's
list items (<div id="section1"> matches <a href="#section1">).
Example
<!-- The scrollable area -->
<body data-spy="scroll" data-target=".navbar" data-offset="50">
<!-- The navbar - The <a> elements are used to jump to a section in the
scrollable area -->
<nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#section1">Section 1</a>
</li>
....
</ul>
</nav>
</body>
Try it Yourself »
Via JavaScript
Enable manually with:
Example
$('body').scrollspy({target: ".navbar"})
Try it Yourself »
Scrollspy Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option
name to data-, as in data-offset="".
Scrollspy Methods
The following table lists all available scrollspy methods.
Method Description
.scrollspy("refresh") When adding and removing elements from the scrollspy, this method can be used to
refresh the document
Scrollspy Events
The following table lists all available scrollspy events.
Event Description
activate.bs.scrollspy Occurs when a new item becomes activated by the scrollspy
Bootstrap JS Tab
❮ PreviousNext ❯
Example
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#home">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu1">Menu 1</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#menu2">Menu 2</a>
</li>
</ul>
Try it Yourself »
Via JavaScript
Enable manually with:
Example
// Select all tabs
$('.nav-tabs a').click(function(){
$(this).tab('show');
})
Try it Yourself »
Tab Options
None
Tab Methods
The following table lists all available tab methods.
Tab Events
The following table lists all available tab events.
shown.bs.tab Occurs when the tab is fully shown (after CSS transitions have completed) Try it
hidden.bs.tab Occurs when the tab is fully hidden (after CSS transitions have completed) Try it
Example
$('.nav-tabs a').on('shown.bs.tab', function(event){
var x = $(event.target).text(); // active tab
var y = $(event.relatedTarget).text(); // previous tab
});
Bootstrap JS Toasts
❮ PreviousNext ❯
Try it Yourself »
Toast Options
Options can be passed via data attributes or JavaScript. For data attributes,
append the option name to data-, as in data-animation="".
Try it
animation boolean true Specifies whether to add a CSS fade transition
effect when showing and hiding the toast.
autohide boolean true Specifies whether to hide the toast by default Try it
delay number 500 Specifies the number of milliseconds it will take Try it
to hide the toast once it is shown.
Toast Methods
The following table lists all available toast methods.
Method Description Try it
.toast(options) Activates the toast with an option. See options above for Try it
valid values
Toast Events
The following table lists all available toast events.
shown.bs.toast Occurs when the toast is fully shown (after CSS transitions Try it
have completed)
Bootstrap JS Tooltip
❮ PreviousNext ❯
JS Tooltip
The Tooltip is a small pop-up box that appears when the user moves the mouse
pointer over an element.
The title attribute specifies the text that should be displayed inside the tooltip.
Example
<a href="#" data-toggle="tooltip" title="Hooray!">Hover over me</a>
Try it Yourself »
Via JavaScript
Tooltips are not CSS-only plugins, and must therefore be initialized with jQuery:
select the specified element and call the tooltip() method.
Example
// Select all elements with data-toggle="tooltips" in the document
$('[data-toggle="tooltip"]').tooltip();
Try it Yourself »
Tooltip Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option
name to data-, as in data-placement="".
Try it
animation boolean true Specifies whether to add a CSS
fade transition effect when
showing and hiding the tooltip
Tooltip Methods
The following table lists all available tooltip methods.
.tooltip(options) Activates the tooltip with an option. See options above Try it
for valid values
Tooltip Events
The following table lists all available tooltip events.
shown.bs.tooltip Occurs when the tooltip is fully shown (after CSS Try it
transitions have completed)
hidden.bs.tooltip Occurs when the tooltip is fully hidden (after CSS Try it
transitions have completed)