Bootstrap Tutorial
Bootstrap Tutorial
Bootstrap Tutorial
Bootstrap is a sleek, intuitive, and powerful front-end framework for faster and easier web
development.
Bootstrap tutorials will help you learn the essentials of Bootstrap, from the fundamentals to
advanced topics, so that you can create web pages with much less effort.
Tutorials are broken down into sections where each section containing a number of related topics
that are packed with easy to understand explanations, practice examples, smart workarounds and
useful tips.
You can save a lot of time and efforts with Bootstrap So bookmark this website and continue on.
If you're completely new to the Bootstrap we recommend you to start with the section that covers Bootstrap Basics and gradually move forward, by
learning a little bit every day.
Tip:Since every chapter in this tutorial is somewhat related to each other. So it's a good idea to make sure that you have understood the each topic
very clearly before moving on to the next chapter or section.
Bootstrap Examples
Every chapter in this tutorial contains practice examples that you can try and test yourself to extend your learning. The purpose of these examples
is to provide you a better understanding of the usage of Bootstrap in your day to day implementation.
Check out the Bootstrap Examples
Bootstrap comes equipped with HTML, CSS, and JavaScript for various web and user interface
components.
What is Bootstrap
Bootstrap is a powerful front-end framework for faster and easier web development. It includes HTML and CSS based design templates for common
user interface components like Typography, Forms, Buttons, Tables, Navigations, Dropdowns, Alerts, Modals, Tabs, Accordion, Carousel and many
other as well as optional JavaScript extensions.
Bootstrap also gives you ability to create responsive layout with much less efforts.
Advantages of Bootstrap
The biggest advantage of using Bootstrap is that it comes with free set of tools for creating flexible and responsive web layouts as well as common
interface components.
Additionally, using the Bootstrap data APIs you can create advanced interface components like Scrollspy and Typeaheads without writing a single line
of JavaScript.
Here are some more advantages, why one should opt for Bootstrap:
Save lots of time You can save lots of time and efforts using the Bootstrap predefined design templates and classes and concentrate
on other developmentwork.
Responsive features Using Bootstrap you can easily create responsive designs. Bootstrap responsive features make your web pages
to appear more appropriately on different devices and screen resolutions without any change in markup.
Consistent design All Bootstrap components share the same design templates and styles through a central library, so that the
designs and layouts of your web pages are consistent throughout your development.
Easy to use Bootstrap is very easy to use. Anybody with the basic working knowledge of HTML and CSS can start development with
Bootstrap.
Compatible with browsers Bootstrap is created with modern browsers in mind and it is compatible with all modern browsers such
as Mozilla Firefox, Google Chrome, Safari, Internet Explorer, and Opera.
Open Source And the best part is, it is completely free to download and use.
Note:Some CSS3 properties such as properties for rounded corners, gradients and shadows are used by the Bootstrap but not supported in older
versions of the web browsers especially Internet Explorer 8 and earlier.
In this tutorial you will learn how to create a basic Bootstrap template using the Bootstrap 3
compiled version.
If you're just starting out in web development, start learning from here
Compiled download contain compiled and minified version of CSS and JavaScript files as well as icons in font format for faster and easier web
development, while the source contain original source files for all CSS and JavaScript, along with a local copy of the docs.
For the purpose of better understanding we'll focus on the compiled Bootstrap files. It saves your time because you don't have to bother every time
including separate files for individual functionality. It will also increase the performance of your website and saves the precious bandwidth when you
decided to move your site on production because of lesser HTTP request and download size since files are compiled and minified.
bootstrap/
| css/
| | bootstrap.css
| | bootstrap.min.css
| | bootstrap-theme.css
| | bootstrap-theme.min.css
| js/
| | bootstrap.js
| | bootstrap.min.js
| fonts/
| | glyphicons-halflings-regular.eot
| | glyphicons-halflings-regular.svg
| | glyphicons-halflings-regular.ttf
| | glyphicons-halflings-regular.woff
As you can see compiled version of Bootstrap provides compiled CSS and JS files (
(
bootstrap.min.*).
glyphicons-halflings-regular.*) inside the fonts folder. These fonts file includes more than 250 icons from
Tip:This is the most basic form of Bootstrap for quick usage in any web project. Please note that all JavaScript plugins require jQuery to be included.
Let's walk through the following steps. At the end of the tutorial, you will have made an HTML file that displays "Hello world" message in your web
browser.
Example
Try this code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic HTML File</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
Tip:Add the viewport <meta> tag inside the <head> section of your document to enable touch zooming and ensure proper rendering on
mobile devices.
<body> tag (i.e. </body>) to improve the performance of your web pages.
Example
Try this code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic Bootstrap Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<!-- Optional Bootstrap theme -->
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
</head>
<body>
<h1>Hello, world!</h1>
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
And we're all set! after adding the Bootstrap's CSS and JS files and the required jQuery library, we can begin to develop any site or application
with Bootstrap framework.
Note:It is important that the extension ".html" is specified some text editors, such as Notepad, will automatically save it
as
".txt" otherwise.
To open the file in a browser. Navigate to your file then double click on it. It will open in your default Web browser. (If it does not, open your browser
and drag the file to it.)
CDNs can offer a performance benefit by reducing the loading time, because they are hosting the Bootstrap's files on multiple servers spread across
the globe and when a user requests the file, it will be served from the server nearest to them.
Example
In the above example, we've included the compiled and minified version of Bootstrap's CSS and JavaScript files as well as the necessary jQuery
library using the CDN links. You'll also find these CDN links in most of the practice examples code throughout this site.
Tip:If the visitor to your site has already downloaded the Bootstrap's files from the same CDN while visiting the other sites, it will be loaded from the
browser's cache instead of re-downloading, which leads to faster loading time.
The Bootstrap grid system is the fastest and easy way to create a layout.
Bootstrap 3 includes predefined grid classes for quickly making grid layouts for different types of devices like cell phones, tablets, laptops and
.col-xs-* class to create grid columns for extra small devices like cell phones, similarly the .colsm-* class for small screen devices like tablets, the .col-md-* class for medium size devices like desktops and the .col-lg-* for large
desktops, etc. For example, you can use the
desktop screens. The following table summarizes some of the key features of the new grid system
Features
Small devices
Bootstrap 3 Grid
System
Phones (<768px)
Tablets
(768px)
Max
container
Medium
devices
Desktops
(992px)
970px
Large devices
Desktops
(1200px)
1170px
width
Grid
behavior
Horizontal
at all times
Collapsed to start,
horizontal above
breakpoints
Class
prefix
.col-xs-
.col-sm- .col-md-
.col-lg-
Max
column
width
Auto
~62px
~97px
Gutter
width
~81px
.col-sm-* class to an element will not only affect its styling on small devices, but
768px(i.e.768px) if .col-md-* and .col-lg-
also on medium and large devices having a screen size greater than or equal to
* class is not present. Similarly the .col-md-* class will not only affect the styling of elements on medium devices, but also on large devices if
a .col-lg-* class is not present.
Now the question arises how to create rows and columns using this 12 column responsive grid system. The answer is pretty simple, at first create a
.container class, after that create rows inside the container using
.row class, and to create columns inside any row you can use the class.col-xs-*, .col-sm-*, .col-md-* and .col-lg-*. The
container that acts as a wrapper for your rows and columns using the
the
columns are actual content area where we will place our contents. Let's put all these things into real action.
Example
Since Bootstrap grid system is based on 12 columns, so to keep the columns in a one line (i.e. side by side), the sum of the grid column numbers in
each row should be equal to 12. If you see the above example carefully you will find the numbers of grid columns (i.e.
twelve (
col-sm-*) add up to
Similarly, you can create other layouts based on the above principle. The following example will typically create three column layouts for laptops and
desktops screens. It also works in tablets in landscape mode if screen resolution is more than or equal to 992 pixels (e.g. Apple iPad). However, in
portrait mode it will be horizontal as usual.
Example
Try this code
<div class="container">
<!--Row with three equal columns-->
<div class="row">
<div class="col-md-4"><!--Column left--></div>
<div class="col-md-4"><!--Column middle--></div>
<div class="col-md-4"><!--Column right--></div>
</div>
<!--Row with three columns divided in 1:4:1 ratio-->
<div class="row">
<div class="col-md-2"><!--Column left--></div>
<div class="col-md-8"><!--Column middle--></div>
<div class="col-md-2"><!--Column right--></div>
</div>
<!--Row with three columns divided unevenly-->
<div class="row">
<div class="col-md-3"><!--Column left--></div>
<div class="col-md-7"><!--Column middle--></div>
<div class="col-md-2"><!--Column right--></div>
</div>
</div>
Note:If more than 12 grid columns are placed within a single row, then each group of extra columns, as a whole, will wrap onto a new line.
Example
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-2"><!--Column one--></div>
<div class="col-sm-9 col-md-8"><!--Column two--></div>
<div class="col-sm-12 col-md-2"><!--Column three--></div>
</div>
</div>
As you can see in the example above the sum of small grid column numbers (i.e.
third
wrapped onto a new line as one contiguous unit on small devices having the viewport width less than the 992 pixels.
Similarly, you can create even more adaptable layouts for your websites and applications using the Bootstrap's grid column wrapping feature. In the
next section, we'll discuss the other aspect of this feature. Here're some ready to use Bootstrap grid examples.
In the above illustration there are total 12 content boxes in all devices, but its placement varies according to the device screen size, like in mobile
device the layout is rendered as one column grid layout which has 1 column and 12 rows placed above one another, whereas in tablet it is rendered
as two column grid layout which has 2 columns and 6 rows. Further, in medium screen size devices like laptops and desktops it is rendered as three
column grid layout which as 3 columns and 4 rows and finally in large screen devices like large desktops it is rendered as four column grid layout
which has 4 columns and 3 rows.
Now the question is how we can create such responsive layouts using this Bootstrap new mobile first grid system. Let's start with the medium
device that can be a laptop or normal desktop. Since our medium device layout has 3 columns and 4 rows i.e. 3x4 grid layout, so the HTML code for
making such grid structure would be something like this.
Example
Try this code
<div class="container">
<div class="row">
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
<div class="col-md-4"><p>Box
</div>
</div>
1</p></div>
2</p></div>
3</p></div>
4</p></div>
5</p></div>
6</p></div>
7</p></div>
8</p></div>
9</p></div>
10</p></div>
11</p></div>
12</p></div>
If you see the output of the above example in a laptop or desktop having screen or viewport width greater than or equal to
than
1200px you will find it has 4 rows where each row has 3 equal columns resulting in 3x4 grid layout.
But just wait, the above example has a major alignment issue. If height of any column is taller than the other it doesn't clear properly and break the
layout. To fix this, use the combination of a
Example
Try this code
<div class="container">
<div class="row">
<div class="col-md-4"><p>Box 1</p></div>
<div class="col-md-4"><p>Box 2</p></div>
<div class="col-md-4"><p>Box 3</p></div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4"><p>Box 4</p></div>
<div class="col-md-4"><p>Box 5</p></div>
<div class="col-md-4"><p>Box 6</p></div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4"><p>Box 7</p></div>
<div class="col-md-4"><p>Box 8</p></div>
<div class="col-md-4"><p>Box 9</p></div>
<div class="clearfix visible-md-block"></div>
<div class="col-md-4"><p>Box 10</p></div>
<div class="col-md-4"><p>Box 11</p></div>
<div class="col-md-4"><p>Box 12</p></div>
</div>
</div>
Since the default gird system has 12 columns and in our layout sum of the every three column number, i.e.
we cleared columns after every third occurrence. In any other scenario where columns numbers are different for every column you should
use
.clearfix after the column that makes the complete 12 column grid.
Note:The responsive utility class .visible-md-block makes the .clearfix class effective only on medium size devices and it is hidden
on other devices.
Now it's time to customize our layout for other devices. First customize it for tablet. Since inside the tablet our layout rendered as 2x6 grids (i.e. 2
columns and 6 rows). So, go ahead and add the class
Example
Try this code
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4"><p>Box 1</p></div>
<div class="col-sm-6 col-md-4"><p>Box 2</p></div>
<div class="col-sm-6 col-md-4"><p>Box 3</p></div>
<div class="clearfix visible-md-block"></div>
<div class="col-sm-6 col-md-4"><p>Box 4</p></div>
<div class="col-sm-6 col-md-4"><p>Box 5</p></div>
<div class="col-sm-6 col-md-4"><p>Box 6</p></div>
<div class="clearfix visible-md-block"></div>
<div class="col-sm-6 col-md-4"><p>Box 7</p></div>
<div class="col-sm-6 col-md-4"><p>Box 8</p></div>
<div class="col-sm-6 col-md-4"><p>Box 9</p></div>
<div class="clearfix visible-md-block"></div>
<div class="col-sm-6 col-md-4"><p>Box 10</p></div>
<div class="col-sm-6 col-md-4"><p>Box 11</p></div>
<div class="col-sm-6 col-md-4"><p>Box 12</p></div>
</div>
</div>
col-sm-* is equal to 12, so clear floats after every second occurrence of columns.
After clearing floats for small devices our final code would be:
Example
Tip:For convenience choose your primary target device and create layout for that device first after that add classes to make it responsive for other
devices.
Similarly, you can customize the layout for larger devices like a large desktop screen. Here's the final code after combining the whole process.
Example
Try this code
<div class="container">
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="clearfix visible-sm-block"></div>
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="clearfix visible-md-block"></div>
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="clearfix visible-sm-block"></div>
<div class="clearfix visible-lg-block"></div>
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="clearfix visible-sm-block"></div>
<div class="clearfix visible-md-block"></div>
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="clearfix visible-sm-block"></div>
<div class="clearfix visible-lg-block"></div>
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="clearfix visible-md-block"></div>
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="clearfix visible-sm-block"></div>
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
<div class="col-sm-6 col-md-4 col-lg-3"><p>Box
</div>
</div>
1</p></div>
2</p></div>
3</p></div>
4</p></div>
5</p></div>
6</p></div>
7</p></div>
8</p></div>
9</p></div>
10</p></div>
11</p></div>
12</p></div>
Tip:According to the above illustration there is no need to customize the layout for extra small devices like mobile phones; since columns on extra
small devices are always horizontal and rendered as one column grid layout by default.
.col-md-offset-*, .col-sm-
offset-*, etc.
These classes offset the columns by simply increasing its left margin by specified number of columns. For example, the class
.col-sm-
offset-4 on the column .col-sm-8 moves it to the right over four columns from its original position.
Example
Try this code
<div class="container">
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-8"></div>
</div>
<div class="row">
<div class="col-sm-8 col-sm-offset-4"><!--Column with 4 columns offset--></div>
</div>
</div>
Example
<div class="container">
<div class="row">
<div class="col-sm-12">
<!--Nested row within a column-->
<div class="row">
<div class="col-xs-4 col-sm-6"></div>
<div class="col-xs-8 col-sm-6"></div>
</div>
</div>
</div>
</div>
.visible-*-* classes for each breakpoint come in three variations, one for each CSS display property
inline, block and inline-block.
As of v3.2.0, the
value:
Class
Description
.visiblemd-*
Tip:You can also mix these classes to make the elements visible on multiple devices. For example, you can apply the class .visible-xs-
* and .visible-md-*on any element to make it visible on extra small and medium devices.
Example
Try this code
1.
2.
3.
4.
<p
<p
<p
<p
Similarly you can use these hidden utility classes to hide the elements on certain devices.
Class
Description
.hiddenxs
.hiddensm
.hiddenmd
.hiddenlg
Tip:You can also mix these classes to make the elements hidden on multiple devices. For example you can apply the class .hidden-
xs and .hidden-md on any element to make it hidden on extra small and medium devices.
Example
Try this code
1.
2.
3.
4.
<p
<p
<p
<p
Similar to the regular responsive classes, you can use the following utility classes to show or hide certain elements for printing purpose or devices.
Class
Description
.visible-print-block
.visible-print-inline
for print.
.hidden-print
In this tutorial you will learn how to create fixed layouts with Bootstrap.
.container class. After that create rows with the .row class to wrap
.container for proper alignment and padding.
The process of creating the fixed yet responsive layout starts with the
the horizontal groups of columns. Rows must be placed within a
.col-xs-*, .col-sm-*, .col-md-* and .col-lg* where * represent grid number and should be from 1 to 12. Learn more about the Bootstrap grid system.
Further columns can be created inside the rows using the predefined grid classes like
Note:Actual content like text, images, videos, etc. should be placed within columns, and only columns may be the immediate children of rows.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap 3 Fixed Layout Example</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
<nav id="myNavbar" class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Tutorial Republic</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="nav navbar-nav">
<li class="active"><a href="http://www.tutorialrepublic.com" target="_blank">Home</a></li>
<li><a href="http://www.tutorialrepublic.com/about-us.php" target="_blank">About</a></li>
<li><a href="http://www.tutorialrepublic.com/contact-us.php" target="_blank">Contact</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Learn to Create Websites</h1>
<p>In today's world internet is the most popular way of connecting with the people. At <a
href="http://www.tutorialrepublic.com" target="_blank">tutorialrepublic.com</a> you will learn the essential of web development technologies
along with real life practice example, so that you can create your own website to connect with the people around the world.</p>
<p><a href="http://www.tutorialrepublic.com" target="_blank" class="btn btn-success btn-lg">Get started today</a></p>
</div>
<div class="row">
<div class="col-xs-4">
<h2>HTML</h2>
<p>HTML is a markup language that is used for creating web pages. The HTML tutorial section will help you understand the
basics of HTML, so that you can create your own web pages or website.</p>
<p><a href="http://www.tutorialrepublic.com/html-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-xs-4">
<h2>CSS</h2>
<p>CSS is used for describing the presentation of web pages. The CSS tutorial section will help you learn the essentials of
CSS, so that you can fine control the style and layout of your HTML document.</p>
<p><a href="http://www.tutorialrepublic.com/css-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-xs-4">
<h2>Bootstrap</h2>
<p>Bootstrap is a powerful front-end framework for faster and easier web development. The Bootstrap tutorial section will
help you learn the techniques of Bootstrap so that you can quickly create your own website.</p>
<p><a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-12">
<footer>
<p>© Copyright 2013 Tutorial Republic</p>
</footer>
</div>
</div>
</div>
</body>
</html>
The output of the above example will look something like this:
In this tutorial you will learn how to create fluid layouts with Bootstrap.
.container-fluid to create the fluid layouts in order to utilize the 100% width of the
viewport.
The class
.container-fluid simply applies the horizontal margin with the value auto and left and right padding of 15px on element to
-15px(i.e. margin: 0 -15px;) used on the .row.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap 3 Fluid Layout Example</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="css/custom.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
<nav id="myNavbar" class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Tutorial Republic</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="nav navbar-nav">
<li class="active"><a href="http://www.tutorialrepublic.com" target="_blank">Home</a></li>
<li><a href="http://www.tutorialrepublic.com/about-us.php" target="_blank">About</a></li>
<li><a href="http://www.tutorialrepublic.com/contact-us.php" target="_blank">Contact</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="container-fluid">
<h1>Learn to Create Websites</h1>
<p>In today's world internet is the most popular way of connecting with the people. At <a
href="http://www.tutorialrepublic.com" target="_blank">tutorialrepublic.com</a> you will learn the essential of web development technologies
along with real life practice example, so that you can create your own website to connect with the people around the world.</p>
<p><a href="http://www.tutorialrepublic.com" target="_blank" class="btn btn-success btn-lg">Get started today</a></p>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-4">
<h2>HTML</h2>
<p>HTML is a markup language that is used for creating web pages. The HTML tutorial section will help you understand the
basics of HTML, so that you can create your own web pages or website.</p>
<p><a href="http://www.tutorialrepublic.com/html-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-xs-4">
<h2>CSS</h2>
<p>CSS is used for describing the presentation of web pages. The CSS tutorial section will help you learn the essentials of
CSS, so that you can fine control the style and layout of your HTML document.</p>
<p><a href="http://www.tutorialrepublic.com/css-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-xs-4">
<h2>Bootstrap</h2>
<p>Bootstrap is a powerful front-end framework for faster and easier web development. The Bootstrap tutorial section will
help you learn the techniques of Bootstrap so that you can quickly create your own website.</p>
<p><a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
</div>
<hr>
<div class="row">
<div class="col-xs-12">
<footer>
<p>© Copyright 2013 Tutorial Republic</p>
</footer>
</div>
</div>
</div>
</body>
</html>
The output of the above example will look something like this:
In this tutorial you will learn how to create responsive web designs or layouts with Bootstrap
framework.
With the growing trend of smart phones and tablets, it has become almost unavoidable to ignore the optimization of sites for mobile devices.
Responsive web design is a preferable alternative and an efficient way to target a wide range of devices with much less efforts.
Responsive layouts automatically adjust and adapts to any device screen size, whether it is a desktop, a laptop, a tablet, or a mobile phone.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap 3 Responsive Layout Example</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
</head>
<body>
<nav id="myNavbar" class="navbar navbar-default navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Tutorial Republic</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="nav navbar-nav">
<li class="active"><a href="http://www.tutorialrepublic.com" target="_blank">Home</a></li>
<li><a href="http://www.tutorialrepublic.com/about-us.php" target="_blank">About</a></li>
<li><a href="http://www.tutorialrepublic.com/contact-us.php" target="_blank">Contact</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Learn to Create Websites</h1>
<p>In today's world internet is the most popular way of connecting with the people. At <a
href="http://www.tutorialrepublic.com" target="_blank">tutorialrepublic.com</a> you will learn the essential of web development technologies
along with real life practice example, so that you can create your own website to connect with the people around the world.</p>
<p><a href="http://www.tutorialrepublic.com" target="_blank" class="btn btn-success btn-lg">Get started today</a></p>
</div>
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-2">
<h2>HTML</h2>
<p>HTML is a markup language that is used for creating web pages. The HTML tutorial section will help you understand the
basics of HTML, so that you can create your own web pages or website.</p>
<p><a href="http://www.tutorialrepublic.com/html-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-sm-6 col-md-4 col-lg-2">
<h2>CSS</h2>
<p>CSS is used for describing the presentation of web pages. The CSS tutorial section will help you learn the essentials of
CSS, so that you can fine control the style and layout of your HTML document.</p>
<p><a href="http://www.tutorialrepublic.com/css-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="clearfix visible-sm-block"></div>
<div class="col-sm-6 col-md-4 col-lg-2">
<h2>Bootstrap</h2>
<p>Bootstrap is a powerful front-end framework for faster and easier web development. The Bootstrap tutorial section will
help you learn the techniques of Bootstrap so that you can create web your own website with much less efforts.</p>
<p><a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="clearfix visible-md-block"></div>
<div class="col-sm-6 col-md-4 col-lg-2">
<h2>References</h2>
<p>The references section outlines all the standard HTML tags and CSS properties along with other useful references such as
color names and values, symbols and character entities, web safe fonts, language codes, HTTP messages and much more.</p>
<p><a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="clearfix visible-sm-block"></div>
<div class="col-sm-6 col-md-4 col-lg-2">
<h2>Examples</h2>
<p>The examples section encloses an extensive collection of examples on various topic that you can try and test yourself
using online HTML editor.</p>
<p><a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-sm-6 col-md-4 col-lg-2">
<h2>FAQ</h2>
<p>The collection of Frequently Asked Questions (FAQ) provides brief answers to many common questions related to web
design and development.</p>
<p><a href="http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-12">
<footer>
<p>© Copyright 2013 Tutorial Republic</p>
</footer>
</div>
</div>
</div>
</body>
</html>
Tip:Open the output of this example in new window and resize the screen you will see the orientation of content boxes changes when viewport
width crossing or approaching the certain limit (i.e. breakpoints).
In this tutorial you will learn about the styling and formatting of text content like headings,
paragraphs, blockquotes, etc. with Bootstrap.
Example
Try this code
1.
2.
3.
4.
5.
6.
<h1>h1.
<h2>h2.
<h3>h3.
<h4>h4.
<h5>h5.
<h6>h6.
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
heading</h1>
heading</h2>
heading</h3>
heading</h4>
heading</h5>
heading</h6>
The output of the above example will look something like this:
<small> tag or <span> tag with .small class to display the secondary text of any heading in a smaller and
lighter variation.
Example
Try this code
1.
2.
3.
4.
5.
6.
<h1>h1.
<h2>h2.
<h3>h3.
<h4>h4.
<h5>h5.
<h6>h6.
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
Bootstrap
heading
heading
heading
heading
heading
heading
<small>Secondary
<small>Secondary
<small>Secondary
<small>Secondary
<small>Secondary
<small>Secondary
text</small></h1>
text</small></h2>
text</small></h3>
text</small></h4>
text</small></h5>
text</small></h6>
The output of the above example will look something like this:
Example
<div class="page-header">
<h1>Bootstrap <small>An intuitive front-end framework</small></h1>
</div>
The output of the above example will look something like this:
font-size is 14px, with a line-height of 1.428. This is applied to the <body> and all paragraphs.
line-height(10px by default) is applied to the all paragraphs (<p>).
You can also make a paragraph stand out by just adding the class
.lead.
Example
The HTML code in the above examples will produce the following result:
You can easily align text inside a paragraph and other elements using text alignment classes.
Example
<p
<p
<p
<p
<p
<strong>, <i>, <small> to make your text bold, italic, small and so on, in the same way
Example
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
<p class="text-lowercase">The quick brown fox jumps over the lazy dog.</p>
<p class="text-uppercase">The quick brown fox jumps over the lazy dog.</p>
<p class="text-capitalize">The quick brown fox jumps over the lazy dog.</p>
The output of the above example will look something like this:
Bootstrap has handful of emphasis utility classes that can be used for this purpose such as showing success message in green color, warning or error
message in red color, etc.
Example
Try this code
1.
2.
3.
4.
5.
6.
<p
<p
<p
<p
<p
<p
The output of the above example will look something like this:
Styling Blockquotes
You can also give pretty look to your blockquotes Just define the blockquotes using the standard
Example
<blockquote>
<p>The world is a dangerous place to live; not because of the people who are evil, but because of the people who don't do anything
about it.</p>
<small>by <cite>Albert Einstein</cite></small>
</blockquote>
The output of the above example will look something like this:
Alternatively you can right-aligned the blockquote through floating it to right by simply applying the class
the
.pull-right on
<blockquote> element.
Example
Try this code
1.
2.
3.
4.
<blockquote class="pull-right">
<p>The world is a dangerous place to live; not because of the people who are evil, but because of the people who don't do anything
about it.</p>
<small>by <cite>Albert Einstein</cite></small>
</blockquote>
The output of the above example will look something like this:
In this tutorial you will learn how to create elegant tables with Bootstrap.
What is Table
The HTML tables are used to present data in grid manner like row and columns. Using Bootstrap you can greatly improve the appearance of table in
a simple way.
Example
<table class="table">
<thead>
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>Carter</td>
<td>johncarter@mail.com</td>
</tr>
<tr>
<td>2</td>
<td>Peter</td>
<td>Parker</td>
<td>peterparker@mail.com</td>
</tr>
<tr>
<td>3</td>
<td>John</td>
<td>Rambo</td>
<td>johnrambo@mail.com</td>
</tr>
</tbody>
</table>
The output of the above example will look something like this:
You can create table with alternate background like zebra-strips by simply adding the Bootstrap's class
class.
in IE7-8).
Example
Try this code
The output of the above example will look something like this:
Example
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>Carter</td>
<td>johncarter@mail.com</td>
</tr>
<tr>
<td>2</td>
<td>Peter</td>
<td>Parker</td>
<td>peterparker@mail.com</td>
</tr>
<tr>
<td>3</td>
<td>John</td>
<td>Rambo</td>
<td>johnrambo@mail.com</td>
</tr>
</tbody>
</table>
The output of the above example will look something like this:
Example
</tbody>
</table>
The output of the above example will look something like this:
You can also make your tables more compact and save the space through adding an extra class
class. The class
Example
The output of the above example will look something like this:
Example
Try this code
<table class="table">
<thead>
<tr>
<th>Row</th>
<th>Bill</th>
<th>Payment Date</th>
<th>Payment Status</th>
</tr>
</thead>
<tbody>
<tr class="active">
<td>1</td>
<td>Credit Card</td>
<td>04/07/2014</td>
<td>Call in to confirm</td>
</tr>
<tr class="success">
<td>2</td>
<td>Water</td>
<td>01/07/2014</td>
<td>Paid</td>
</tr>
<tr class="info">
<td>3</td>
<td>Internet</td>
<td>05/07/2014</td>
<td>Change plan</td>
</tr>
<tr class="warning">
<td>4</td>
<td>Electricity</td>
<td>03/07/2014</td>
<td>Pending</td>
</tr>
<tr class="danger">
<td>5</td>
<td>Telephone</td>
<td>06/07/2014</td>
<td>Due</td>
</tr>
</tbody>
</table>
The output of the above example will look something like this:
Example
768px). However,
Tag
Description
<table
>
Tag
Description
>
<tr>
<th>
<td>
In this tutorial you will learn how to apply styles to different types of lists with Bootstrap.
Unordered lists A list of items in which the order does not explicitly matter. The list items in unordered lists are marked with bullets.
Ordered lists A list of items in which the order does explicitly matter. The list items in ordered lists are marked with numbers.
See the tutorial on HTML Lists, to learn more about different lists types.
.list-unstyled to
Example
Try this code
<ul class="list-unstyled">
<li>Home</li>
<li>Products
<ul>
<li>Gadgets</li>
<li>Accessories</li>
</ul>
</li>
<li>About Us</li>
<li>Contact</li>
</ul>
The output of the above example will look something like this:
Note:The .list-unstyled class removes the default list-style and left paddingonly from the list items which are immediate children
of the
.list-inline to the respective <ul> or <ol> elements. The .list-inline class also adds
5px by default) to the all list items.
Example
Try this code
1.
2.
3.
4.
5.
6.
<ul class="list-inline">
<li>Home</li>
<li>Products</li>
<li>About Us</li>
<li>Contact</li>
</ul>
The output of the above example will look something like this:
The terms and descriptions in definition lists can also be placed side-by-side using the Bootstrap's class
horizontal definition lists will be truncated if is too long to fit in the left column (
change to the default stacked layout.
Example
Try this code
<dl class="dl-horizontal">
<dt>User Agent</dt>
<dd>An HTML user agent is any device that interprets HTML documents.</dd>
<dt>Client-side Scripting</dt>
<dd>Client-side scripting generally refers to the category of computer programs on the web that are executed client-side i.e. by the
user's web browser.</dd>
<dt>Document Tree</dt>
<dd>The tree of elements encoded in the source document.</dd>
</dl>
The output of the above example will look something like this:
Note:The terms clipped in horizontal definition lists will be indicated by an ellipsis () using the text-overflow CSS property.
Example
Try this code
1.
2.
3.
4.
<ul class="list-group">
<li class="list-group-item">Pictures</li>
<li class="list-group-item">Documents</li>
<li class="list-group-item">Music</li>
5.
6.
<li class="list-group-item">Videos</li>
</ul>
The output of the above example will look something like this:
Further you can hyperlink list group items with the little change in HTML markup.
<li> with <a> tag and use <div> element as a parent instead of <ul>. You can also add icons and badges to this list
group to make it more elegant. The badges component will automatically be positioned on the right.
Example
Try this code
<div class="list-group">
<a href="#" class="list-group-item active">
<span class="glyphicon glyphicon-camera"></span> Pictures <span class="badge">25</span>
</a>
<a href="#" class="list-group-item">
<span class="glyphicon glyphicon-file"></span> Documents <span class="badge">145</span>
</a>
<a href="#" class="list-group-item">
<span class="glyphicon glyphicon-music"></span> Music <span class="badge">50</span>
</a>
<a href="#" class="list-group-item">
<span class="glyphicon glyphicon-film"></span> Videos <span class="badge">8</span>
</a>
</div>
The output of the above example will look something like this:
Tip: You can use the Bootstrap list group component for creating sidebar navigation. For example, displaying the list of product or categories on your
website.
You can also add other HTML elements like headings and paragraph within these list groups.
Example
Try this code
<div class="list-group">
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading">What is HTML?</h4>
<p class="list-group-item-text">HTML stands for HyperText Markup Language. HTML is the main markup language for describing
the structure of Web pages.</p>
</a>
<a href="#" class="list-group-item active">
<h4 class="list-group-item-heading">What is Bootstrap?</h4>
<p class="list-group-item-text">Bootstrap is a powerful front-end framework for faster and easier web development. It is a
collection of HTML and CSS based design template.</p>
</a>
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading">What is CSS?</h4>
<p class="list-group-item-text">CSS stands for Cascading Style Sheet. CSS allows you to specify various style properties for a given
HTML element such as colors, backgrounds, fonts etc.</p>
</a>
</div>
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
6.
<ul class="list-group">
<li class="list-group-item
<li class="list-group-item
<li class="list-group-item
request.</li>
<li class="list-group-item
</ul>
The output of the above example will look something like this:
Similarly, you can use these contextual classes to the linked list group items. You can also use the class
item.
Example
Try this code
1.
2.
3.
4.
5.
6.
<div class="list-group">
<a href="#" class="list-group-item
<a href="#" class="list-group-item
<a href="#" class="list-group-item
request.</a>
<a href="#" class="list-group-item
</div>
In this tutorial you will learn how to create elegant forms with Bootstrap.
HTML forms are the integral part of the web pages and applications, but
styling the form controls manually one by one with CSS are often boring
and tedious. Bootstrap greatly simplifies the process of styling and
alignment of form controls like labels, input fields, selectboxes, textareas,
buttons, etc. through predefined set of classes.
Bootstrap provides three different types of form layouts:
Vertical Form (default form layout)
Horizontal Form
Inline Form
The following section will give you the detailed overview of these form
layouts as well as the various form related Bootstrap components one by
one.
Creating Vertical Form Layout
This is the default Bootstrap form layout in which styles are applied to
form controls without adding any base class to the <form> element or any
large changes in the markup.
The form controls in this layout are stacked with left-aligned labels on the
top.
Example
Try this code
<form>
<div class="form-group">
<label for="inputEmail">Email</label>
<input type="email" class="form-control" id="inputEmail" placeholder="Email">
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
<button type="submit" class="btn btn-primary">Login</button>
</form>
The output of the above example will look something like this:
In horizontal form layout labels are right aligned and floated to left to
make them appear on the same line as form controls. The horizontal form
layout requires the various markup changes from a default form layout.
Steps to achieve this layout are listed below:
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail" class="control-label col-xs-2">Email</label>
<div class="col-xs-10">
<input type="email" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Password</label>
<div class="col-xs-10">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
The output of the above example will look something like this:
The output of the above example will look something like this:
There might be a situation when you need to place just plain text next to a
form label instead of a form control. You can do this within a horizontal
form layout by using the
.form-control-static class on a <p> element, like this:
Example
Try this code
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail" class="control-label col-xs-2">Email</label>
<div class="col-xs-10">
<p class="form-control-static">harrypotter@mail.com</p>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Password</label>
<div class="col-xs-10">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</form>
The output of the above example will look something like this:
You can easily control the height of your input and select boxes to match
the button sizes. The Bootstrap's relative sizing classes like .input-lg, .inputsm can be used both on<input> and <select> boxes to create it's larger or
smaller sizes.
Example
Try this code
<form>
<div class="row">
<div class="col-xs-6">
<input type="text" class="form-control input-lg" placeholder="Large input">
</div>
<div class="col-xs-6">
<select class="form-control input-lg">
<option>Large select</option>
</select>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-6">
<input type="text" class="form-control" placeholder="Default input">
</div>
<div class="col-xs-6">
<select class="form-control">
<option>Default select</option>
</select>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-6">
<input type="text" class="form-control input-sm" placeholder="Small input">
</div>
<div class="col-xs-6">
<select class="form-control input-sm">
<option>Small select</option>
</select>
</div>
</div>
</form>
You can also match the sizes of your form controls to the Bootstrap grid
column sizes. Just wrap your form controls (i.e. <input>, <textarea>,
and <select>) in grid columns, or any custom element and apply the grid
classes on it.
Example
Try this code
<form>
<div class="row">
<div class="col-xs-3">
<input type="text" class="form-control">
</div>
<div class="col-xs-4">
<input type="text" class="form-control">
</div>
<div class="col-xs-5">
<input type="text" class="form-control">
</div>
</div>
<br>
<div class="row">
<div class="col-xs-3">
<textarea class="form-control"></textarea>
</div>
<div class="col-xs-4">
<textarea class="form-control"></textarea>
</div>
<div class="col-xs-5">
<textarea class="form-control"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-3">
<select class="form-control">
<option>Select</option>
</select>
</div>
<div class="col-xs-4">
<select class="form-control">
<option>Select</option>
</select>
</div>
<div class="col-xs-5">
<select class="form-control">
<option>Select</option>
</select>
</div>
</div>
</form>
Bootstrap includes some other useful form components to make your form
more attractive.
Creating Prepended and Appended Inputs
You can add text and icons or buttons before or after any text-based input.
To prepend or append text and icons to an input:
Wrap the text or icon within a <span> element having the class .inputgroup-addonand place it before or after the <input> element.
Wrap both the <span> and text-based <input> element within
a <div> element and apply the class .input-group on it.
Bootstrap's prepending or appending feature is only available to textbased inputs. It does not support <select> or <textarea> elements.
Note:
Example
Try this code
<form>
<div class="row">
<div class="col-xs-4">
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
<input type="text" class="form-control" placeholder="Username">
</div>
</div>
<div class="col-xs-4">
<div class="input-group">
<input type="text" class="form-control" placeholder="Amount">
<span class="input-group-addon">.00</span>
</div>
</div>
<div class="col-xs-4">
<div class="input-group">
<span class="input-group-addon">$</span>
<input type="text" class="form-control" placeholder="US Dollar">
<span class="input-group-addon">.00</span>
</div>
</div>
</div>
</form>
The output of the above example will look something like this:
Similarly, you can place checkbox or radio button within input group's
addon instead of text.
Example
Try this code
<form>
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox">
</span>
<input type="text" class="form-control">
</div>
</div>
<div class="col-xs-6">
<div class="input-group">
<span class="input-group-addon">
<input type="radio">
</span>
<input type="text" class="form-control">
</div>
</div>
</div>
</form>
The output of the above example will look something like this:
You can also prepend or append buttons instead of text. Wrap buttons
within the <span>element and apply the class .input-group-btn, instead
of .input-group-addon.
Example
<form>
<div class="row">
<div class="col-xs-5">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search…">
<span class="input-group-btn">
<button type="button" class="btn btn-default">Go</button>
</span>
</div>
</div>
<div class="col-xs-7">
<div class="input-group">
<input type="text" class="form-control" placeholder="Type something…">
<span class="input-group-btn">
<button type="button" class="btn btn-default">Action</button>
<button type="button" class="btn btn-default">Options</button>
</span>
</div>
</div>
</div>
</form>
The output of the above example will look something like this:
You can also create dropdown buttons if you want to do more than one
action from a button.
Example
Try this code
<form>
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Action <span
class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<input type="text" class="form-control">
</div>
</div>
<div class="col-xs-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Action <span
class="caret"></span></button>
<ul class="dropdown-menu pull-right">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
</div>
</div>
</div>
</form>
The output of the above example will look something like this:
Similarly, you can define the segmented dropdown button group where
dropdown button is placed besides the other buttons.
Example
<form>
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<div class="input-group-btn">
<button tabindex="-1" class="btn btn-default" type="button">Action</button>
<button tabindex="-1" data-toggle="dropdown" class="btn btn-default dropdown-toggle" type="button">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
<input type="text" class="form-control">
</div>
</div>
<div class="col-xs-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-btn">
<button tabindex="-1" class="btn btn-default" type="button">Action</button>
<button tabindex="-1" data-toggle="dropdown" class="btn btn-default dropdown-toggle" type="button">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu pull-right">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
</div>
</div>
</div>
</form>
The output of the above example will look something like this:
You can also add the relative form sizing classes such as .input-grouplg or .input-group-sm to the .input-group itself to make it larger or smaller.
The contents within .input-group will automatically resize there is no need
for repeating the form control size classes on each element.
Example
Try this code
<form>
<div class="row">
<div class="col-xs-4">
</div>
</div>
<div class="col-xs-4">
<span class="input-group-addon">
<input type="checkbox">
</span>
</div>
<div class="col-xs-4">
<div class="input-group-btn">
</button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li class="divider"></li>
</ul>
</div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-4">
<div class="input-group">
</div>
</div>
<div class="col-xs-4">
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox">
</span>
</div>
</div>
<div class="col-xs-4">
<div class="input-group">
<div class="input-group-btn">
</button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li class="divider"></li>
</ul>
</div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-xs-4">
</div>
</div>
<div class="col-xs-4">
<span class="input-group-addon">
<input type="checkbox">
</span>
</div>
</div>
<div class="col-xs-4">
<div class="input-group-btn">
</button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li class="divider"></li>
</ul>
</div>
</div>
</div>
</form>
Similarly, you can use the class .form-group-lg or .form-group-sm to resize the
labels and form controls within the horizontal form layouts at the same
time.
Example
Try this code
<form class="form-horizontal">
</div>
<div class="form-group">
</div>
</div>
</form>
<form>
<input type="text" class="form-control" placeholder="Disabled input" disabled="disabled">
</form>
The output of the above example will look something like this:
Similarly, you can add the readonly attribute on input elements to create
read only input controls that prevent user inputs and give the style same
as disabled.
Example
Try this code
1.
2.
3.
<form>
<input type="text" class="form-control" placeholder="Readonly input" readonly="readonly">
</form>
Rather than disabling the form controls individually, you can also disable
all form controls within a fieldset at once by adding the disabled attribute to
the <fieldset> element.
Example
Try this code
<form class="form-horizontal">
<fieldset disabled="disabled">
<div class="form-group">
<label for="inputEmail" class="control-label col-xs-2">Email</label>
<div class="col-xs-10">
<input type="email" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="control-label col-xs-2">Password</label>
<div class="col-xs-10">
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-2 col-xs-10">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</div>
</fieldset>
</form>
The output of the above example will look something like this:
Placing help text for the form controls in an efficient way to guide users to
enter the correct data in a form. You can place block level help text for the
form controls using the class.help-block. The help text is typically displayed
at the bottom of the control.
Example
Try this code
1.
2.
3.
4.
<form>
<input type="text" class="form-control">
<span class="help-block">A block of help text that breaks onto a new line and may extend beyond one line.</span>
</form>
The output of the above example will look something like this:
Bootstrap provides easy to use and powerful mechanism for styling input
controls to present different validation states. Bootstrap includes
validation styles for error, warning, and success messages. To use, just
add the appropriate class to the surrounding .form-group.
Example
Try this code
<form class="form-horizontal">
<div class="form-group has-success">
<label class="col-xs-2 control-label" for="inputSuccess">Username</label>
<div class="col-xs-10">
<input type="text" id="inputSuccess" class="form-control" placeholder="Input with success">
<span class="help-block">Username is available</span>
</div>
</div>
<div class="form-group has-warning">
<label class="col-xs-2 control-label" for="inputWarning">Password</label>
<div class="col-xs-10">
<input type="password" id="inputWarning" class="form-control" placeholder="Input with warning">
<span class="help-block">Password strength: Weak</span>
</div>
</div>
<div class="form-group has-error">
<label class="col-xs-2 control-label" for="inputError">Email</label>
<div class="col-xs-10">
<input type="email" id="inputError" class="form-control" placeholder="Input with error">
<span class="help-block">Please enter a valid email address</span>
</div>
</div>
</form>
The output of the above example will look something like this:
You can also add optional feedback icons to your inputs using the
class .has-feedback on.form-group and the right glyphicon, like this:
Example
Try this code
<form class="form-horizontal">
<div class="form-group has-success has-feedback">
<label class="col-xs-2 control-label" for="inputSuccess">Username</label>
<div class="col-xs-10">
<input type="text" id="inputSuccess" class="form-control" placeholder="Input with success">
<span class="glyphicon glyphicon-ok form-control-feedback"></span>
<span class="help-block">Username is available</span>
</div>
</div>
<div class="form-group has-warning has-feedback">
<label class="col-xs-2 control-label" for="inputWarning">Password</label>
<div class="col-xs-10">
<input type="password" id="inputWarning" class="form-control" placeholder="Input with warning">
<span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
<span class="help-block">Password strength: Weak</span>
</div>
</div>
<div class="form-group has-error has-feedback">
<label class="col-xs-2 control-label" for="inputError">Email</label>
<div class="col-xs-10">
<input type="email" id="inputError" class="form-control" placeholder="Input with error">
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
<span class="help-block">Please enter a valid email address</span>
</div>
</div>
</form>
Bootstrap includes support for all standard form controls as well as new
HTML5 input typessuch as datetime, number, email, url, search, tel, color
etc. The following example will show you the usages of standard form
controls with Bootstrap.
Example
Try this code
<form class="form-horizontal">
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" value="agree"> I agree to the <a href="#">Terms and Conditions</a>.
</label>
</div>
</div>
<br>
<div class="form-group">
<div class="col-xs-offset-3 col-xs-9">
<input type="submit" class="btn btn-primary" value="Submit">
<input type="reset" class="btn btn-default" value="Reset">
</div>
</div>
</form>
In this tutorial you will learn how to style images, creating thumbnails, grids of images and videos,
and so on using Bootstrap.
Using the Bootstrap built-in classes you can easily style images such as making the round cornered or circular images, or give them effect like
thumbnails.
Example
Try this code
1.
2.
3.
The output of the above example will look something like this:
Warning:The classes .img-rounded and .img-circle do not work in IE8 and lower versions due to lack of support for CSS border-
radius property.
In Bootstrap you can make the images responsive too. Just add the class
the styles
Example
Try this code
1.
2.
3.
Note:When making the responsive layouts consider making your images responsive too, otherwise if an image width is larger than the parent
element's width in any case it will overflow and may break your layout.
You can also make the video or slideshow embedded in a web page responsive without affecting its original aspect ratio. The Bootstrap responsive
embed classes can be applied directly to the
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
9.
.embedresponsive-16by9 and .embed-responsive-4by3 to their containing blocks respectively and the class.embedresponsive-item to the descendant <iframe> element.
In the above example, we've created the two responsive videos with two different aspect ratios (16:9 and 4:3) by adding the classes
Tip:The aspect ratio of an image describes the proportional relationship between its width and its height. Two common videographic aspect ratios
are 16:9 and 4:3.
Bootstrap Thumbnails
The Bootstrap thumbnail component is very useful for creating grids of images or videos, lists of products, portfolios, and much more. The following
example will show you how to create thumbnails to showcase linked images.
Example
Try this code
<div class="container">
<div class="row">
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="125x125.jpg" alt="125x125">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="125x125.jpg" alt="125x125">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="125x125.jpg" alt="125x125">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="125x125.jpg" alt="125x125">
</a>
</div>
</div>
</div>
The output of the above example will look something like this:
You can also insert HTML content like headings, paragraphs, or buttons into thumbnails.
Example
Try this code
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="thumbnail">
<img src="avatar.jpg" alt="Sample Image">
<div class="caption">
<h3>Thumbnail label</h3>
<p>Thumbnail description</p>
<p><a href="#" class="btn btn-primary">Share</a> <a href="#" class="btn btn-default">Download</a></p>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="thumbnail">
<img src="avatar.jpg" alt="Sample Image">
<div class="caption">
<h3>Thumbnail label</h3>
<p>Thumbnail description</p>
<p><a href="#" class="btn btn-primary">Share</a> <a href="#" class="btn btn-default">Download</a></p>
</div>
</div>
</div>
</div>
</div>
Tip:The thumbnails component uses existing grid classes like .col-xs-*, .col-sm-*, .col-md-*, .col-lg-*, etc. for controlling the
dimensions of thumbnails.
Example
<div class="media">
<a href="#" class="pull-left">
<img src="avatar-tiny.jpg" class="media-object" alt="Sample Image">
</a>
<div class="media-body">
<h4 class="media-heading">Jhon Carter <small><i>Posted on January 10, 2014</i></small></h4>
<p>Excellent feature! I love it. One day I'm definitely going to put this Bootstrap component into use and I'll let you know once I
do.</p>
8.
9.
</div>
</div>
The output of the above example will look something like this:
You can also create a list of media object or nested media object using the media list component. It can be useful for comment threads or article
lists.
Example
Try this code
<ul class="media-list">
<li class="media">
<a href="#" class="pull-left">
<img src="avatar-tiny.jpg" class="media-object" alt="Sample Image">
</a>
<div class="media-body">
<h4 class="media-heading">Media Heading</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipis elit</p>
<!-- Nested media object -->
<div class="media">
<a href="#" class="pull-left">
<img src="avatar-tiny.jpg" class="media-object" alt="Sample Image">
</a>
<div class="media-body">
<h4 class="media-heading">Nested Media Heading</h4>
<p>Vestibulum consectetur scelerisque faucibus</p>
<!-- Nested media object -->
<div class="media">
<a href="#" class="pull-left">
<img src="avatar-tiny.jpg" class="media-object" alt="Sample Image">
</a>
<div class="media-body">
<h4 class="media-heading">Nested Media Heading</h4>
<p>Integer pulvinar leo id risus tempor</p>
</div>
</div>
</div>
</div>
<!-- Nested media object -->
<div class="media">
<a href="#" class="pull-left">
<img src="avatar-tiny.jpg" class="media-object" alt="Sample Image">
</a>
<div class="media-body">
<h4 class="media-heading">Nested Media Heading</h4>
<p>Phasellus vitae suscipit justo mauris</p>
</div>
</div>
</div>
</li>
<li class="media">
<a href="#" class="pull-left">
<img src="avatar-tiny.jpg" class="media-object" alt="Sample Image">
</a>
<div class="media-body">
<h4 class="media-heading">Media Heading</h4>
<p>Quisque pharetra velit id velit iaculis pretium</p>
</div>
</li>
</ul>
Icons by Glyphicons
Bootstrap 3.3.5 includes more than 250 Glyphicons. As opposed to previous sprite versionthese icons are available in font format for better usability
and scalability.
Since these Glyphicons are font based now you can create icons of any color just applying the CSS
glyphicon glyphicon-asterisk
glyphicon glyphicon-plus
glyphicon glyphicon-euro
glyphicon glyphicon-eur
glyphicon glyphicon-minus
glyphicon glyphicon-cloud
glyphicon glyphicon-envelope
glyphicon glyphicon-pencil
glyphicon glyphicon-glass
glyphicon glyphicon-music
glyphicon glyphicon-search
glyphicon glyphicon-heart
glyphicon glyphicon-star
glyphicon glyphicon-star-empty
glyphicon glyphicon-user
glyphicon glyphicon-film
glyphicon glyphicon-th-large
glyphicon glyphicon-th
glyphicon glyphicon-th-list
glyphicon glyphicon-ok
glyphicon glyphicon-remove
glyphicon glyphicon-zoom-in
glyphicon glyphicon-zoom-out
glyphicon glyphicon-off
glyphicon glyphicon-signal
glyphicon glyphicon-cog
glyphicon glyphicon-trash
glyphicon glyphicon-home
glyphicon glyphicon-file
glyphicon glyphicon-time
glyphicon glyphicon-road
glyphicon glyphicon-download-alt
glyphicon glyphicon-download
glyphicon glyphicon-upload
glyphicon glyphicon-inbox
glyphicon glyphicon-play-circle
glyphicon glyphicon-repeat
glyphicon glyphicon-refresh
glyphicon glyphicon-list-alt
glyphicon glyphicon-lock
glyphicon glyphicon-flag
glyphicon glyphicon-headphones
glyphicon glyphicon-volume-off
glyphicon glyphicon-volume-down
glyphicon glyphicon-volume-up
glyphicon glyphicon-qrcode
glyphicon glyphicon-barcode
glyphicon glyphicon-tag
glyphicon glyphicon-tags
glyphicon glyphicon-book
glyphicon glyphicon-bookmark
glyphicon glyphicon-print
glyphicon glyphicon-camera
glyphicon glyphicon-font
glyphicon glyphicon-bold
glyphicon glyphicon-italic
glyphicon glyphicon-text-height
glyphicon glyphicon-text-width
glyphicon glyphicon-align-left
glyphicon glyphicon-align-center
glyphicon glyphicon-align-right
glyphicon glyphicon-align-justify
glyphicon glyphicon-list
glyphicon glyphicon-indent-left
glyphicon glyphicon-indent-right
glyphicon glyphicon-facetime-video
glyphicon glyphicon-picture
glyphicon glyphicon-map-marker
glyphicon glyphicon-adjust
glyphicon glyphicon-tint
glyphicon glyphicon-edit
glyphicon glyphicon-share
glyphicon glyphicon-check
glyphicon glyphicon-move
glyphicon glyphicon-step-backward
glyphicon glyphicon-fast-backward
glyphicon glyphicon-backward
glyphicon glyphicon-play
glyphicon glyphicon-pause
glyphicon glyphicon-stop
glyphicon glyphicon-forward
glyphicon glyphicon-fast-forward
glyphicon glyphicon-step-forward
glyphicon glyphicon-eject
glyphicon glyphicon-chevron-left
glyphicon glyphicon-chevron-right
glyphicon glyphicon-plus-sign
glyphicon glyphicon-minus-sign
glyphicon glyphicon-remove-sign
glyphicon glyphicon-ok-sign
glyphicon glyphicon-question-sign
glyphicon glyphicon-info-sign
glyphicon glyphicon-screenshot
glyphicon glyphicon-remove-circle
glyphicon glyphicon-ok-circle
glyphicon glyphicon-ban-circle
glyphicon glyphicon-arrow-left
glyphicon glyphicon-arrow-right
glyphicon glyphicon-arrow-up
glyphicon glyphicon-arrow-down
glyphicon glyphicon-share-alt
glyphicon glyphicon-resize-full
glyphicon glyphicon-resize-small
glyphicon glyphicon-exclamation-sign
glyphicon glyphicon-gift
glyphicon glyphicon-leaf
glyphicon glyphicon-fire
glyphicon glyphicon-eye-open
glyphicon glyphicon-eye-close
glyphicon glyphicon-warning-sign
glyphicon glyphicon-plane
glyphicon glyphicon-calendar
glyphicon glyphicon-random
glyphicon glyphicon-comment
glyphicon glyphicon-magnet
glyphicon glyphicon-chevron-up
glyphicon glyphicon-chevron-down
glyphicon glyphicon-retweet
glyphicon glyphicon-shopping-cart
glyphicon glyphicon-folder-close
glyphicon glyphicon-folder-open
glyphicon glyphicon-resize-vertical
glyphicon glyphicon-resize-horizontal
glyphicon glyphicon-hdd
glyphicon glyphicon-bullhorn
glyphicon glyphicon-bell
glyphicon glyphicon-certificate
glyphicon glyphicon-thumbs-up
glyphicon glyphicon-thumbs-down
glyphicon glyphicon-hand-right
glyphicon glyphicon-hand-left
glyphicon glyphicon-hand-up
glyphicon glyphicon-hand-down
glyphicon glyphicon-circle-arrow-right
glyphicon glyphicon-circle-arrow-left
glyphicon glyphicon-circle-arrow-up
glyphicon glyphicon-circle-arrow-down
glyphicon glyphicon-globe
glyphicon glyphicon-wrench
glyphicon glyphicon-tasks
glyphicon glyphicon-filter
glyphicon glyphicon-briefcase
glyphicon glyphicon-fullscreen
glyphicon glyphicon-dashboard
glyphicon glyphicon-paperclip
glyphicon glyphicon-heart-empty
glyphicon glyphicon-link
glyphicon glyphicon-phone
glyphicon glyphicon-pushpin
glyphicon glyphicon-usd
glyphicon glyphicon-gbp
glyphicon glyphicon-sort
glyphicon glyphicon-sort-by-alphabet
glyphicon glyphicon-sort-by-alphabet-alt
glyphicon glyphicon-sort-by-order
glyphicon glyphicon-sort-by-order-alt
glyphicon glyphicon-sort-by-attributes
glyphicon glyphicon-sort-by-attributes-alt
glyphicon glyphicon-unchecked
glyphicon glyphicon-expand
glyphicon glyphicon-collapse-down
glyphicon glyphicon-collapse-up
glyphicon glyphicon-log-in
glyphicon glyphicon-flash
glyphicon glyphicon-log-out
glyphicon glyphicon-new-window
glyphicon glyphicon-record
glyphicon glyphicon-save
glyphicon glyphicon-open
glyphicon glyphicon-saved
glyphicon glyphicon-import
glyphicon glyphicon-export
glyphicon glyphicon-send
glyphicon glyphicon-floppy-disk
glyphicon glyphicon-floppy-saved
glyphicon glyphicon-floppy-remove
glyphicon glyphicon-floppy-save
glyphicon glyphicon-floppy-open
glyphicon glyphicon-credit-card
glyphicon glyphicon-transfer
glyphicon glyphicon-cutlery
glyphicon glyphicon-header
glyphicon glyphicon-compressed
glyphicon glyphicon-earphone
glyphicon glyphicon-phone-alt
glyphicon glyphicon-tower
glyphicon glyphicon-stats
glyphicon glyphicon-sd-video
glyphicon glyphicon-hd-video
glyphicon glyphicon-subtitles
glyphicon glyphicon-sound-stereo
glyphicon glyphicon-sound-dolby
glyphicon glyphicon-sound-5-1
glyphicon glyphicon-sound-6-1
glyphicon glyphicon-sound-7-1
glyphicon glyphicon-copyright-mark
glyphicon glyphicon-registration-mark
glyphicon glyphicon-cloud-download
glyphicon glyphicon-cloud-upload
glyphicon glyphicon-tree-conifer
glyphicon glyphicon-tree-deciduous
glyphicon glyphicon-cd
glyphicon glyphicon-save-file
glyphicon glyphicon-open-file
glyphicon glyphicon-level-up
glyphicon glyphicon-copy
glyphicon glyphicon-paste
glyphicon glyphicon-alert
glyphicon glyphicon-equalizer
glyphicon glyphicon-king
glyphicon glyphicon-queen
glyphicon glyphicon-pawn
glyphicon glyphicon-bishop
glyphicon glyphicon-knight
glyphicon glyphicon-baby-formula
glyphicon glyphicon-tent
glyphicon glyphicon-blackboard
glyphicon glyphicon-bed
glyphicon glyphicon-apple
glyphicon glyphicon-erase
glyphicon glyphicon-hourglass
glyphicon glyphicon-lamp
glyphicon glyphicon-duplicate
glyphicon glyphicon-piggy-bank
glyphicon glyphicon-scissors
glyphicon glyphicon-bitcoin
glyphicon glyphicon-btc
glyphicon glyphicon-xbt
glyphicon glyphicon-yen
glyphicon glyphicon-jpy
glyphicon glyphicon-ruble
glyphicon glyphicon-rub
glyphicon glyphicon-scale
glyphicon glyphicon-ice-lolly
glyphicon glyphicon-ice-lolly-tasted
glyphicon glyphicon-education
glyphicon glyphicon-option-horizontal
glyphicon glyphicon-option-vertical
glyphicon glyphicon-menu-hamburger
glyphicon glyphicon-modal-window
glyphicon glyphicon-oil
glyphicon glyphicon-grain
glyphicon glyphicon-sunglasses
glyphicon glyphicon-text-size
glyphicon glyphicon-text-color
glyphicon glyphicon-text-background
glyphicon glyphicon-object-align-top
glyphicon glyphicon-object-align-bottom
glyphicon glyphicon-object-align-horizontal
glyphicon glyphicon-object-align-left
glyphicon glyphicon-object-align-vertical
glyphicon glyphicon-object-align-right
glyphicon glyphicon-triangle-right
glyphicon glyphicon-triangle-left
glyphicon glyphicon-triangle-bottom
glyphicon glyphicon-triangle-top
glyphicon glyphicon-console
glyphicon glyphicon-superscript
glyphicon glyphicon-subscript
glyphicon glyphicon-menu-left
glyphicon glyphicon-menu-right
glyphicon glyphicon-menu-down
glyphicon glyphicon-menu-up
Tip:Bootstrap icons are provided by Glyphicons. However you are free to use these icons in your project but as a courtesy you can consider to
include a link back to Glyphicons whenever practical.
"glyphicon-class-name" is the name of the particular icon class (e.g. glyphicon-search, glyphiconuser, glyphicon-star etc.) defined in bootstrap.css.
Where
For example, to use search icon you can place the following code just about anywhere:
Example
The output of the above example will look something like this:
Check out the next chapter to see how to use these icons in Bootstrap nav components.
</span> tag) when using icons along with the strings of text such as inside buttons or navigation links, to ensure proper spacing.
In this tutorial you will learn how to create Bootstrap nav components.
.nav class.
Example
Try this code
1.
2.
3.
4.
5.
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
The output of the above example will look something like this:
Example
The output of the above example will look something like this:
Example
The output of the above example will look something like this:
.nav-stacked to
<ul> element.
Example
Try this code
1.
2.
3.
4.
5.
The output of the above example will look something like this:
Example
Try this code
<ul class="nav nav-tabs">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Messages <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Inbox</a></li>
<li><a href="#">Drafts</a></li>
<li><a href="#">Sent Items</a></li>
<li class="divider"></li>
<li><a href="#">Trash</a></li>
</ul>
</li>
</ul>
The output of the above example will look something like this:
Example
Try this code
The output of the above example will look something like this:
.nav-justified.
Example
Try this code
<!-- Justified tabs -->
<ul class="nav nav-tabs nav-justified">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Messages</a></li>
</ul>
<!-- Justified pills -->
<ul class="nav nav-pills nav-justified">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Messages</a></li>
</ul>
.disabled.
Example
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Messages</a></li>
<li class="disabled"><a href="#">Admin</a></li>
</ul>
Note:The Bootstrap .disabled class only changes the visual appearance of the link by making it gray and removing the hover effect, however
the link will remain clickable unless you remove the
"href" attribute.
In this tutorial you will learn how to create the static and fixed navigation headers using the Bootstrap
navbar component.
The output of the above example will look something like this:
You can also include dropdowns and search form within navbars.
Example
Try this code
<nav role="navigation" class="navbar navbar-default">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand">Brand</a>
</div>
<!-- Collection of nav links, forms, and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">Messages <b class="caret"></b></a>
<ul role="menu" class="dropdown-menu">
<li><a href="#">Inbox</a></li>
<li><a href="#">Drafts</a></li>
<li><a href="#">Sent Items</a></li>
<li class="divider"></li>
<li><a href="#">Trash</a></li>
</ul>
</li>
</ul>
<form role="search" class="navbar-form navbar-left">
<div class="form-group">
<input type="text" placeholder="Search" class="form-control">
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Login</a></li>
</ul>
</div>
</nav>
The output of the above example will look something like this:
Add an extra class .navbar-fixed-top in addition to the .navbar and .navbardefaultbase class to create navbars that is fixed on the top.
Example
Try this code
<nav role="navigation" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="#" class="navbar-brand">Brand</a>
</div>
<!-- Collection of nav links and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li><a href="#">Messages</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Login</a></li>
</ul>
</div>
</div>
</nav>
custom style sheet after the core Bootstrap CSS file, otherwise it may not
work.
You can also create full-width navbar that appears on the top but scrolls
away with the page by adding the class .navbar-static-top. Unlike the .navbarfixed-top class, you do not need to change any padding on
the <body> element.
Example
Search form is very common component of the navbars and you have
seen it on various website quite often. Search form can be placed inside
the navbar using the class .navbar-form on the <form> element.
Example
Try this code
You can also create inverted variation of the Bootstrap navbar by adding
an extra class.navbar-inverse to the .navbar base class, without any further
change in markup.
Example
Try this code
The output of the above example will look something like this:
In this tutorial you will learn how to create panels with Bootstrap.
Sometimes you might require to put your content in box for certain reason. In such situation the Bootstrap panel component can be very useful. In
most basic form the panel component applies some
Example
The output of the above example will look something like this:
.panel-heading class.
Example
Try this code
1.
2.
3.
4.
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
6.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
9.
The output of the above example will look something like this:
.panel-primary, .panel-success, .panel-info, .panelwarning, or .panel-danger on the panel components to make it more meaningful and drawing attention of the user.
Like other component you also add contextual state classes like
Example
Try this code
The output of the above example will look something like this:
Example
<td>Carter</td>
<td>johncarter@mail.com</td>
</tr>
<tr>
<td>2</td>
<td>Peter</td>
<td>Parker</td>
<td>peterparker@mail.com</td>
</tr>
<tr>
<td>3</td>
<td>John</td>
<td>Rambo</td>
<td>johnrambo@mail.com</td>
</tr>
</tbody>
</table>
</div>
Similarly you can include full-width list groups within any panel.
Example
Try this code
In this tutorial you will learn how to create breadcrumbs with Bootstrap.
Example
<ul class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Products</a></li>
<li class="active">Accessories</li>
</ul>
The output of the above example will look something like this:
In this tutorial you will learn how to create pagination with Bootstrap.
Pagination is used in some or other form quite often in almost every web application, for instance it is used by search engines for displaying a
limited number of results on search results pages, or showing a limited number of posts for every page on a blog or forum.
Example
<ul class="pagination">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
The output of the above example will look something like this:
.disabled for making the links unclickable and .active to indicate the current
page.
Example
Try this code
<ul class="pagination">
<li class="disabled"><a href="#">«</a></li>
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
The output of the above example will look something like this:
Note:The .disabled class only displays links as it disabled it doesn't remove the click functionality, to do this you can swap active or disabled
anchors with spans.
Example
<ul class="pagination">
<li class="disabled"><span>«</span></li>
<li class="active"><span>1</span></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
smaller pagination.
Example
Try this code
The output of the above example will look something like this:
Bootstrap Pager
Sometimes you may simply require previous and next links on your website to provide simple and quick navigation to the user instead of the
complex pagination as we discussed above.
.pager.
Example
<ul class="pager">
<li><a href="#">Previous</a></li>
<li><a href="#">Next</a></li>
</ul>
The output of the above example will look something like this:
Alignment of Pager
By default pager are aligned horizontally center but you align previous link to left and next link right using the
class
Example
Try this code
1.
2.
3.
4.
<ul class="pager">
<li class="previous"><a href="#">← Previous</a></li>
<li class="next"><a href="#">Next →</a></li>
</ul>
The output of the above example will look something like this:
Example
<ul class="pager">
<li class="previous disabled"><a href="#">← Previous</a></li>
<li class="next"><a href="#">Next →</a></li>
</ul>
The output of the above example will look something like this:
In this tutorial you will learn how to create inline labels and badges with Bootstrap.
The following example will show you how to create inline labels using the Bootstrap.
Example
<h1>Bootstrap
<h2>Bootstrap
<h3>Bootstrap
<h4>Bootstrap
<h5>Bootstrap
<h6>Bootstrap
heading
heading
heading
heading
heading
heading
<span
<span
<span
<span
<span
<span
class="label
class="label
class="label
class="label
class="label
class="label
label-default">New</span></h1>
label-default">New</span></h2>
label-default">New</span></h3>
label-default">New</span></h4>
label-default">New</span></h5>
label-default">New</span></h6>
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
6.
<span
<span
<span
<span
<span
<span
class="label
class="label
class="label
class="label
class="label
class="label
label-default">Default</span>
label-primary">Primary</span>
label-success">Success</span>
label-info">Info</span>
label-warning">Warning</span>
label-danger">Danger</span>
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
The output of the above example will look something like this:
In this tutorial you will learn how to create progress bars using Bootstrap.
Example
<div class="progress">
<div class="progress-bar" style="width: 60%;">
<span class="sr-only">60% Complete</span>
</div>
</div>
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
<div class="progress">
<div class="progress-bar" style="width: 60%;">
60%
</div>
</div>
The output of the above example will look something like this:
min-width to the progress bar to ensure that the label text remains readable even
Example
<div class="progress">
<div class="progress-bar" style="min-width: 20px;">
0%
</div>
</div>
<div class="progress">
<div class="progress-bar" style="min-width: 20px; width: 2%;">
2%
</div>
</div>
Example
The output of the above example will look something like this:
Warning:The stripped progress bar uses a gradient to create the striped effect. The stripped progress bar is not supported in IE7-8.
Similarly you can create the animated progress bar just add the
Example
Try this code
1.
2.
3.
4.
5.
Warning:Due to lack of support for CSS3 animation properties the animated progress bar is not supported in any versions of IE upto IE9.
Example
<div class="progress">
<div class="progress-bar progress-bar-success" style="width: 40%">
<span class="sr-only">Program Files (40%)</span>
</div>
<div class="progress-bar progress-bar-warning" style="width: 25%">
<span class="sr-only">Residual Files (25%)</span>
</div>
<div class="progress-bar progress-bar-danger" style="width: 15%">
<span class="sr-only">Junk Files (15%)</span>
</div>
</div>
The output of the above example will look something like this:
Bootstrap also provides some emphasis utility classes for progress bars that can be further used to convey meaning through color.
Example
Try this code
<div class="progress">
<div class="progress-bar progress-bar-info" style="width: 20%">
<span class="sr-only">20% Used</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-success" style="width: 40%">
<span class="sr-only">40% Used</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-warning" style="width: 80%">
<span class="sr-only">80% Used</span>
</div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-danger" style="width: 90%">
<span class="sr-only">90% Used</span>
</div>
</div>
The output of the above example will look something like this:
Example
The output of the above example will look something like this:
In this tutorial you will learn about the Bootstrap helper classes.
Contextual Colors
You can use the contextual color classes like
Contextual Backgrounds
Similar to the contextual text color classes, you can use the contextual background color classes to set the
background-color of an
Example
Try this code
1.
2.
3.
4.
5.
<p
<p
<p
<p
<p
The output of the above example will look something like this:
Note:The contextual background classes only apply the CSS background-colorproperty on the element. To adjust the space between
content and border-box you have to set the CSS
Close Icon
Bootstrap provides a generic close icon that can be used for dismissing modals and alerts.
Example
Try this code
1.
2.
3.
4.
The output of the above example will look something like this:
Caret Icon
Bootstrap provides a generic caret icon to indicate the dropdown functionality. The direction of the caret icon will reverse automatically in dropup
menus.
Example
Try this code
<ul class="nav nav-pills">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Services <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Design</a></li>
<li><a href="#">Development</a></li>
</ul>
</li>
</ul>
The output of the above example will look something like this:
.center-block to align the content block horizontally center. However, to see the effect of this class you have
to set the width of the content block yourself and it should be less than the containing parent element.
Example
<div class="wrapper">
<div class="center-block">Center Aligned DIV Box</div>
</div>
See the tutorial on CSS alignment to learn more about aligning the elements.
Quick Floats
You can quickly float an element to the left or right using the
Clearfix
The
.clearfix class clears the float on any element. This class is widely used for fixing thecollapsing parent issue, where parent element
Example
See the tutorial on CSS alignment to learn more about clearing floats on an element.
You can force an element to be shown or hidden on all the devices using the
CSS
.invisible to toggle only the visibility of an element; however the element still occupies the space in the
layout.
Example
Example
Try this code
1.
2.
Example
Warning:Think twice before using this class, because it uses the color:transparent and font-size:0px to hide the text. Search
engines consider such techniques as spam that may result in penalty.
In this tutorial you will learn how to use Bootstrap utility components.
Jumbotron
The Bootstrap jumbotron component provides an excellent way to showcase the key content or information on a web page. Just wrap your featured
content like heading, descriptions etc. in a
Example
Try this code
1.
2.
3.
4.
5.
<div class="jumbotron">
<h1>Learn to Create Websites</h1>
<p>In today's world internet is the most popular way</p>
<p><a href="#" class="btn btn-primary btn-lg">Learn more</a></p>
</div>
The output of the above example will look something like this:
To create a jumbotron without rounded corners and that covers the full width of the viewport, place it outside the all containers and add
the
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<div class="jumbotron">
<div class="container">
<h1>Learn to Create Websites</h1>
<p>In today's world internet is the most popular way</p>
<p><a href="#" class="btn btn-primary btn-lg">Learn more</a></p>
</div>
</div>
Wells Component
You can give a simple inset effect to the element by using the Bootstrap
.well class.
Example
Try this code
1.
2.
3.
<div class="well">
Look, I'm in a well!
</div>
The output of the above example will look something like this:
Tip:You can further control the padding and rounded corners of wells with two optional modifier classes
In this tutorial you will learn how to create and modify buttons with Bootstrap.
The following table lists the different buttons which are available in the Bootstrap:
Button
Class
Description
btn btndefault
btn btnprimary
btn btninfo
Can be used as an
alternative to the default
button.
btn btnsuccess
Indicates a successful or
positive action.
btn btnwarning
btn btndanger
Indicates a dangerous or
potentially negative
action.
btn btnlink
Deemphasize a button by
making it look like a link
while maintaining button
behavior.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<button
<button
<button
<button
<button
<button
type="button"
type="button"
type="button"
type="button"
type="button"
type="button"
class="btn
class="btn
class="btn
class="btn
class="btn
class="btn
btn-primary">Primary</button>
btn-info">Info</button>
btn-success">Success</button>
btn-warning">Warning</button>
btn-danger">Danger</button>
btn-link">Link</button>
Warning:Internet Explorer 9 doesn't crop background gradients on rounded corners, so gradient is removed from buttons.
.btn-
Example
<p>
<button
<button
</p>
<p>
<button
<button
</p>
<p>
<button
<button
</p>
<p>
<button
<button
</p>
The output of the above example will look something like this:
You can also create block level buttons (buttons that covers the full width of the parent elements) by adding an extra class
Example
Try this code
1.
2.
The output of the above example will look something like this:
.btn-block.
Example
The output of the above example will look something like this:
Note:The .disabled class only changes the visual appearance of the link by making it gray and removing the hover effect, however the link will
remain clickable unless you remove the
"href" attribute. Alternatively, you could implement custom JavaScript to prevent those clicks.
<button> or <input> tag can be disabled by adding the "disabled"attribute to the respective element.
Example
The output of the above example will look something like this:
text="Loading..." to a button.
data-loading-
Example
Try this code
1.
The output of the above example will look something like this:
Note:Mozilla firefox persists the disabled state across page loads, to prevents this behavior, you may simply set
autocomplete="off" on
the form containing the buttons, or directly to the input or button element.
data-toggle="button".
Example
Try this code
1.
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
<div class="btn-group">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
The output of the above example will look something like this:
You can also make the button groups appear vertically stacked rather than horizontally. To do this just replace the class
the
.btn-group-vertical.
.btn-group with
Example
Try this code
1.
2.
3.
4.
5.
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">Top</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Bottom</button>
</div>
data-toggle="buttons" to a group of checkboxes for checkbox style toggling on button groups, like this:
Example
The output of the above example will look something like this:
Example
Try this code
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="checkbox" name="options"> Option 1
</label>
<label class="btn btn-primary">
<input type="checkbox" name="options"> Option 2
</label>
<label class="btn btn-primary active">
<input type="checkbox" name="options"> Option 3
</label>
</div>
data-toggle="buttons" to a group of radio inputs for radio style toggling on button groups, like
this:
Example
Try this code
</label>
<label class="btn btn-primary">
<input type="radio" name="options"> Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options"> Option 3
</label>
</div>
The output of the above example will look something like this:
Example
Try this code
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary active">
<input type="radio" name="options"> Option 1
</label>
<label class="btn btn-primary">
<input type="radio" name="options"> Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options"> Option 3
</label>
</div>
Example
Try this code
<div class="btn-toolbar">
<div class="btn-group">
<button type="button"
<button type="button"
<button type="button"
<button type="button"
</div>
<div class="btn-group">
<button type="button"
<button type="button"
<button type="button"
</div>
<div class="btn-group">
<button type="button"
</div>
</div>
class="btn
class="btn
class="btn
class="btn
btn-primary">1</button>
btn-primary">2</button>
btn-primary">3</button>
btn-primary">4</button>
class="btn btn-primary">5</button>
class="btn btn-primary">6</button>
class="btn btn-primary">7</button>
class="btn btn-primary">8</button>
The output of the above example will look something like this:
larger or smaller button groups. Just add these button sizing classes directly to the
Example
Try this code
<div class="btn-toolbar">
<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
</div>
<div class="btn-toolbar">
<div class="btn-group">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
</div>
<div class="btn-toolbar">
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
</div>
<div class="btn-toolbar">
<div class="btn-group btn-group-xs">
<button type="button" class="btn btn-primary">Left</button>
<button type="button" class="btn btn-primary">Middle</button>
<button type="button" class="btn btn-primary">Right</button>
</div>
</div>
The output of the above example will look something like this:
Example
Try this code
1.
2.
3.
4.
5.
The output of the above example will look something like this:
<a> element.
.btn-group-
<button> elements, you must wrap each button individually in a .btn-group class,
Example
Try this code
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="button" class="btn btn-primary">Left</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary">Middle</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary">Right</button>
</div>
</div>
Example
<script type="text/javascript">
$(document).ready(function(){
$(".nav-tabs a").click(function(){
$(this).button('loading').delay(500).queue(function(){
$(this).button('reset');
$(this).dequeue();
});
});
});
</script>
Options
None
Methods
These are the standard bootstrap's buttons methods:
$().button('toggle')
This method toggles push state of the button. It changes the appearance of the button, and makes it look like that it has been activated. You can
also enable auto toggling of a button by using the
Example
<script type="text/javascript">
"data-toggle" attribute.
2.
3.
4.
5.
6.
7.
$(document).ready(function(){
$("#myButton").click(function(){
$(this).button('toggle');
});
});
</script>
$().button('loading')
This method sets the button state to loading. When loading, the button is disabled and the text is swapped with the value of
<script type="text/javascript">
$(document).ready(function(){
$("#myButton").click(function(){
$(this).button('loading');
});
});
</script>
$().button('reset')
This method resets button state by swapping text to original text.
Example
Try this code
<script type="text/javascript">
$(document).ready(function(){
$("#myButton").click(function(){
$(this).button('loading').delay(1000).queue(function(){
$(this).button('reset');
$(this).dequeue();
});
});
});
</script>
$().button(string)
This method resets button state by swapping text to any data defined text state.
Example
Try this code
<script type="text/javascript">
$(document).ready(function(){
$("#myButton").click(function(){
$(this).button('loading').delay(1000).queue(function() {
$(this).button('complete');
$(this).dequeue();
});
});
});
</script>
"data-loading-
In this tutorial you will learn how to add dropdown menus to various components using the Bootstrap
dropdown plugin.
You can use the Bootstrap dropdown component to add toggleable dropdown menus (i.e. open and close on click) to almost anything such as
buttons, navbar, tabs and pills nav etc. without even writing a single line of JavaScript code.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<div class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
</ul>
</div>
The above example demonstrates the most basic form of the Bootstrap dropdowns. Let's understand each part of the Bootstrap dropdown
component one by one.
Explanation of Code
The Bootstrap dropdown has basically two components the dropdown trigger element which can be a hyperlink or button, and the dropdown
menu itself.
dropdown menu.
.dropdown-menu is actually building the dropdown menu that typically contains the related
links or actions.
The previous example code has one small problem. If you click the dropdown link it will add a
dropdowns. If you want to keep your URLs intact use the
Example
<div class="dropdown">
<a data-target="#" href="page.html" data-toggle="dropdown" class="dropdown-toggle">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
</ul>
</div>
Similarly, you can add the dropdowns to the buttons and nav components. The following section will show you some common implementation of the
Bootstrap dropdown.
Example
Try this code
<div class="navbar navbar-static">
<div class="navbar-inner">
<a href="#" class="brand">Brand</a>
<ul role="navigation" class="nav">
<li><a href="#">Home</a></li>
<li><a href="#">Profile</a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Messages <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Inbox</a></li>
<li><a href="#">Drafts</a></li>
<li><a href="#">Sent Items</a></li>
<li class="divider"></li>
<li><a href="#">Trash</a></li>
</ul>
</li>
</ul>
<ul class="nav pull-right">
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">Admin <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Settings</a></li>
</ul>
</li>
</ul>
</div>
</div>
The output of the above example will look something like this:
Tip:You can draw a divider line to separate the links inside a dropdown menu by adding the class
Example
The output of the above example will look something like this:
You can simply convert the above example to a tab dropdown by replacing the class
change in markup.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
9.
<div class="btn-group">
<button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Action <span
class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
The output of the above example will look something like this:
Example
Try this code
<div class="btn-group">
<button type="button" class="btn btn-default">Action</button>
<button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
The output of the above example will look something like this:
Tip:You can use the Bootstrap's button relative sizing classes like
dropdowns.
Example
<div class="btn-group">
<button type="button" class="btn btn-primary">Button</button>
<button type="button" class="btn btn-primary">Another Button</button>
<div class="btn-group">
<button type="button" data-toggle="dropdown" class="btn btn-primary dropdown-toggle">Dropdown <span
class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
</div>
The output of the above example will look something like this:
Similarly, you can crate dropdown inside vertically stacked button groups, like this:
Example
Try this code
<div class="btn-group-vertical">
<button type="button" class="btn btn-primary">Button</button>
<button type="button" class="btn btn-primary">Another Button</button>
<div class="btn-group">
<button type="button" data-toggle="dropdown" class="btn btn-primary dropdown-toggle">Dropdown <span
class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</div>
</div>
Example
Try this code
The output of the above example will look something like this:
.dropdown-
Example
<div class="btn-group">
<button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Products <span
class="caret"></span></button>
<ul class="dropdown-menu">
<li class="dropdown-header">ELECTRONICS</li>
<li><a href="#">Mobiles</a></li>
<li><a href="#">Tablets</a></li>
<li><a href="#">Laptops</a></li>
<li class="dropdown-header">FASHION</li>
<li><a href="#">Clothing</a></li>
<li><a href="#">Sunglasses</a></li>
</ul>
</div>
.disabled on a list element to make the menu item look like disabled. However, the link is still clickable, to disable this
href attribute either using the JavaScript or manually.
Example
<div class="btn-group">
<button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Report <span
class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">View</a></li>
<li><a href="#">Download</a></li>
<li class="disabled"><a href="#">Edit / Delete</a></li>
</ul>
</div>
You may also add dropdowns manually using the JavaScript just call the
the
Example
Try this code
1.
2.
3.
4.
5.
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown-toggle").dropdown();
});
</script>
Note:The data-toggle="dropdown" is still required for the dropdown's trigger element regardless of whether you call the dropdown
via JavaScript or data-api.
Options
None
Methods
This is the standard bootstrap's dropdown method:
$().dropdown('toggle')
A programmatic api for toggling menus for a given navbar or tabbed navigation.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown-toggle").dropdown('toggle');
});
</script>
Events
These are the standard Bootstrap events to enhance the dropdown functionality. All dropdown events are fired at the
parent element.
Event
Description
.dropdown-menu's
Event
Description
The following example displays the text content of dropdown link when the users click on it.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$(".dropdown").on("show.bs.dropdown", function(e){
var linkText = $(e.relatedTarget).text(); // Get the link text
alert("Click on OK button to view the dropdown menu for - " + linkText);
});
});
</script>
In this tutorial you will learn how to create tooltips with Bootstrap.
Tooltips can be very helpful for the new visitors of your website because they enable the user to know the purpose of icons and links by placing the
mouse pointer over them.
tooltip() Bootstrap method with the"id" or "class" selector of the target element
Example
Try this code
1.
2.
3.
4.
5.
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
The output of the above example will look something like this:
Note:For performance reasons, the tooltip and popover data-apis are opt in, means to use tooltips and popovers you must initialize them yourself.
Example
Try this code
1.
2.
3.
4.
<a
<a
<a
<a
href="#"
href="#"
href="#"
href="#"
data-toggle="tooltip"
data-toggle="tooltip"
data-toggle="tooltip"
data-toggle="tooltip"
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$(".tip-top").tooltip({placement : 'top'});
$(".tip-right").tooltip({placement : 'right'});
$(".tip-bottom").tooltip({placement : 'bottom'});
$(".tip-left").tooltip({ placement : 'left'});
});
</script>
Options
There are certain options which may be passed to
Name
Type
Default Value
html
bool false
ean
Name
Type
Default Value
Description
display on the
bottom.
select strin false
or
g
If a selector is
provided, tooltip
objects will be
attached to the
specified targets.
title
Sets the
default title value
if title attribute
isn't present.
strin ''
g|
funct
ion
delay num 0
ber |
obje
ct
Time to delay in
showing and
hiding the tooltip
(ms) does not
apply to manual
trigger type.
If a number is
supplied, delay is
applied to both
hide/show Object
structure is:
delay: {show: 500,
hide: 100}
Appends the
tooltip to a specific
elementcontainer:
Name
Type
Default Value
Description
'body'
templ strin
'<div
ate
g
class="tooltip"
role="tooltip"><
div
class="tooltiparrow"></div><
div
class="tooltipinner"></div></
div>'
Base HTML to
use when
creating the
tooltip. The
tooltip's title will
be inserted into
the element
having the
class .tooltip-inner
and the element
with the
class .tooltip-arrow
will become the
tooltip's arrow.
The outermost
wrapper element
should have
the .tooltip class.
You may set these options either through the use of data attributes or JavaScript. For setting the tooltips options via data attributes, just append the
option name to
data- along with the correct value, like data-animation="false", data-placement="bottom" etc.
However, JavaScript is the more preferable way for setting these options as it prevents you from repetitive work. See the tooltip's method
().tooltip(options) in the section below to know how to set the options for tooltips using the JavaScript.
Methods
These are the standard Bootstrap's tooltip methods:
$().tooltip(options)
This method attaches the tooltip handler to a group of elements. It also allows you to set the options for the tooltips, so that you can customize
them according to your needs.
The following example will insert the specified text inside the tooltips if the value of the
elements:
Example
<script type="text/javascript">
$(document).ready(function(){
$("#myTooltips a").tooltip({
title: 'It works in absence of title attribute.'
});
});
</script>
The following example will show you how to place the HTML content inside a tooltip:
Example
<script type="text/javascript">
$(document).ready(function(){
$("#myTooltip").tooltip({
title: "<h4><img src='images/smiley.png' alt='Smiley'> Hello, <b>I'm</b> <i>Smiley!</i></h4>",
html: true
});
});
</script>
The following example will show you how to control the timing of showing and hiding of the tooltip using the tooltip's
Example
Try this code
<script type="text/javascript">
$(document).ready(function(){
// Showing and hiding tooltip with same speed
$(".tooltip-tiny").tooltip({
delay: 100
});
The following example will show you how you can create your own custom template for the Bootstrap tooltips instead of using the default one.
Example
<script type="text/javascript">
$(document).ready(function(){
$("#myTooltips a").tooltip({
template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-head"><h3><span class="glyphicon
glyphicon-info-sign"></span> Tool Info</h3></div><div class="tooltip-inner"></div></div>'
});
});
</script>
The following example will insert the dynamically generated HTML code of the tooltip at the end of a
the
<body> element.
Example
1.
2.
3.
4.
5.
6.
<script type="text/javascript">
$(document).ready(function(){
// Append tooltip HTML to wrapper element
$("#myTooltips a").tooltip({container: ".wrapper"});
});
</script>
Note:Overriding the tooltip's default container option value does not produce any visible difference on the page. To see the actual result you
need inspect the resulting DOM using the Firebug or Developer tools.
Similarly, you can set other options for the tooltips using the
Bootstrap tooltip plugin.
.tooltip('show')
This method reveals an element's tooltip.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".show-tooltip").click(function(){
$("#myTooltip").tooltip('show');
});
});
</script>
.tooltip('hide')
This method hides an element's tooltip.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".hide-tooltip").click(function(){
$("#myTooltip").tooltip('hide');
});
});
</script>
.tooltip('toggle')
This method toggles an element's tooltip.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".toggle-tooltip").click(function(){
$("#myTooltip").tooltip('toggle');
});
});
</script>
.tooltip('destroy')
This method hides and destroys an element's tooltip.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".destroy-tooltip").click(function(){
$("#myTooltip").tooltip('destroy');
});
});
</script>
Events
Bootstrap's tooltip class includes few events for hooking into tooltip functionality.
Event
Description
The following example will display an alert message to the user when the fade out transition of the tooltip has been fully completed.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="tooltip"]').on('hidden.bs.tooltip', function(){
alert("Tooltip has been completely closed.");
});
});
</script>
In this tutorial you will learn how to create popovers with Bootstrap.
popover() Bootstrap method with the "id" or "class" selector of the required
Example
Try this code
1.
2.
3.
4.
5.
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
The output of the above example will look something like this:
Note:For performance reasons, the tooltip and popover data-apis are opt in, means to use tooltips and popovers you must initialize them yourself.
Example
Try this code
1.
2.
3.
4.
<button type="button" class="btn btn-primary" data-toggle="popover" data-placement="top" title="Popover title" datacontent="Default popover">Popover on top</button>
<button type="button" class="btn btn-success" data-toggle="popover" data-placement="right" title="Popover title" datacontent="Popover on right.">Popover on right</button>
<button type="button" class="btn btn-info" data-toggle="popover" data-placement="bottom" title="Popover title" datacontent="Popover on bottom.">Popover on bottom</button>
<button type="button" class="btn btn-warning" data-toggle="popover" data-placement="left" title="Popover title" datacontent="Popover on left.">Popover on left</button>
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$(".pop-top").popover({placement : 'top'});
$(".pop-right").popover({placement : 'right'});
$(".pop-bottom").popover({placement : 'bottom'});
$(".pop-left").popover({ placement : 'left'});
});
</script>
Example
Try this code
1.
<a href="#" class="btn btn-primary btn-lg" data-toggle="popover" tabindex="0" data-trigger="focus" title="Popover title" datacontent="Here's some amazing content.">Dismissible popover</a>
Note:To make this feature work properly across the browsers, you must use the<a> tag, not the <button> tag, and you also must include
a
tabindex attribute.
Options
There are certain options which may be passed to
Name
Type
Default Value
html
bool false
ean
Name
Type
Default Value
Description
Sets the
position of the
popover top |
bottom | left |
right | auto.
When "auto"
value is
specified, it will
dynamically
reorient the
popover.
For example, if
placement value
is "auto left",
the popover will
display to the
left when
possible,
otherwise it will
display to right.
If a selector is
provided,
popover objects
will be attached
to the specified
targets.
title
Sets the
default title value
if title attribute
isn't present.
strin ''
g|
func
tion
Specify how
popover is
triggered click
| hover | focus |
manual.
Name
Type
Default Value
tion
Description
ribute isn't
present.
delay num 0
ber |
obje
ct
Time to delay in
showing and
hiding the
popover (ms)
does not apply
to manual
trigger type.
If a number is
supplied, delay
is applied to
both hide/show
Object structure
is: delay: { show:
500, hide: 100 }
Appends the
popover to a
specific
elementcontainer:
'body'
templ strin
'<div
ate
g
class="popover">
<div
class="arrow"></
div><h3
class="popovertitle"></h3><div
class="popovercontent"></div><
/div>'
Base HTML to
use when
creating the
popover. The
popover's title
and content will
be inserted into
the elements
having the
class .popover-title
and .popovercontent respectiv
ely. Whereas the
element with
the
class .arrow will
Name
Type
Default Value
Description
become the
popover's arrow.
The outermost
wrapper
element should
have
the .popover clas
s.
viewp strin { selector: 'body',
padding: 0 }
ort
g|
obje
ct
Keeps the
popover within
the bounds of this
element.
Example: viewport
: '#viewport' or{
selector:
'#viewport',
padding: 0}
You may set these options either through the use of data attributes or JavaScript. For setting the popovers options via data attributes, just append
data- along with the correct value, like data-animation="false", dataplacement="bottom" etc.
the option name to
However, JavaScript is the more preferable way for setting these options as it saves you from doing the repetitive work. See the popover's
method
$().popover(options) in the section below to know how to set the options for popovers using the JavaScript.
Methods
These are the standard Bootstrap's popover methods:
$().popover(options)
This method attaches the popover handler to a group of elements. It also allows you to set the options for the popovers so that you can customize
them according to your needs.
The following example will insert the specified text inside the popovers title if the value of the
selected elements:
Example
Try this code
1.
2.
3.
4.
5.
6.
<script type="text/javascript">
$(document).ready(function(){
$("#myPopovers a").popover({
title: 'Default title value'
});
});
7.
</script>
The following jQuery code will trigger the popovers on mouse hover instead of click:
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover({
trigger: 'hover'
});
});
</script>
The following example will show you how to place the HTML content inside a popover:
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
9.
<script type="text/javascript">
$(document).ready(function(){
$("#myPopover").popover({
title: '<h3 class="custom-title"><span class="glyphicon glyphicon-info-sign"></span> Popover Info</h3>',
content: '<p>This is a <em>simple example</em> demonstrating how to insert HTML code inside <mark><strong>Bootstrap
popover</strong></mark>.</p>',
html: true
});
});
</script>
The following example will show you how to control the timing of showing and hiding of the popover using the popover's
JavaScript.
Example
<script type="text/javascript">
$(document).ready(function(){
// Showing and hiding popover with same speed
$(".popover-tiny").tooltip({
delay: 500
});
// Showing and hiding popover with different speed
$(".popover-large").tooltip({
delay: {show: 0, hide: 2000}
});
});
</script>
The following example will show you how you can create your own custom template for the Bootstrap popovers instead of using the default one.
Example
Try this code
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').popover({
html: true,
template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popovercontent"></div><div class="popover-footer"><a href="#" class="btn btn-info btn-sm">Close</a></div></div>'
});
// Custom jQuery to hide popover on click of the close button
$(document).on("click", ".popover-footer .btn" , function(){
$(this).parents(".popover").popover('hide');
});
});
</script>
The following example will insert the dynamically generated HTML code of the popover at the end of a
the
<body> element.
Example
Try this code
1.
2.
3.
4.
5.
6.
<script type="text/javascript">
$(document).ready(function(){
// Append popover HTML to wrapper element
$("#myPopovers a").popover({container: '.wrapper'});
});
</script>
Note:Overriding the popover's default container option value does not produce any visible difference on the page. To see the actual result you
need inspect the resulting DOM using the Firebug or Developer tools.
Similarly, you can set other options for the popovers using the
Bootstrap popover plugin.
.popover('show')
This method reveals an element's popover.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".show-popover").click(function(){
$("#myPopover").popover('show');
});
});
</script>
.popover('hide')
This method hides an element's popover.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".hide-popover").click(function(){
$("#myPopover").popover('hide');
});
});
</script>
.popover('toggle')
This method toggles an element's popover.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".toggle-popover").click(function(){
$("#myPopover").popover('toggle');
});
});
</script>
.popover('destroy')
This method hides and destroys an element's popover.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".destroy-popover").click(function(){
$("#myPopover").popover('destroy');
});
});
</script>
Events
Bootstrap's popover class includes few events for hooking into popover functionality.
Event
Description
The following example displays an alert message to the user when fade out transition of the popover has been fully completed.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$('[data-toggle="popover"]').on('hidden.bs.popover', function(){
alert("Popover has been completely closed.");
});
});
</script>
In this tutorial you will learn how to create alerts messages with Bootstrap.
With Bootstrap you can easily create elegant alert messages box for various purposes. You can also add an optional close button to dismiss any
alert.
Warning Alerts
You can create a simple Bootstrap warning alert message box by adding the contextual class
this:
Example
Try this code
1.
2.
3.
4.
The output of the above example will look something like this:
Tip:If you want to enable the fading transition effect while closing the alert boxes, apply the classes
contextual class.
Example
Example
Try this code
1.
2.
3.
4.
The output of the above example will look something like this:
Example
The output of the above example will look something like this:
Information Alerts
For information alert messages add the class
Example
Try this code
1.
2.
3.
4.
The output of the above example will look something like this:
Example
data-dismiss="alert" to the
Example
<script type="text/javascript">
$(document).ready(function(){
$(".close").click(function(){
$("#myAlert").alert();
});
});
</script>
Methods
These are the standard bootstrap's alerts methods:
$().alert()
This method wraps all alerts with close functionality.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".close").click(function(){
$(".alert").alert();
});
});
</script>
$().alert('close')
This method closes an alert message box.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".close").click(function(){
$("#myAlert").alert('close');
});
});
</script>
Events
Bootstrap's alert class includes few events for hooking into alert functionality.
Event
Description
Event
Description
ert
The following example displays an alert message to the user when fade out transition of an alert message box has been fully completed.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$("#myAlert").on('closed.bs.alert', function () {
alert("Alert message box has been closed.");
});
});
</script>
In this tutorial you will learn how to create dynamic tabs to toggle between the content using the
Bootstrap tabs plugin.
Example
Try this code
1.
2.
3.
4.
5.
The output of the above example will look something like this:
You can activate a tab component without writing any JavaScript simply specify the
a
Example
Try this code
You may also enable tabs via JavaScript. Each tab needs to be activated individually.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$("#myTab a").click(function(e){
e.preventDefault();
$(this).tab('show');
});
});
</script>
Example
Try this code
1.
2.
3.
4.
Methods
This is the standard bootstrap's tab method:
$().tab
Activates a tab element and the related content container. Tab should have either a data-target or an href for targeting a container node in the DOM.
Example
Try this code
1.
2.
3.
4.
5.
<script type="text/javascript">
$(document).ready(function(){
$("#myTab li:eq(1) a").tab('show');
})
</script>
Events
These are the standard Bootstrap events to enhance the tab functionality.
Event
Description
Event
Description
tab
The following example displays the names of active tab and previous tab to the user when transition of a tab has been fully completed.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$('a[data-toggle="tab"]').on('shown', function (e) {
e.target // active tab
e.relatedTarget // previous tab
})
});
</script>
In this tutorial you will learn how to create modals with Bootstrap.
You can easily create very smart and flexible dialog boxes with the Bootstrap modal plugin. The following example will show you how to create a
simple modal with a header, message body and the footer containing action buttons for the user.
Example
The above example launches the modal window when the DOM is fully loaded via JavaScript. The output will look something like this:
Example
Try this code
<!-- Button HTML (to Trigger Modal) -->
<a href="#myModal" role="button" class="btn btn-large btn-primary" data-toggle="modal">Launch Demo Modal</a>
The above example launches the modal window on click of the "Launch Demo Modal" button. Let's go through each part of this modal code one by
one for a better understanding.
Explanation of Code
To activate a Bootstrap modal via data attributes we basically need two components the controller element like a button or link, and the modal
element itself.
targeted via
.modal-header element defines a header for the modal that usually contains a modal title
.modal-body element contains the actual content like text, images, forms etc. and the .modal-
footer element defines the footer that typically contains action buttons for the user.
Note:The .fade class on the .modal element adds a fading and sliding animation effect while showing and hiding the modal window. If you
want the modal that simply appear without any effect you can just remove this class.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".btn").click(function(){
$("#myModal").modal('show');
});
});
</script>
lg or .modal-sm on .modal-dialog.
.modal-
Example
You can use the modal events to create slightly different modal windows based on the same modal HTML. The following example will change the title
of the modal window according to the trigger button's
Example
<script type="text/javascript">
$(document).ready(function(){
$("#myModal").on('show.bs.modal', function(event){
// Get button that triggered the modal
var button = $(event.relatedTarget);
// Extract value from data-* attributes
var titleData = button.data('title');
$(this).find('.modal-title').text(titleData + ' Form');
});
});
</script>
Options
There are certain options which may be passed to
Name
Type
Default Value
Description
backdr boolean
op
or the
string'static'
true
Includes a
modalbackdrop
(black overlay
area) element.
Alternatively,
you may
specify static f
or a backdrop
which doesn't
close the
modal on click.
keyboa boolean
rd
true
Closes the
modal window
on press of
escape key.
show
true
Shows the
modal when
initialized or
activate.
boolean
remote URL
false
If a
remote url is
provided,
content will be
loaded one
time via
jQuery's load
method and
injected into
the '.modalcontent' div.
Deprecated
You may set these options either through the use of data attributes or JavaScript. For setting the modals options via data attributes, just append the
option name to
However, JavaScript is the more preferable way for setting these options as it prevents you from repetitive work. See the modal's
method
.modal(options) in the section below to know how to set the options for modals using the JavaScript.
If you're using the data api for setting the options for modal window, you may alternatively use the "
Example
Try this code
<!-- Button HTML (to Trigger Modal) -->
<a href="remote.html" role="button" class="btn btn-large btn-primary" data-toggle="modal" data-target="#myModal">Launch Demo
Modal</a>
Note:The remote option for the Bootstrap modals is deprecated since v3.3.0 and will be removed in v4. Use the client-side templating or a data
binding framework instead, or call the
Methods
These are the standard bootstrap's modals methods:
.modal(options)
This method activates the content as a modal. It also allows you to set options for them.
The jQuery code in the following example will prevent the modal from closing when a user clicks on the backdrop i.e. black overlay area behind the
modal.
Example
Try this code
<script type="text/javascript">
$(document).ready(function(){
$(".launch-modal").click(function(){
$("#myModal").modal({
backdrop: 'static'
});
});
});
</script>
The following jQuery code will prevent the modal from closing on press of the escape key.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".launch-modal").click(function(){
$("#myModal").modal({
keyboard: false
});
});
});
</script>
The jQuery code in the following example will create a modal in which content of the modal will be inserted from a remote file upon activation.
Example
Try this code
<script type="text/javascript">
$(document).ready(function(){
$(".launch-modal").click(function(){
$("#myModal").modal({
remote: '../remote.php'
});
});
});
</script>
.modal('toggle')
This method toggles a modal window manually.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".toggle-modal").click(function(){
$("#myModal").modal('toggle');
});
});
</script>
.modal('show')
This method can be used to open a modal window manually.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".open-modal").click(function(){
$("#myModal").modal('show');
});
});
</script>
.modal('hide')
This method can be used to hide a modal window manually.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".hide-modal").click(function(){
$("#myModal").modal('hide');
});
});
</script>
.modal('handleUpdate')
This method readjusts the modal's position to counter the jerk that is occurring due to the appearance of the viewport scrollbar in case if the modal
height changes in such a way that it becomes higher than the viewport height while it is open.
Example
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$(".show-text").click(function(){
$('#myModal').find(".lots-of-text").toggle();
$('#myModal').modal('handleUpdate')
});
});
</script>
Events
Bootstrap's modal class includes few events for hooking into modal functionality.
Event
Description
The following example displays an alert message to the user when fade out transition of the modal window has been fully completed.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$("#myModal").on('hidden.bs.modal', function(){
alert("Modal window has been completely closed.");
});
});
</script>
In this tutorial you will learn how to create accordion with Bootstrap.
The following example will show you how to build a simple accordion widget using the Bootstrap collapsible plugin and the panel component.
Example
The output of the above example will look something like this:
Example
We've just created a collapsible control without writing any JavaScript code. Well, let's go through each part of this code one by one for a better
understanding.
Explanation of Code
The Bootstrap collapse plugin basically requires the two elements to work properly the controller element such as a button or hyperlink by clicking
on which you want to collapse the other element, and the collapsible element itself.
The data-toggle="collapse" attribute (line no-2) is added to the controller element along with a attribute datatarget (for buttons) or href (for anchors) to automatically assign the control of a collapsible element.
The data-target or href attribute accepts a CSS selector to apply the collapse to a specific element. Be sure to add the
class "collapse" to the collapsible element.
You can optionally add the class "in" (line no-4) to the collapsible element in addition to the class "collapse" to make it open by
default.
To make the collapsible controls to work in group like accordion menu, you can utilize theBootstrap panel component as demonstrated in the
previous example.
Example
Options
There are certain options which may be passed to
Name
Type
Default Value
Description
Name
Type
nt
or
Default Value
Description
Methods
These are the standard bootstrap's collapse methods:
.collapse(options)
This method activates your content as a collapsible element.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".btn").click(function(){
$("#myCollapsible").collapse({
toggle: false
});
});
});
</script>
.collapse('toggle')
This method toggles (show or hide) a collapsible element.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".toggle-btn").click(function(){
$("#myCollapsible").collapse('toggle');
});
});
</script>
.collapse('show')
This method shows a collapsible element.
Example
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".show-btn").click(function(){
$("#myCollapsible").collapse('show');
});
});
</script>
.collapse('hide')
This method hides a collapsible element.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".hide-btn").click(function(){
$("#myCollapsible").collapse('hide');
});
});
</script>
Events
Bootstrap's collapse class includes few events for hooking into collapse functionality.
Event
Description
The following example displays an alert message to the user when sliding transition of a collapsible element has been fully completed.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$("#myCollapsible").on('hidden.bs.collapse', function(){
alert("Collapsible element has been completely closed.");
});
});
</script>
In this tutorial you will learn how to create carousels with Bootstrap.
Example
The output of the above example will look something like this:
You can also add captions such as heading or description to the individual slides of the carousel, please check out the next example.
With Bootstrap you can create carousels very easily via data attributes without writing a single line of JavaScript code. Let's go through the following
example:
Example
Try this code
<div id="myCarousel" class="carousel slide" data-interval="3000" data-ride="carousel">
<!-- Carousel indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active">
<img src="images/slide1.png" alt="First Slide">
<div class="carousel-caption">
<h3>First slide label</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>
<div class="item">
<img src="images/slide2.png" alt="Second Slide">
<div class="carousel-caption">
<h3>Second slide label</h3>
<p>Aliquam sit amet gravida nibh, facilisis...</p>
</div>
</div>
<div class="item">
<img src="images/slide3.png" alt="Third Slide">
<div class="carousel-caption">
<h3>Third slide label</h3>
<p>Praesent commodo cursus magna vel...</p>
</div>
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
You might be wondering what this code was all about. Ok, let's go through each part of this carousel code one by one for a better understanding.
Explanation of Code
The Bootstrap carousel has basically three components carousel indicators (small circles), carousel controls (previous and next arrows) and the
carousel items or slides.
the carousel indicators (line no-4,5,6) and carousel controls (line no-33,36) to function properly.
data-ride="carousel" attribute of the .carousel element tells the Bootstrap to start animating the carousel
data-interval attribute specifies the time delay between two slides.
The .data-slide-to attribute (line no-4,5,6) move the slide position to a particular item (index beginning with 0) when clicking on
The
the
The slides are specified within the .carousel-inner (line no-9) and the content of each slide is defined within
.item element that can be text and images.
The data-slide attribute on carousel controls (line no-33,36) accepts the keywords "prev" or "next", which alters the slide
.carousel element specifies the Bootstrap carousel, the .carouselindicators element indicates how many slides are there in the carousel and which slide is currently active, the .carouselcaption element used within the.item element defines the caption for that slide etc.
Rest of the thing is self explanatory, such as the
Tip:It is required to add the class .active to one of the slides (i.e. on the .itemelement). Otherwise, the carousel will not be visible.
Note:The .slide class adds CSS slide transition animation to the carousel that makes the items slide when showing the new item. But it doesn't
work in Internet Explorer 8 & 9 due to lack of support of the necessary CSS3 properties.
Example
<script type="text/javascript">
$(document).ready(function(){
$("#myCarousel").carousel();
});
</script>
Options
There are certain options which may be passed to
Name
Type
Default Value
Description
pause
wrap
boole true
an
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$("#myCarousel").carousel({
interval : 3000,
pause: false
});
});
</script>
data-, like datainterval="3000", data-pause="hover" as demonstrated in the section of data attribute implementation.
You can also set these options using the data attributes on carousel just append the option name to
interval" option to "false" via JavaScript. You can also set this option using the data attribute likedatainterval="false" on the .carousel element.
setting the carousel "
Example
<script type="text/javascript">
$(document).ready(function(){
$("#myCarousel").carousel({
interval : false
});
});
</script>
Methods
These are the standard bootstrap's carousels methods:
.carousel(options)
This method initializes the carousel with optional options and starts cycling through items.
Example
<script type="text/javascript">
$(document).ready(function(){
$("#myCarousel").carousel({
interval : 3000
});
});
</script>
.carousel('cycle')
This method start carousel for cycling through the items from left to right.
Example
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".start-slide").click(function(){
$("#myCarousel").carousel('cycle');
});
});
</script>
.carousel('pause')
This method stops the carousel from cycling through items.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$(".pause-slide").click(function(){
$("#myCarousel").carousel('pause');
});
});
</script>
.carousel(number)
This method cycles the carousel to a particular frame (start with
Example
<script type="text/javascript">
$(document).ready(function(){
$(".slide-three").click(function(){
$("#myCarousel").carousel(3);
});
});
</script>
.carousel('prev')
This method cycles the carousel to the previous item.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".prev-slide").click(function(){
$("#myCarousel").carousel('prev');
});
});
</script>
.carousel('next')
This method cycles the carousel to the next item.
Example
<script type="text/javascript">
$(document).ready(function(){
$(".next-slide").click(function(){
$("#myCarousel").carousel('next');
});
});
</script>
0, similar to an array).
Events
Bootstrap's carousel class includes few events for hooking into carousel functionality.
Event
Description
The following example displays an alert message to the user when sliding transition of a carousel item has been fully completed.
Example
<script type="text/javascript">
$(document).ready(function(){
$('#myCarousel').on('slid.bs.carousel', function () {
alert("The sliding transition of previous carousel item has been fully completed.");
});
});
</script>
In this tutorial you will learn how to create typeaheads with Bootstrap.
Note:Typeahead plugin has been dropped from the latest version of Bootstrap (v3.0+), in favor of using Twitter typeahead.
Twitter typeaheads is a fast and fully-featured autocomplete library inspired by twitter.com's autocomplete search functionality. To create Twitter
typeaheads first download typeahead.jsfrom GitHub and include in your project after that you can turns any text-based
(i.e.
<input>element
Example
<script type="text/javascript">
$(document).ready(function(){
$('input.typeahead').typeahead({
name: 'accounts',
local: ['Audi', 'BMW', 'Bugatti', 'Ferrari', 'Ford', 'Lamborghini', 'Mercedes Benz', 'Porsche', 'Rolls-Royce', 'Volkswagen']
});
});
</script>
The output of the above example will look something like this:
Tip:Set autocomplete="off" for the input box if you want to prevent default browser menus from appearing over the Bootstrap typeahead dropdown.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
9.
<script type="text/javascript">
$(document).ready(function(){
$('input.typeahead').typeahead({
name: 'countries',
prefetch: 'data/countries.json',
limit: 10
});
});
</script>
In this tutorial you will learn how to create scrollspy with Bootstrap.
Example
Note:The Bootstrap scrollspy plugin requires the use of a Bootstrap nav component (e.g. navbar, nav tabs or pills) for proper highlighting of active
links.
Example
You might be thinking what this code was all about. Ok, let's go through each part of this scrollspy code one by one for a better understanding.
Explanation of Code
The Bootstrap scrollspy has basically two components the target nav (e.g. navbar, nav tabs or pills) and the scrollable area to spy on, which is
often the
<body> section.
The data-spy="scroll" attribute (line no-01) is applied to the scrollable element that is being spied on, which is
<body> element.
The data-target attribute is added on the scrollable element with the ID or class of the parent element of the
Bootstrap .nav component so that nav links can be targeted by the scrollspy for highlighting purpose.
The optional data-offset attribute specifies the number of pixels to offset from top when calculating the position of scroll. Adjust
the
the offset value if the targeted links are highlighting too early or too late. The default value is 10 pixels.
You may also add scrollspy manually using the JavaScript just call the
the
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$("body").scrollspy({
target: "#myNavbar",
offset: 70
})
});
</script>
Methods
These are the standard bootstrap's scrollspy methods:
.scrollspy('refresh')
When using scrollspy in conjunction with adding or removing of elements from the DOM, you'll need to call the refresh method like this:
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
<script type="text/javascript">
$(document).ready(function(){
$('[data-spy="scroll"]').each(function(){
var $spy = $(this).scrollspy('refresh');
});
});
</script>
Options
There are certain options which may be passed to
Name
Type
Default Value
offs numb 10
et
er
Description
You can also set this options for scrollspy using the data attributes just append the option name to
Events
Bootstrap's scrollspy class includes few events for hooking into scrollspy functionality.
Event
Description
The following example displays an alert message to the user when a new item becomes highlighted by the scrollspy.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
<script type="text/javascript">
$(document).ready(function(){
$("#myNavbar").on("activate.bs.scrollspy", function(){
var currentItem = $(".nav li.active > a").text();
$("#info").empty().html("Currently you are viewing - " + currentItem);
})
});
</script>
You can easily add affix behavior to any element just add dataspy="affix" to the element you want to spy on. Then use "dataoffset-" attributes to define when to toggle the pinning of an element 'on'
and 'off'.
Example
Try this code
1.
2.
3.
4.
5.
The "data-offset-" attributes only specify how many pixels that you must
scroll in order to toggle the pinning of an element, it did not set the
position of pinned element. You must define the top or bottom CSS property
for the pinned element specifically in your style sheet to set its position in
the viewport.
Note:
You may also enable the affix plugin manually using the JavaScript just
call the affix()method with the "id" or "class" selector of the required element
in your JavaScript code.
Example
Try this code
1.
2.
3.
4.
5.
6.
7.
8.
9.
<script type="text/javascript">
$(document).ready(function(){
$("#myNav").affix({
offset: {
top: 195
}
});
});
</script>
Options
There are certain options which may be passed to affix() Bootstrap method
to customize the functionality of the affix plugin.
Name
Type
Default Value
offs numbe 10
et
r|
functio
n|
object
Description
Specify the
number of pixels
to offset from
screen when
calculating
position of scroll.
If a single number
is provided, the
offset will be
applied in both
top and bottom
directions. To set
offset for a single
direction, or
multiple unique
offsets just
provide an object
likeoffset: {top:50,
bottom:100}
Name
Type
Default Value
Description
dynamically
provide an offset
in case of
responsive
designs.
targ selecto the windowob Specifies the target
et
r|
ject
element of the affix.
node |
jQuery
elemen
t
You can also set these options for affix using the data attributes just
append the option name to data-, like data-offset-top="195".
Events
Bootstrap's affix class includes few events for hooking into modal
functionality.
Event
Description
affix.bs.affix
affixed.bs.affix
affix-top.bs.affix
affixedtop.bs.affix
affixbottom.bs.affix
Event
Description
affixedbottom.bs.affix
<script type="text/javascript">
$(document).ready(function(){
$("#myNav").on('affixed.bs.affix', function(){
alert("The navigation menu has been affixed. Now it doesn't scroll with the page.");
});
});
</script>