Bootstrap Tutorial
Bootstrap Tutorial
Get Started
Bootstrap is the most popular HTML, CSS, and JavaScript framework
for developing responsive, mobile-first web sites. Bootstrap is completely
free to download and use!
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
Bootstrap History
Bootstrap was developed by Mark Otto and Jacob Thornton at Twitter,
and released as an open source product in August 2011 on GitHub.
In June 2014 Bootstrap was the No.1 project on GitHub!
Easy to use: Anybody with just basic knowledge of HTML and CSS can
start using Bootstrap
Responsive features: Bootstrap's responsive CSS adjusts to phones,
tablets, and desktops
Mobile-first approach: In Bootstrap 3, mobile-first styles are part of
the core framework
Browser compatibility: Bootstrap is compatible with all modern
browsers (Chrome, Firefox, Internet Explorer, Safari, and Opera)
MaxCDN:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"href="https://maxcdn.bootstrapcdn.co
m/bootstrap/3.3.7/css/bootstrap.min.css">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
</html>
2. Bootstrap 3 is mobile-first
3. Containers
Bootstrap also requires a containing element to wrap site contents.
There are two container classes to choose from:
Note: Containers are not nestable (you cannot put a container inside another
container).
The following example shows the code for a basic Bootstrap page (with a
responsive fixed width container):
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap/3.
3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.m
in.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstra
p.min.js"></script>
</head>
<body>
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body>
</html>
The following example shows the code for a basic Bootstrap page (with a full
width container):
Example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootst
rap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jq
uery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bo
otstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body>
</html>
Bootstrap Grids
Bootstrap Grid System
Bootstrap's grid system allows up to 12 columns across the page. If
you do not want to use all 12 columns individually, you can group the
columns together to create wider columns:
span span span span span span span span span span span span
1 1 1 1 1 1 1 1 1 1 1 1
span 4 span 8
span 6 span 6
span 12
Grid Classes
The Bootstrap grid system has four classes:
xs (for phones)
sm (for tablets)
md (for xdesktops)
lg (for larger desktops)
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 xs and
sm, you only need to specify xs.
Number of 12 12 12 12
columns
Gutter width 30px (15px on 30px (15px on 30px (15px on each 30px (15px on each side
each side of a each side of a side of a column) of a column)
column) column)
The following example shows how to get two various-width columns starting
at tablets and scaling to large desktops:
Example: Stacked-to-horizontal
<div class="container">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-6" style="background-color:yellow;">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-6" style="background-color:pink;">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Tip: The numbers in the .col-sm-* classes indicates how many columns the
div should span (out of 12). So, .col-sm-1 spans 1 column, .col-sm-
4 spans 4 columns, .col-sm-6 spans 6 columns, etc.
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
and large) devices. On extra small devices, it will automatically stack
(100%):
col-sm-3 col-sm-9
Example
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-3" style="background-color:yellow;">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9" style="background-color:pink;">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
col-sm-4 col-sm-8
Example
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-4" style="background-color:yellow;">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-8" style="background-color:pink;">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Example
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-3 col-md-6" style="background-color:yellow;">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6" style="background-color:pink;">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</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".
The following example will result in a 25%/75% split on small devices, a
50%/50% split on medium devices, and a 33%/66% split on large devices:
<div class="container-fluid">
<h1>Hello World!</h1>
<div class="row">
<div class="col-sm-3 col-md-6 col-lg-4" style="background color:yellow;">
<p>Lorem ipsum...</p>
</div>
<div class="col-sm-9 col-md-6 col-lg-8" style="background-color:pink;">
<p>Sed ut perspiciatis...</p>
</div>
</div>
</div>
Example
<div class="row">
<div class="col-sm-8">
.col-sm-8
<div class="row">
<div class="col-sm-6">.col-sm-6</div>
<div class="col-sm-6">.col-sm-6</div>
</div>
</div>
<div class="col-sm-4">.col-sm-4</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-8 col-lg-10">.col-xs-6 .col-sm-8 .col-lg-10</div>
<div class="col-xs-6 col-sm-4 col-lg-2">.col-xs-6 .col-sm-4 .col-lg-2</div>
</div>
Bootstrap Text/Typography
1. <h1> - <h6>
By default, Bootstrap will style the HTML headings (<h1> to <h6>) in the
following way:
2. <small>
In Bootstrap the HTML <small> element is used to create a lighter, secondary text in any
heading:
Example
Example:
<div class="container">
<h1>Highlight Text</h1>
<p>Use the mark element to <mark>highlight</mark>
text.</p>
</div>
4. <abbr>
Bootstrap will style the HTML <abbr> element in the following way:
Example:
<div class="container">
<h1>Abbreviations</h1>
<p>The abbr element is used to mark up an abbreviation or
acronym:</p>
<p>The <abbr title="World Health Organization">WHO</abbr>
was founded in 1948.</p>
</div>
5. <blockquote>
Bootstrap will style the HTML <blockquote> element in the following
way:
Example:
<div class="container">
<h1>Blockquotes</h1>
<p>The blockquote element is used to
present content from another source:</p>
<blockquote>
<p>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.</p>
<footer>From WWF's website</footer>
</blockquote>
</div>
6. <dl>
Bootstrap will style the HTML <dl> element in the following way:
Example:
<div class="container">
<h1>Description Lists</h1>
<p>The dl element indicates a description list:</p>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
</div>
7. <code>
Bootstrap will style the HTML <code> element in the following way:
Example:
<div class="container">
<h1>Code Snippets</h1>
<p>Inline snippets of code should be embedded in the code element:</p>
<p>The following HTML elements:
<code>span</code>, <code>section</code>,
and <code>div</code> defines a section in a document.</p>
</div>
8. <kbd>
Bootstrap will style the HTML <kbd> element in the following way:
Example:
<div class="container">
<h1>Keyboard Inputs</h1>
<p>To indicate input that is typically entered via the keyboard,
use the kbd element:</p>
<p>Use <kbd>ctrl + p</kbd> to open the Print dialog box.</p>
</div>
9. <pre>
Bootstrap will style the HTML <pre> element in the following way:
Example:
<div class="container">
<h1>Multiple Code Lines</h1>
<p>For multiple lines of code, use the pre element:</p>
<pre>
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both spaces and
line breaks.
</pre>
</div>
10. Contextual Colors and Backgrounds
Bootstrap also has some contextual classes that can be used to provide
"meaning through colors".
The classes for text colors are:.text-muted, .text-primary, .text-
success, .text-info, .text-warning, and .text-danger:
Example:
<div class="container">
<h2>Contextual Colors</h2>
<p>Use the contextual classes to provide "meaning through
colors":</p>
<p class="text-muted">This text is muted.</p>
<p class="text-primary">This text is important.</p>
<p class="text-success">This text indicates success.</p>
<p class="text-info">This text represents some information.</p>
<p class="text-warning">This text represents a warning.</p>
<p class="text-danger">This text represents danger.</p>
</div>
Class Description
.lead Makes a paragraph stand out
.small Indicates smaller text (set to 85% of the size of the
parent)
.text-left Indicates left-aligned text
.text-center Indicates center-aligned text
.text-right Indicates right-aligned text
.text-justify Indicates justified text
.text-nowrap Indicates no wrap text
.text-lowercase Indicates lowercased text
.text-uppercase Indicates uppercased text
.text- Indicates capitalized text
capitalize
.initialism Displays the text inside an <abbr> element in a
slightly smaller font size
.list-unstyled Removes the default list-style and left margin on
list 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
.dl-horizontal Lines up the terms (<dt>) and descriptions (<dd>)
in <dl>elements side-by-side. Starts off like
default <dl>s, but when the browser window
expands, it will line up side-by-side
.pre-scrollable Makes a <pre> element scrollable
Bootstrap Tables
Bootstrap Basic Table
A basic Bootstrap table has a light padding and only horizontal
dividers. The .table class adds basic styling to a table:
Example:
<div class="container">
<h2>Basic Table</h2>
<p>The .table class adds basic styling
(light padding and only horizontal dividers) to a table:</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
Striped Rows
The .table-striped class adds zebra-stripes to a table:
Example:
<div class="container">
<h2>Striped Rows</h2>
<p>The .table-striped class adds zebra-stripes to a table:</p>
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
</tbody>
</table>
</div>
Bordered Table
The .table-bordered class adds borders on all sides of the table and cells:
Example:
<div class="container">
<h2>Bordered Table</h2>
<p>The .table-bordered class adds borders to a table:</p>
<table class="table table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
</tbody>
</table>
</div>
Hover Rows
The .table-hover class adds a hover effect (grey background color) on table
rows:
Example:
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state on table rows:</p>
<table class="table table-hover">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
</tbody>
</table>
</div>
Contextual Classes
Contextual classes can be used to color table rows (<tr>) or table cells
(<td>):
Example:
<div class="container">
<h2>Contextual Classes</h2>
<p>Contextual classes can be used to color table rows or table cells. The
classes that can be used are: .active, .success, .info, .warning, and .danger.</p>
<table class="table">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>Default</td>
<td>Defaultson</td>
<td>def@somemail.com</td>
</tr>
<tr class="success">
<td>Success</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr class="danger">
<td>Danger</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr class="info">
<td>Info</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
<tr class="warning">
<td>Warning</td>
<td>Refs</td>
<td>bo@example.com</td>
</tr>
<tr class="active">
<td>Active</td>
<td>Activeson</td>
<td>act@example.com</td>
</tr>
</tbody>
</table>
</div>
Responsive Tables
The .table-responsive class creates a responsive table. The table will then
scroll horizontally on small devices (under 768px). When viewing on anything
larger than 768px wide, there is no difference:
Example:
<div class="container">
<h2>Table</h2>
<p>The .table-responsive class creates a responsive table which will scroll
horizontally on small devices (under 768px). When viewing on anything larger
than 768px wide, there is no difference:</p>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>City</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Anna</td>
<td>Pitt</td>
<td>35</td>
<td>New York</td>
<td>USA</td>
</tr>
</tbody>
</table>
</div>
</div>
Bootstrap Images
Bootstrap Image Shapes
Rounded Corners
The .img-rounded class adds rounded corners to an image (IE8 does not
support rounded corners):
Example:
<div class="container">
<h2>Rounded Corners</h2>
<p>The .img-rounded class adds rounded
corners to an image (not available in IE8):</p>
<img src="cinqueterre.jpg"
class="img-rounded" alt="Cinque Terre" width="304" height="236">
</div>
Circle
The .img-circle class shapes the image to a circle (IE8 does not support
rounded corners):
Example:
<img src="cinqueterre.jpg" class="img-circle" alt="Cinque
Terre" width="304"height="236">
Thumbnail
The .img-thumbnail class shapes the image to a thumbnail:
Example:
<img src="cinqueterre.jpg" class="img-thumbnail" alt="Cinque
Terre" width="304"height="236">
Responsive Images
Images come in all sizes. So do screens. Responsive images automatically
adjust to fit the size of the screen.
Create responsive images by adding an .img-responsive class to
the <img> tag. The image will then scale nicely to the parent element.
The .img-responsive class applies display: block; and max-width:
100%; and height: auto; to the image:
Example:
<img class="img-responsive" src="img_chania.jpg" alt="Chania">
Image Gallery
You can also use Bootstrap's grid system in conjunction with
the .thumbnail class to create an image gallery.
Example:
<div class="row">
<div class="col-md-4">
<div class="thumbnail">
<a href="/w3images/lights.jpg">
<img src="/w3images/lights.jpg" alt="Lights" style="width:100%">
<div class="caption">
<p>Lorem ipsum...</p>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<a href="/w3images/nature.jpg">
<img src="/w3images/nature.jpg" alt="Nature" style="width:100%">
<div class="caption">
<p>Lorem ipsum...</p>
</div>
</a>
</div>
</div>
<div class="col-md-4">
<div class="thumbnail">
<a href="/w3images/fjords.jpg">
<img src="/w3images/fjords.jpg" alt="Fjords" style="width:100%">
<div class="caption">
<p>Lorem ipsum...</p>
</div>
</a>
</div>
</div>
</div>
Bootstrap Jumbotron and
Page Header
Creating a Jumbotron
A jumbotron indicates a big box for calling extra attention to some
special content or information. A jumbotron is displayed as a grey box with
rounded corners. It also enlarges the font sizes of the text inside it.
Tip: Inside a jumbotron you can put nearly any valid HTML, including other
Bootstrap elements/classes. Use a <div> element with class .jumbotron to
create a jumbotron:
Bootstrap Wells
Wells
The .well class adds a rounded border around an element with a gray
background color and some padding:
Example :
<div class="well">Basic Well</div>
<div class="well well-sm">Small Well</div>
<div class="well well-lg">Large Well</div>
Alerts
Bootstrap provides an easy way to create predefined alert messages:
Alerts are created with the .alert class, followed by one of the four
contextual classes .alert-success, .alert-info, .alert-
warning or .alert-danger:
Example :
<div class="alert alert-success">
<strong>Success!</strong> Indicates a successful or positive action.
</div>
Closing Alerts
Click on the "x" symbol to the right to close me.
To close the alert message, add a .alert-dismissable class to the alert
container. Then add class="close" and data-dismiss="alert" to a link or
a button element (when you click on this the alert box will disappear).
Example :
<div class="alert alert-success alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-
label="close">×</a>
<strong>Success!</strong> Indicates a successful or positive
action.
</div>
Animated Alerts
Click on the "x" symbol to the right to close me. I will "fade" out.
The .fade and .in classes adds a fading effect when closing the alert
message:
Example :
<div class="alert alert-danger alert-dismissable fade in">
<a href="#" class="close" data-dismiss="alert"
aria-label="close">×</a>
<strong>Danger!</strong> This alert box could indicate a
dangerous or potentially negative action.
</div >
Buttons
Button Styles
Bootstrap provides different styles of buttons:
To achieve the button styles above, Bootstrap has the following classes:
To achieve the button styles above, Bootstrap has the following classes:
.btn
.btn-default
.btn-primary
.btn-success
.btn-info
.btn-warning
.btn-danger
.btn-link
The following example shows the code for the different button styles:
Example :
<button type="button" class="btn">Basic</button>
<button type="button" class="btn btn-default">Default</button>
<button type="button" class="btn btn-primary">Primary</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-link">Link</button>
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">
Button Sizes
Bootstrap provides four button sizes:
.btn-lg
.btn-md
.btn-sm
.btn-xs
The following example shows the code for different button sizes:
Example :
<button type="button" class="btn btn-primary btn-lg">Large</button>
<button type="button" class="btn btn-primary btn-md">Medium</button>
<button type="button" class="btn btn-primary btn-sm">Small</button>
<button type="button" class="btn btn-primary btn-xs">XSmall</button>
Example :
<button type="button" class="btn btn-primary btn-block">Button 1</button>
Active/Disabled Buttons
A button can be set to an active (appear pressed) or a disabled (unclickable)
state:
Button Groups
Bootstrap allows you to group a series of buttons together (on a single
line) in a button group:
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>
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>
Example :
<div class="btn-group btn-group-justified">
<a href="#" class="btn btn-primary">Apple</a>
<a href="#" class="btn btn-primary">Samsung</a>
<a href="#" class="btn btn-primary">Sony</a>
</div>
Note: For <button> elements, you must wrap each button in a .btn-
group class:
Example :
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary">Samsung</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary">Sony</button>
</div>
</div>
Example :
<div class="btn-group">
<button type="button" class="btn btn-primary">Sony</button>
<button type="button" class="btn btn-primary dropdown-toggle" data-
toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Tablet</a></li>
<li><a href="#">Smartphone</a></li>
</ul>
</div>
Glyphicons
Bootstrap provides 260 glyphicons from the Glyphicons Halflings set.
Glyphicons can be used in text, buttons, toolbars, navigation, forms, etc.
Here are some examples of glyphicons:
Glyphicon Syntax
A glyphicon is inserted with the following syntax:
<span class="glyphicon glyphicon-name"></span>
The name part in the syntax above must be replaced with the proper name
of the glyphicon.
Glyphicon Example
The following example shows different ways to use glyphicons:
Example :
<p>Envelope icon: <span class="glyphicon glyphicon-envelope"></span></p>
<p>Envelope icon as a link:
<a href="#"><span class="glyphicon glyphicon-envelope"></span></a>
</p>
<p>Search icon: <span class="glyphicon glyphicon-search"></span></p>
<p>Search icon on a button:
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span> Search
</button>
</p>
<p>Search icon on a styled button:
<button type="button" class="btn btn-info">
<span class="glyphicon glyphicon-search"></span> Search
</button>
</p>
<p>Print icon: <span class="glyphicon glyphicon-print"></span></p>
<p>Print icon on a styled link button:
<a href="#" class="btn btn-success btn-lg">
<span class="glyphicon glyphicon-print"></span> Print
</a>
</p>
Badges and Labels
Badges are numerical indicators of how many items are associated with
a link:
Labels
Labels are used to provide additional information about something:
Use the .label class, followed by one of the six contextual classes .label-
default, .label-primary, .label-success, .label-info, .label-
warning or .label-danger, within a <span>element to create a label:
Example :
<h1>Example <span class="label label-default">New</span></h1>
<h2>Example <span class="label label-default">New</span></h2>
<h3>Example <span class="label label-default">New</span></h3>
<h4>Example <span class="label label-default">New</span></h4>
<h5>Example <span class="label label-default">New</span></h5>
<h6>Example <span class="label label-default">New</span></h6>
Example :
<span class="label label-default">Default Label</span>
<span class="label label-primary">Primary Label</span>
<span class="label label-success">Success Label</span>
<span class="label label-info">Info Label</span>
<span class="label label-warning">Warning Label</span>
<span class="label label-danger">Danger Label</span>
Progress Bars
Basic Progress Bar
A progress bar can be used to show a user how far along he/she is in a
process. Bootstrap provides several types of progress bars. A default
progress bar in Bootstrap looks like this:
To create a default progress bar, add a .progress class to a <div> element:
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="70"
aria-valuemin="0" aria-valuemax="100" style="width:70%">
<span class="sr-only">70% Complete</span>
</div>
</div>
Note: Progress bars are not supported in Internet Explorer 9 and earlier
(because they use CSS3 transitions and animations to achieve some of their
effects).
Note: To help improve accessibility for people using screen readers, you
should include the aria-* attributes.
70%
Remove the .sr-only class from the progress bar to show a visible
percentage:
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="70"
aria-valuemin="0" aria-valuemax="100" style="width:70%">
70%
</div>
</div>
.progress-bar-success
.progress-bar-info
.progress-bar-warning
.progress-bar-danger
The following example shows how to create progress bars with the different
contextual classes:
Example :
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-
valuenow="40"
aria-valuemin="0" aria-valuemax="100" style="width:40%">
40% Complete (success)
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-info" role="progressbar" aria-
valuenow="50"
aria-valuemin="0" aria-valuemax="100" style="width:50%">
50% Complete (info)
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-warning" role="progressbar" aria-
valuenow="60"
aria-valuemin="0" aria-valuemax="100" style="width:60%">
60% Complete (warning)
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-danger" role="progressbar" aria-
valuenow="70"
aria-valuemin="0" aria-valuemax="100" style="width:70%">
70% Complete (danger)
</div>
</div>
Example :
<div class="progress">
<div class="progress-bar progress-bar-success progress-bar-
striped"role="progressbar"
aria-valuenow="40" aria-valuemin="0" aria-
valuemax="100" style="width:40%">
40% Complete (success)
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-info progress-bar-
striped"role="progressbar"
aria-valuenow="50" aria-valuemin="0" aria-
valuemax="100" style="width:50%">
50% Complete (info)
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-warning progress-bar-
striped"role="progressbar"
aria-valuenow="60" aria-valuemin="0" aria-
valuemax="100" style="width:60%">
60% Complete (warning)
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-danger progress-bar-
striped"role="progressbar"
aria-valuenow="70" aria-valuemin="0" aria-
valuemax="100" style="width:70%">
70% Complete (danger)
</div>
</div>
Create a stacked progress bar by placing multiple bars into the same <div
class="progress">:
Example :
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar"
style="width:40%">
Free Space
</div>
<div class="progress-bar progress-bar-warning" role="progressbar"
style="width:10%">
Warning
</div>
<div class="progress-bar progress-bar-danger" role="progressbar"
style="width:20%">
Danger
</div>
</div>
Pagination
Basic Pagination
If you have a web site with lots of pages, you may wish to add some
sort of pagination to each page. A basic pagination in Bootstrap looks like
this:
Active State
The active state shows what is the current page:
Add class .active to let the user know which page he/she is on:
Example :
<ul class="pagination">
<li><a href="#">1</a></li>
<li class="active"><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
</ul>
Disabled State
A disabled link cannot be clicked:
Breadcrumbs
Another form for pagination, is breadcrumbs:
Pager
What is Pager?
Pager is also a form of pagination (as described in the previous chapter).
Pager provides previous and next buttons (links). To create previous/next
buttons, add the .pager class to an <ul> element:
Example :
<ul class="pager">
<li><a href="#">Previous</a></li>
<li><a href="#">Next</a></li>
</ul>
Align Buttons
Use the .previous and .next classes to align each button to the sides of the
page:
Example :
<ul class="pager">
<li class="previous"><a href="#">Previous</a></li>
<li class="next"><a href="#">Next</a></li>
</ul>
List Groups
Basic List Groups
The most basic list group is an unordered list with list items:
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>
To create a badge, create a <span> element with class .badge inside the list
item:
Example :
<ul class="list-group">
<li class="list-group-item">New <span class="badge">12</span></li>
<li class="list-group-item">Deleted <span class="badge">5</span></li>
<li class="list-group-item">Warnings <span class="badge">3</span></li>
</ul>
Active State
Example :
<div class="list-group">
<a href="#" class="list-group-item active">First item</a>
<a href="#" class="list-group-item">Second item</a>
<a href="#" class="list-group-item">Third item</a>
</div>
Disabled Item
The following list group has a disabled item:
Example :
<div class="list-group">
<a href="#" class="list-group-item disabled">First item</a>
<a href="#" class="list-group-item">Second item</a>
<a href="#" class="list-group-item">Third item</a>
</div>
Contextual Classes
Contextual classes can be used to color list items:
Custom Content
You can add nearly any HTML inside a list group item. Bootstrap provides the
classes .list-group-item-heading and .list-group-item-text which can
be used as follows:
Example :
<div class="list-group">
<a href="#" class="list-group-item active">
<h4 class="list-group-item-heading">First List Group Item Heading</h4>
<p class="list-group-item-text">List Group Item Text</p>
</a>
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading">Second List Group Item
Heading</h4>
<p class="list-group-item-text">List Group Item Text</p>
</a>
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading">Third List Group Item Heading</h4>
<p class="list-group-item-text">List Group Item Text</p>
</a>
</div>
Panels
A panel in bootstrap is a bordered box with some padding around its content:
Panels are created with the .panel class, and content inside the panel has
a .panel-body class:
<div class="panel panel-default">
<div class="panel-body">A Basic Panel</div>
</div>
The .panel-default class is used to style the color of the panel. See the last
example on this page for more contextual classes.
Panel Heading
Example :
<div class="panel panel-default">
<div class="panel-heading">Panel Heading</div>
<div class="panel-body">Panel Content</div>
</div>
Panel Footer
Panel Group
To group many panels together, wrap a <div> with class .panel-
group around them. The .panel-group class clears the bottom-margin of
each panel:
Example :
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-body">Panel Content</div>
</div>
<div class="panel panel-default">
<div class="panel-body">Panel Content</div>
</div>
</div>
Panels with Contextual Classes
To color the panel, use contextual classes (.panel-default, .panel-
primary, .panel-success, .panel-info, .panel-warning, or .panel-
danger):
Dropdown
A dropdown menu is a toggleable menu that allows the user to choose
one value from a predefined list:
Example :
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-
toggle="dropdown">Dropdown Example
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
Example Explained
The .dropdown class indicates a dropdown menu.
To open the dropdown menu, use a button or a link with a class
of .dropdown-toggle and the data-toggle="dropdown" attribute.
The .caret class creates a caret arrow icon (), which indicates that the
button is a dropdown.
Add the .dropdown-menu class to a <ul> element to actually build the
dropdown menu.
Dropdown Divider
The .divider class is used to separate links inside the dropdown menu with
a thin horizontal border:
<li class="divider"></li>
Dropdown Header
The .dropdown-header class is used to add headers inside the dropdown
menu:
Dropup
Dropdown Accessibility
To help improve accessibility for people using screen readers, you should
include the following role and aria-* attributes, when creating a dropdown
menu:
<div class="dropdown">
<button class="btn btn-default dropdown-
toggle" type="button" id="menu1" data-toggle="dropdown">Tutorials
<span class="caret"></span></button>
<ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
<li role="presentation"><a role="menuitem" href="#">HTML</a></li>
<li role="presentation"><a role="menuitem" href="#">CSS</a></li>
<li role="presentation"><a role="menuitem" href="#">JavaScript</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" href="#">About Us</a></li>
</ul>
</div>