Bootstrap Quick Guide

Overview

What is Twitter Bootstrap?

Bootstrap is a sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript.

History

Bootstrap was developed by Mark Otto and Jacob Thornton at Twitter. It was released as an open source product in August 2011 on GitHub.

Why use Bootstrap?

Mobile first approach: Since Bootstrap 3, the framework consists of Mobile first styles throughout the entire library instead of in separate files.

Browser Support: It is supported by all popular browsers.

Easy to get started: With just the knowledge of HTML and CSS anyone can get started with Bootstrap. Also the Bootstrap official site has a good documentation.

Responsive design: Bootstrap's responsive CSS adjusts to Desktops,Tablets and Mobiles. More about responsive design in the chapter Bootstrap Responsive Design

Provides a clean and uniform solution for building an interface for developers.

It contains beautiful and functional built-in components which are easy to customize.

It also provides web based customization.

And best of all it is an open source.

What Bootstrap Package Includes?

Scaffolding: Bootstrap provides a basic structure with Grid System, link styles, background. This is is covered in detail in the section Bootstrap Basic Structure

CSS: Bootstrap comes with feature of global CSS settings, fundamental HTML elements styled and enhanced with extensible classes, and an advanced grid system. This is covered in detail in the section Bootstrap with CSS.

Components: Bootstrap contains over a dozen reusable components built to provide iconography, dropdowns, navigation, alerts, popovers, and much more. This is covered in detail in the section Layout Components.

JavaScript Plugins: Bootstrap contains over a dozen custom jQuery plugins. You can easily include them all, or one by one. This is covered in details in the section Bootstrap Plugins.

Customize: You can customize Bootstrap's components, LESS variables, and jQuery plugins to get your very own version.

Environment Setup

It is very easy to setup and start using Bootstrap. This chapter will explain how to download and setup Bootstrap. It will also discuss the Bootstrap file structure, and demonstrate its usage with an example.

Download Bootstrap

You can download the latest version of Bootstrap from http://getbootstrap.com/. When you click on this link, you will get to see a screen as below:

Here you can see two buttons:

Download Bootstrap: Clicking this, you can download the precompiled and minified versions of Bootstrap CSS, JavaScript, and fonts. No documentation or original source code files are included.

Download Source: Clicking this, you can get the latest Bootstrap LESS and JavaScript source code directly from GitHub.

If you work with Bootstrap's uncompiled source code, you need to compile the LESS files to produce usable CSS files. For compiling LESS files into CSS, Bootstrap officially supports only Recess , which is Twitter's CSS hinter based on less.js.

For better understanding and ease of use, we shall use precompiled version of Bootstrap throughout the tutorial . As the files are complied and minified you don't have to bother every time including separate files for individual functionality. At the time of writing this tutorial the latest version (Bootstrap 3) was downloaded.

File structure

Precompiled Bootstrap

Once the compiled version Bootstrap is downloaded, extract the ZIP file, and you will see the following file/directory structure:

As you can see there are compiled CSS and JS (bootstrap.*), as well as compiled and minified CSS and JS (bootstrap.min.*). Fonts from Glyphicons are included, as is the optional Bootstrap theme.

Bootstrap Source Code

If you downloaded the Bootstrap source code then the file structure would be as follows:

The files under less/, js/, and fonts/ are the source code for Bootstrap CSS, JS, and icon fonts (respectively).

The dist/ folder includes everything listed in the precompiled download section above.

docs-assets/, examples/, and all *.html files are Bootstrap documentation.

Here you can see the jquery.js and bootstrap.min.js and bootstrap.min.css files are included to make a normal HTM file to Bootstrapped Template.

More details about each of the elements in this above piece of code will be discussed in the chapter Bootstrap CSS Overview.

This template structure is already included as part of the Try it tool. Hence in all the examples (in the following chapters) of this tutorial you shall only see the contents of the <body> element. Once you click on the Try it option available at the top right corner of example, you will see the entire code.

Example

Now let's try an example using the above template. Try following example using Try it option available at the top right corner of the below sample code box:

<h1>Hello, world!</h1>

Grid System

What is a Grid?

As put by wikepedia:

In graphic design, a grid is a structure (usually two-dimensional) made up of a series of intersecting straight (vertical, horizontal) lines used to structure content. It is widely used to design layout and content structure in print design. In web design, it is a very effective method to create a consistent layout rapidly and effectively using HTML and CSS.

What is Bootstrap Grid System?

As put by the official documentation of Bootstrap for grid system:

Bootstrap includes a responsive, mobile first fluid grid system that appropriately scales up to 12 columns as the device or viewport size increases. It includes predefined classes for easy layout options, as well as powerful mixins for generating more semantic layouts.

Let us understand the above statement. Bootstrap 3 is mobile first in the sense that the code for Bootstrap now starts by targeting smaller screens like mobile devices,tablets, and then “expands” components and grids for larger screens such as laptops, desktops.

Responsive column resets

With the four tiers of grids available you're bound to run into issues where, at certain breakpoints, your columns don't clear quite right as one is taller than the other. To fix that, use a combination of a class .clearfix and the responsive utility classes.

Offset columns

Offsets are a useful feature for more specialized layouts. They can be used to push columns over for more spacing, for example. The .col-xs=* classes don’t support offsets, but they are easily replicated by using an empty cell.

To use offsets on large displays, use the .col-md-offset-* classes. These classes increase the left margin of a column by * columns where * range from 1 to 11.

Nesting columns

To nest your content with the default grid, add a new .row and set of .col-md-* columns within an existing .col-md-* column. Nested rows should include a set of columns that add up to 12.

In the following example, the layout has two columns, with the second one being split into four boxes over two rows.

Column ordering

Another nice feature of Bootstrap grid system is that you can easily write the columns in an order, and show them in another one. You can easily change the order of built-in grid columns with .col-md-push-* and .col-md-pull-* modifier classes where * range from 1 to 11.

In the following example we have two-columns layout with left column being the narrowest and acting as sidebar. We will swap the order of these columns using .col-md-push-* and .col-md-pull-* classes.

CSS Overview

In this chapter we will see an overview of the key pieces of Bootstrap's infrastructure, including Bootstrap's approach to better, faster, stronger web development.

HTML5 doctype

Bootstrap makes use of certain HTML elements and CSS properties that require the use of the HTML5 doctype. Hence include the below piece of code for HTML5 doctype at the beginning of all your projects using Bootstrap.

<!DOCTYPE html>
<html>
....
</html>

Mobile First

Since Bootstrap 3, Bootstrap has become mobile first. It means mobile first styles can be found throughout the entire library instead of in separate files. You need to add the viewport meta tag to the <head> element, to ensure proper rendering and touch zooming on mobile devices.

width property controls the width of the device. Setting it to device-width will make sure that it is rendered across various devices (mobiles,desktops,tablets...) properly.

initial-scale=1.0 ensures that when loaded, your web page will be rendered at a 1:1 scale, and no zooming will be applied out of the box.

Add user-scalable=no to the content attribute to disable zooming capabilities on mobile devices as shown below. Users are only able to scroll and not zoom with this change, and results in your site feeling a bit more like a native application.

Normally maximum-scale=1.0 is used along with user-scalable=no. As mentioned above user-scalable=no may give users an experience more like a native app, hence Bootstrap doesn't recommend using this attribute.

Responsive images

Bootstrap 3 allows to make the images responsive by adding a class .img-responsive to the <img> tag. This class applies max-width: 100%; and height: auto; to the image so that it scales nicely to the parent element.

Note that, due to padding and fixed widths, containers are not nestable by default.

Take a look at bootstrap.css file:

@media (min-width: 768px) {
.container {
width: 750px;
}

Here you can see that CSS has media-queries for containers with width. This helps for applying responsiveness and within those the container class is modified accordingly to render the grid system properly.

Typography

Bootstrap uses Helvetica Neue, Helvetica, Arial, and sans-serif in its default font stack. Using typography feature of Bootstrap you can create headings, paragraphs, lists and other inline elements. Let see each one these in the following sections:

Headings

All HTML headings (h1 to h6) are styled in Bootstrap.

Inline Subheadings

To add an inline subheading to any of the headings, simply add <small> around any of the elements or add .small class and you will get smaller text in a lighter color.

Lead Body Copy

To add some emphasis to a paragraph, add class="lead". This will give you larger font size, lighter weight, and a taller line height.

Emphasis

HTML's default emphasis tags such as

Abbreviations

The HTML element provides markup for abbreviations or acronyms, like WWW or HTTP. Bootstrap styles <abbr> elements with a light dotted border along the bottom and reveals the full text on hover (as long as you add that text to the <abbr> title attribute). To get a a slightly smaller font size Add .initialism to <abbr>.

Addresses

Using <address> tag you can display the contact information on your web page. Since the <address> defaults to display:block;
you’ll need to use tags to add line breaks to the enclosed address text.

Blockquotes

You can use the default <blockquote> around any HTML text. Other options include, adding a <small> tag for identifying the source of the quote and right-aligning the blockquote using class .pull-right.

Lists

Ordered lists: An ordered list is a list that falls in some sort of sequential order and is prefaced by
numbers.

Unordered lists: An unordered list is a list that doesn’t have any particular order and is traditionally styled with bullets. If you do not want the bullets to appear then you can remove the styling by using the class .list-unstyled. You can also place all list items on a single line using the class .list-inline.

Definition lists: In this type of list, each list item can consist of both the <dt> and the <dd> elements. <dt> stands for definition term, and like a dictionary, this is the term (or phrase) that is being defined. Subsequently, the <dd> is the definition of the <dt>.

You can make terms and descriptions in <dl> line up side-by-side using class dl-horizontal.

Code

Bootstrap allows you to display code with two different key ways:

The first is the <code> tag. If you are going to be displaying code inline, you should use the <code> tag.

Second is the <pre> tag. If the code needs to be displayed as a standalone block element or if it has multiple lines, then you should use the <pre> tag.

Tables

Bootstrap provides a clean layout for building tables. Some of the table elements supported by Bootstrap are:

Tag

Description

<table>

Wrapping element for displaying data in a tabular format

<thead>

Container element for table header rows (<tr>) to label table columns

<tbody>

Container element for table rows (<tr>) in the body of the table

<tr>

Container element for a set of table cells (<td> or <th>) that appears on a single row

<td>

Default table cell

<th>

Special table cell for column (or row, depending on scope and placement) labels. Must be used within a <thead>

<caption>

Description or summary of what the table holds.

Basic Table

If you want a nice, basic table style with just some light padding and horizontal dividers, add the base class of .table to any table.

Optional Table Classes

Along with the base table markup and the .table class, there are a few additional classes that you can use to style the markup. Following sections will give you a glimpse of all these classes.

Striped Table

By adding the .table-striped class, you will get stripes on rows within the <tbody>.

Bordered Table

By adding the .table-bordered class, you will get borders surrounding every element and rounded corners around the entire table.

Hover Table

By adding the .table-hover class, a light gray background will be added to rows while the cursor hovers over them.

Condensed Table

By adding the .table-condensed class, row padding is cut in half to condense the table. as seen in the following example. This is useful if you want denser information.

Contextual classes

The Contextual classes shown in following table will allow you to change the background color of your table rows or individual cells.

Class

Description

.active

Applies the hover color to a particular row or cell

.success

Indicates a successful or positive action

.warning

Indicates a warning that might need attention

.danger

Indicates a dangerous or potentially negative action

These classes can be applied to <tr>, <td> or <th>.

Responsive tables

By wrapping any .table in .table-responsive class, you will make the table scroll horizontally up to small devices (under 768px). When viewing on anything larger than 768px wide, you will not see any difference in these tables.

Forms

Form Layout

Bootstrap provides you with following types of form layouts:

Vertical (default) form

Inline form

Horizontal form

Vertical or basic form

The basic form structure comes with Bootstrap; individual form controls automatically receive some global styling. To create a basic form do the following:

Add a role form to the parent <form> element.

Wrap labels and controls in a <div> with class .form-group. This is needed for optimum spacing.

Add a class of .form-control to all textual <input>, <textarea>, and <select> elements.

Inline form

To create a form where all of the elements are inline, left aligned and labels are alongside, add the class .form-inline to the <form> tag.

Horizontal form

Horizontal forms stands apart from the others not only in the amount of markup, but also in the presentation of the form. To create a form that uses the horizontal layout, do the following:

Add a class of .form-horizontal to the parent <form> element.

Wrap labels and controls in a <div> with class .form-group.

Add a class of .control-label to the labels.

Supported Form Controls

Bootstrap natively supports the most common form controls mainly input, textarea, checkbox, radio, and select.

Inputs

The most common form text field is the input—this is where users will enter most of the essential form data. Bootstrap offers support for all native HTML5 input types: text, password, datetime, datetime-local, date, month, time, week, number, email, url, search, tel, and color. Proper type declaration is required to make Inputs fully styled.

Textarea

The textarea is used when you need multiple lines of input. Change rows attribute as necessary (fewer rows = smaller box, more rows = bigger box).

CheckBoxes and Radios

Checkboxes and radio buttons are great when you want users to choose from a list of preset options.

When building a form, use checkbox if you want the user to select any number of options from a list. Use radio if you want to limit the user to just one selection.

Use .checkbox-inline or .radio-inline class to a series of checkboxes or radios for controls appear on the same line.

Selects

A select is used when you want to allow the user to pick from multiple options, but by default it only allows one.

Use <select> for list options with which the user is familiar, such as states or numbers.

Use multiple="multiple" to allow the user to select more than one option.

Static control

Use the class .form-control-static on a <p>, when you need to place plain text next to a form label within a horizontal form.

Form Control States

In addition to the :focus (i.e., a user clicks into the input or tabs onto it) state, Bootstrap offers styling for disabled inputs and classes for form validation.

Input focus

When an input receives :focus, the outline of the input is removed and a box-shadow is applied.

Disabled inputs

If you need to disable an input, simply adding the disabled attribute will not only disable it; it will also change the styling and the mouse cursor when the cursor hovers over the element.

Disabled fieldsets

Add the disabled attribute to a <fieldset> to disable all the controls within the <fieldset> at once.

Validation states

Bootstrap includes validation styles for error, warning, and success messages. To use, simply add the appropriate class (.has-warning, .has-error, or .has-success) to the parent element.

Form Control Sizing

You can set heights and widths of forms using classes like .input-lg and .col-lg-* respectively.

Help Text

Bootstrap form controls can have a block level help text that flows with the inputs. To add a full width block of content, use the .help-block after the <input>.

Buttons

This chapter will discuss about how to use Bootstrap button with examples. Anything that is given a class of .btn will inherit the default look of a gray button with rounded corners. However Bootstrap provides some options to style buttons, which are summarized in the following table:

Class

Description

btn

Default/ Standard button.

btn-primary

Provides extra visual weight and identifies the primary action in a set of buttons.

btn-success

Indicates a successful or positive action.

btn-info

Contextual button for informational alert messages.

btn-warning

Indicates caution should be taken with this action.

btn-danger

Indicates a dangerous or potentially negative action.

btn-link

Deemphasize a button by making it look like a link while maintaining button behavior.

Button Size

The following table summarizes classes used to get buttons of various sizes:

Class

Description

.btn-lg

This makes button size large.

.btn-sm

This makes button size small.

.btn-xs

This makes button size with extra small.

.btn-block

This creates block level buttons—those that span the full width of a parent.

Button State

Bootstrap provides classes which allow you change the state of buttons say active, disabled etc each of these are discussed in the following sections:

Active State

Buttons will appear pressed (with a darker background, darker border, and inset shadow) when active. The following table summarizes classes used to make button element and anchor element active:

Element

Class

Button element

Use .active class to show that it is activated..

Anchor element

Use .active class to <a> buttons to show that it is activated.

Disabled State

When you disable a button, it will fade in color by 50%, and lose the gradient.

The following table summarizes classes used to make button element and anchor element disabled:

Element

Class

Button element

Add the disabledattribute to <button> buttons.

Anchor element

Add the disabledclass to <a> buttons.Note: This class will only change the <a>'s appearance, not its functionality. You need to use custom JavaScript to disable links here.

Button Tags

You may use button classes with <a>, <button>, or <input> element. But it is recommended that you use it with <button> elements mostly to avoid cross browser inconsistency issues.

Images

In this chapter we will learn Bootstrap support for images. Bootstrap provides three classes that can be used to apply some simple styles to images:

Helper Classes

This chapter discusses some of the helper classes in Bootstrap that might come in handy.

Close icon

Use the generic close icon for dismissing content like modals and alerts. Use the class close to get the close icon.

Carets

Use carets to indicate dropdown functionality and direction. To get this functionality use the class caret with a <span> element.

Quick floats

You can float an element to the left or right with class pull-left or pull-right respectively. Following example demonstrates this.

Center content blocks

Use class center-block to set an element to center.

Clearfix

To clear the float of any element, use the .clearfix class.

Showing and hiding content

You can force an element to be shown or hidden (including for screen readers) with the use of classes .show and .hidden.

Screen reader content

You can hide an element to all devices except screen readers with class .sr-only.

Responsive Utilites

Bootstrap provides some handful helper classes, for faster mobile-friendly development. These can be used for showing and hiding content by device via media query combined with large, small, and medium devices.

Use these sparingly and avoid creating entirely different versions of the same site. Responsive utilities are currently only available for block and table toggling.

Classes

Devices

.visible-xs

Extra small (less than 768px) visible

.visible-sm

Small (up to 768 px) visible

.visible-md

Medium (768 px to 991 px) visible

.visible-lg

Larger (992 px and above) visible

.hidden-xs

Extra small (less than 768px) hidden

.hidden-sm

Small (up to 768 px) hidden

.hidden-md

Medium (768 px to 991 px) hidden

.hidden-lg

Larger (992 px and above) hidden

Print classes

Following table lists the print classes. Use these for toggling content for print.

Classes

Print

.visible-print

Yes Visible

.hidden-print

Visible only to browser not to print.

Glyphicons

This chapter will discuss about Glyphicons, its use and some examples. Bootstrap bundles 200 glyphs in font format.
First let us understand what are Glyphicons.

What are Glyphicons?

Glyphicons are icon fonts which you can use in your web projects. Glyphicons Halflings are not free and require licensing, however their creator has made them available for Bootstrap projects free of cost.

It is recommended, as a thank you, we ask you to include an optional link back to GLYPHICONS whenever practical.
— Bootstrap Documentation

Where to find Glyphicons?

Now that we have downloaded Bootstrap 3.x version and understand its directory structure from chapter Environment Setup, glyphicons can be found within the fonts folder. This contains following files:

glyphicons-halflings-regular.eot

glyphicons-halflings-regular.svg

glyphicons-halflings-regular.ttf

glyphicons-halflings-regular.woff

Associated CSS rules are present within bootstrap.css and bootstrap-min.css files within css folder of dist folder. You can see the available glyphicons at this link : Glyphicons List

Usage

To use the icons, simply use the following code just about anywhere in your code. Leave a space between the icon and text for proper padding.

<span class="glyphicon glyphicon-search"></span>

Dropdowns

This chapter will discuss about how to add dropdown menu to buttons using Bootstrap classes. To add a dropdown to a button, simply wrap the button and dropdown menu in a .btn-group. You can also use <span class="caret"></span> to act as an indicator that the button is a dropdown.

Split Button Dropdowns

Split button dropdowns use the same general style as the dropdown button but add a primary action along with the dropdown. Split buttons have the primary action on the left and a toggle on the right that displays the dropdown.

Button Dropdown Size

You can use the dropdowns with any button size: .btn-large, .btn-sm, or .btn-xs.

Dropup variation

Menus can also be built to drop up rather than down. To achieve this, simply add .dropup to the parent .btn-group container.

Button Groups

Button groups allow multiple buttons to be stacked together on a single line. This is useful when you want to place items like alignment buttons together. You can add on optional JavaScript radio and checkbox style behavior with Bootstrap Button Plugin.

Following table summarizes the important classes Bootstrap provides to use button groups:

Class

Description

Code Sample

.btn-group

This class is used form a basic button group. Wrap a series of buttons with class .btn in .btn-group.

This class make a set of buttons appear vertically stacked rather than horizontally.

<div class="btn-group-vertical">
...
</div>

Button Dropdowns

This chapter will discuss about how to add dropdown menu to buttons using Bootstrap classes. To add a dropdown to a button, simply wrap the button and dropdown menu in a .btn-group. You can also use <span class="caret"></span> to act as an indicator that the button is a dropdown.

Split Button Dropdowns

Split button dropdowns use the same general style as the dropdown button but add a primary action along with the dropdown. Split buttons have the primary action on the left and a toggle on the right that displays the dropdown.

Button Dropdown Size

You can use the dropdowns with any button size: .btn-large, .btn-sm, or .btn-xs.

Dropup variation

Menus can also be built to drop up rather than down. To achieve this, simply add .dropup to the parent .btn-group container.

Input Groups

This chapter explains about one more feature Bootstrap supports, the Input Groups. Input groups are extended Form Controls. Using input groups you can easily prepend and append text or buttons to text-based inputs.

By adding prepended and appended content to an input field, you can add common elements to the user’s input. For example, you can add the dollar symbol, the @ for a Twitter username, or anything else that might be common for your application interface.

To prepend or append elements to a .form-control:

Wrap it in a <div> with class .input-group

As a next step, within that same <div> , place your extra content inside a <span> with class .input-group-addon.

Now place this <span> either before or after the <input> element.

For cross browser compatibility, avoid using <select> elements here as they cannot be fully styled in WebKit browsers. Also do not apply input group classes directly to form groups. An input group is an isolated component.

Input Group Sizing

You can change the size of the input groups, by adding the relative form sizing classes like .input-group-lg, input-group-sm, input-group-xs to the .input-group itself. The contents within will automatically resize.

Button addons

You can even preappend or append buttons in input groups. Instead of .input-group-addon class, you'll need to use class .input-group-btn to wrap the buttons. This is required due to default browser styles that cannot be overridden.

Buttons with dropdowns

Adding button with dropdown menus in input groups can be done by simply wrapping the button and dropdown menu in a .input-group-btn class.

Segmented buttons

To segment button dropdowns in input groups, use the same general style as the dropdown button but add a primary action along with the dropdown.

Navigation Elements

In this chapter we will discuss about how Bootstrap provides a few different options for styling navigation elements. All of them share the same markup and base class, .nav. Bootstrap also provides a helper class, to share markup and states. Swap modifier classes to switch between each style.

Tabular Navigation or Tabs

To create a tabbed navigation menu:

Start with a basic unordered list with the base class of .nav

Add class .nav-tabs.

Pills Navigation

Basic pills

To turn the tabs into pills, follow the same steps as above, use the class .nav-pills instead of .nav-tabs.

Verticle Pills

You can stack the pills vertically using the class .nav-stacked alongwith classes .nav, .nav-pills.

Justified Nav

You can make tabs or pills equal widths of their parent at screens wider than 768px using class .nav-justified alongwith .nav, .nav-tabs or .nav, .nav-pills respectively. On smaller screens, the nav links are stacked.

Disabled Links

For each of the .nav classes, if you add the .disabled class, it will create a gray link that also disables the :hover state.

Dropdowns

Navigation menus share a similar syntax with dropdown menus. By default, you have a list item that has an anchor working in conjunction with some data-attributes to trigger an unordered list with a .dropdown-menu class.

Tabs with Dropdowns

To add dropdowns to tab:

Start with a basic unordered list with the base class of .nav

Add class .nav-tabs.

Now add an unordered list with a .dropdown-menu class.

Pills with Dropdowns

To do the same thing with pills, simply swap the .nav-tabs class with .nav-pills as shown in the following example.

Navbar

The navbar is a nice feature, and is one of the prominent features of Bootstrap sites. Navbars are responsive meta components that serve as navigation headers for your application or site. Navbars collapse in mobile views and become horizontal as the available viewport width increases. At its core, the navbar includes styling for site names and basic navigation.

Default navbar

To create a default navbar:

Add classes .navbar, .navbar-default to the <nav> tag.

Add role="navigation" to the above element, to help with accessibility.

Add a header class .navbar-header to the <div> element. Include an <a> element with class navbar-brand. This will give the text a slightly larger size.

To add links to the navbar, simply add an unordered list with a classes of .nav, .navbar-nav.

Responsive navbar

To add the responsive features to the navbar, the content that you want to be collapsed needs to be wrapped in a <div> with classes .collapse, .navbar-collapse. The collapsing nature is tripped by a button that has a the class of .navbar-toggle and then features two data- elements. The first, data-toggle, is used to tell the JavaScript what to do with the button, and the second, data-target, indicates which element to toggle. Three with a class of .icon-bar create what I like to call the hamburger button. This will toggle the elements that are in the .nav-collapse <div>. For this feature to work, you need to include the Bootstrap Collapse Plugin.

Forms in navbar

Instead of using the default class-based forms from Chapter Bootstrap Forms, forms that are in the navbar use the .navbar-form class. This ensures that the form’s proper vertical alignment and collapsed behavior in narrow viewports. Use the alignment options (explained in Component alignment section) to decide where it resides within the navbar content.

Buttons in navbar

You can add buttons using class .navbar-btn to <button> elements not residing in a <form> to vertically center them in the navbar. .navbar-btn can be used on <a> and <input> elements.

Do not use .navbar-btn nor the standard button classes on <a> elements within .navbar-nav.

Text in navbar

To wrap strings of text in an element use class .navbar-text. This is usually used with <p> tag for proper leading and color.

Non-nav links

If you want to use standard links that are not within the regular navbar navigation component, then use class navbar-link to add the proper colors for the default and inverse navbar options.

Component alignment

You can align the components like nav links, forms, buttons, or text to left or right in a navbar using the utility classes .navbar-left or .navbar-right. Both classes will add a CSS float in the specified direction.

Fixed to top

The Bootstrap navbar can be dynamic in its positioning. By default, it is a block-level element that takes its positioning based on its placement in the HTML. With a few helper classes, you can place it either on the top or bottom of the page, or you can make it scroll
statically with the page.

If you want the navbar fixed to the top, add class .navbar-fixed-top to the .navbar class.

Fixed to bottom

If you want the navbar fixed to the bottom of the page, add class .navbar-fixed-bottom to the .navbar class.

Static top

To create a navbar that scrolls with the page, add the .navbar-static-top class. This class does not require adding the padding to the <body>.

Inverted navbar

To create an inverted navbar with a black background and white text, simply add .navbar-inverse class to the .navbar class.

Breadcrumb

Breadcrumbs are a great way to show hierarchy-based information for a site. In the case of blogs, breadcrumbs can show the dates of publishing, categories, or tags. They indicate the current page's location within a navigational hierarchy.

A breadcrumb in Bootstrap is simply an unordered list with a class of .breadcrumb. The separator is automatically added by CSS (bootstrap.min.css) through the following class:

Pager

If you need to create simple pagination links that go beyond text, the pager can work quite well. Like the pagination links, the pager is an unordered list. By default the links are centered. The following table lists the classes Bootstrap provides for pager.

Labels

This chapter will discuss about Bootstrap labels. Labels are great for offering counts, tips, or other markup for pages. Use class .label to display labels.

You can the appearance of the labels using the modifier classes label-default, label-primary, label-success, label-info, label-warning, label-danger.

Badges

This chapter will discuss about Bootstrap badges. Badges are similar to labels; the primary difference is that the corners are more rounded.

Badges are mainly used to highlight new or unread items. To use badges just add <span class="badge"> to links, Bootstrap navs, and more.

Active nav states

You can place badges in active states of pill and list navigations. You can achieve this by placing <span class="badge"> to active links.

Jumbotron

This chapter will discuss one more feature Bootstrap supports, the Jumbotron. As the name suggest this component can optionally increases the size of headings and add a lot of margin for landing page content. To use the Jumbotron:

simply create a container <div> with the class of .jumbotron.

In addition to a larger <h1>, the font-weight is reduced to 200px.

To get a jumbotron full width, and without rounded corners use the .jumbotron class outside all .container classes and instead add a .container within.

Page Header

The page header is a nice little feature to add appropriate spacing around the headings on a page. This is particularly helpful on a web page where you may have several post titles and need a way to add distinction to each of them. To use a page header, wrap your heading in a <div> with a class of .page-header:

Thumbnails

This chapter discusses about Bootstrap thumbnails. A lot of sites need a way to lay out images,videos,text, etc in a grid, and Bootstrap has an easy way to do this with thumbnails. To create thumbnails using Bootstrap:

Add an <a> tag with the class of .thumbnail around an image.

This adds four pixels of padding and a gray border.

On hover, an animated glow outlines the image.

Adding Custom Content

Now that we have a basic thumbnail, it's possible to add any kind of HTML content like headings, paragraphs, or buttons into thumbnails. Follow the steps below:

Change the <a> tag that has a class of .thumbnail to a <div>.

Inside of that <div>, you can add anything you need. As this is a <div>, we can use the default span-based naming convention for sizing.

If you want to group multiple images, place them in an unordered list, and each list item will be floated to the left.

Alerts

This chapter will discuss about alerts and the classes Bootstrap provides for alerts. Alerts provide a way to style messages to the user. They provide contextual feedback messages for typical user actions.

You can add an basic alert by creating a wrapper <div> and adding a class of .alert and one of the four contextual classes (e.g., .alert-success, .alert-info, .alert-warning, .alert-danger).

Dismissal Alerts

To build a dismissal alert:

Add an basic alert by creating a wrapper <div> and adding a class of .alert and one of the four contextual classes (e.g., .alert-success, .alert-info, .alert-warning, .alert-danger)

Also add optional .alert-dismissable to the above <div> class.

Add a close button.

Links in Alerts

To get links in alerts:

Add an basic alert by creating a wrapper <div> and adding a class of .alert and one of the four contextual classes (e.g., .alert-success, .alert-info, .alert-warning, .alert-danger)

Use the .alert-link utility class to quickly provide matching colored links within any alert.

Progress Bars

This chapter discusses about Bootstrap progress bars. The purpose of progress bars is to show that assets are loading, in progress, or that there is action taking place regarding elements on the page.

Progress bars use CSS3 transitions and animations to achieve some of their effects. These features are not supported in Internet Explorer 9 and below or older versions of Firefox. Opera 12 does not support animations.

Default Progress Bar

To create a basic progress bar:

Add a <div> with a class of .progress.

Next, inside the above <div>, add an empty <div> with a class of .progress-bar.

Add a style attribute with the width expressed as a percentage. Say for example, style="60%"; indicates that the progress bar was at 60%.

Alternate Progress Bar

To create a progress bar with different styles:

Add a <div> with a class of .progress.

Next, inside the above <div>, add an empty <div> with a class of .progress-bar and class progress-bar-* where * could be success, info, warning, danger.

Add a style attribute with the width expressed as a percentage. Say for example, style="60%"; indicates that the progress bar was at 60%.

Striped Progress Bar

To create a striped progress bar:

Add a <div> with a class of .progress and .progress-striped.

Next, inside the above <div>, add an empty <div> with a class of .progress-bar and class progress-bar-* where * could be success, info, warning, danger.

Add a style attribute with the width expressed as a percentage. Say for example, style="60%"; indicates that the progress bar was at 60%.

Animated Progress Bar

To create an animated progress bar:

Add a <div> with a class of .progress and .progress-striped. Also add class .active to .progress-striped.

Next, inside the above <div>, add an empty <div> with a class of .progress-bar.

Add a style attribute with the width expressed as a percentage. Say for example, style="60%"; indicates that the progress bar was at 60%.

Stacked Progress Bar

You can even stack multiple progress bars. Place the multiple progress bars into the same .progress to stack.

Media Object

This chapter discusses about Media object. These are abstract object styles for building various types of components (like blog comments, Tweets, etc) that feature a left- or right-aligned image alongside textual content. The goal of the media object is to make the code for developing these blocks of information drastically shorter.

The goal of media objects (light markup, easy extendability) is achieved by applying classes to some simple markup. There are two
forms to the media object:

.media: This class allows to float a media object (images, video, audio) to the left or right of a content block.

.media-list: If you are preparing a list where the items will be part of an unordered list, use class. Useful for comment threads or articles lists.

List Group

In this article we will study about list group. Purpose of list group component is to render complex and customized content in lists. To get a basic list group:

Add the class .list-group to element <ul>.

Add class .list-group-item to <li>.

Adding Badges to List Group

We can add the badges component to any list group item and it will automatically be positioned on the right. Just add <span class="badge"> within the <li> element.

Linking List Group Items

By using anchor tags instead of list items, we can link the list groups. We need to use <div> instead of <ul> element.

Panels

This chapter will discuss about Bootstrap panels. Panel component are used when you want to put your DOM component in a box. To get a basic panel, just add class .panel to the <div> element. Also add class .panel-default to this element.

Panel with heading

There are two ways to add panel heading:

Use .panel-heading class to easily add a heading container to your panel.

Use any <h1>-<h6> with a .panel-title class to add a pre-styled heading.

Panel with footer

You can add footers to panels, by wrapping buttons or secondary text in a <div> containing class .panel-footer.

Panel Contextual alternatives

Use contextual state classes panel-primary, panel-success, panel-info, panel-warning, panel-danger, to make a panel more meaningful to a particular context.

Panel with tables

To get a non-bordered table within a panel, use class .table within the panel. Suppose there is a <div> containing .panel-body, we add an extra border to the top of the table for separation. If there is no <div> containing .panel-body, then the component moves from panel header to table without interruption.

Panel with Listgroups

You can include list groups within any panel. Create a panel by adding class .panel to the <div> element. Also add class .panel-default to this element. Now within this panel include your list groups. You can learn to create a list group from chapter List Groups.

Wells

A well is a container <div> that causes the content to appear sunken or an inset effect on the page. To create a well, simply wrap the content that you would like to appear in the well with a <div> containing the class of .well.

Sizing

You can change the size of well using the optional classes well-lg or well-lg. These classes are used in conjunction with .well class. These affect the padding, making the well larger or smaller depending on the class.

Plugins Overview

The components discussed in the previous chapters under Layout Components are just the beginning. Bootstrap comes bundled with 12 jQuery plugins that extend the features and can add more interaction to your site. To get started with Bootstrap’s JavaScript plugins, you don’t need to be an advanced JavaScript developer. By utilizing Bootstrap Data API, most of the plugins can be triggered without writing a single line of code.

Bootstrap Plugins can be included on your site in two forms:

Individually: Using Bootstrap's individual *.js files. Some plugins and CSS components depend on other plugins. If you include plugins individually, make sure to check for these dependencies in the docs.

Or compiled (all at once): Using bootstrap.js or the minified bootstrap.min.js.

Do not attempt to include both, as both bootstrap.js and bootstrap.min.js contain all plugins in a single file.

All plugins depend on jQuery. So jQuery must be included before the plugin files. Check bower.json to see which versions of jQuery are supported.

Data Attributes

All of the Bootstrap plugins are accessible using the included Data API. Hence, you don’t need to include a single line of JavaScript to invoke any of the plugin features.

In some situations it may be desirable to turn this functionality of Data API off. If you need to turn off the Data API, you can unbind the attributes by adding the following line of JavaScript:

$(document).off('.data-api')

To turn off a specific/single plugin, just include the plugin's name as a namespace along with the data-api namespace like this:

$(document).off('.alert.data-api')

Programmatic API

The developers of Bootstrap believe that you should be able to use all of the plugins purely through the JavaScript API. All public APIs are single, chainable methods, and return the collection acted upon say for example:

$(".btn.danger").button("toggle").addClass("fat")

All methods accept an optional options object, a string which targets a particular method, or nothing (which initiates a plugin with default behavior) as shown below:

Each plugin also exposes its raw constructor on a Constructor property: $.fn.popover.Constructor. If you'd like to get a particular plugin instance, retrieve it directly from an element:

$('[rel=popover]').data('popover').

No Conflict

Bootstrap plugins can sometimes be used with other UI frameworks. In these circumstances, namespace collisions can occasionally occur. To overcome this call .noConflict on the plugin you wish to revert the value of.

Events

Bootstrap provides custom events for most plugin's unique actions. Generally, these events come in two forms:

Infinitive form: This is triggered at the start of an event. ex: show. Infinitive events provide preventDefault functionality. This provides the ability to stop the execution of an action before it starts.

Past participle form: This is triggered on the completion of an action. ex: shown

Transition Plugin

The transition plugin provides simple transition effects.

If you want to include this plugin functionality individually, then you will need transition.js once alongside the other JS files. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Transition.js is a basic helper for transitionEnd events as well as a CSS transition emulator. It's used by the other plugins to check for CSS transition support and to catch hanging transitions.

Modal Plugin

A modal is a child window that is layered over its parent window. Typically, the purpose is to display content from a separate source that can have some interaction without leaving the parent window. Child windows can provide information, interaction, or more.

If you want to include this plugin functionality individually, then you will need modal.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

You can toggle the modal plugin's hidden content:

Via data attributes: Set attribute data-toggle="modal" on a controller element, like a button or link, along with a data-target="#identifier" or href="#identifier" to target a specific modal (with the id="identifier") to toggle.

Via JavaScript: Using this technique you can call a modal with id="identifier" with a single line of JavaScript:

Dropdown Plugin

The chapter Bootstrap Dropdowns covered the dropdown menu, but the interaction part was not covered which will be explained here. Using Dropdown plugin you can add dropdowns menus to any components like navbars, tabs, pills and buttons.

If you want to include this plugin functionality individually, then you will need dropdown.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

You can toggle the dropdown plugin's hidden content:

Via data attributes: Add data-toggle="dropdown" to a link or button to toggle a dropdown as shown below:

Scrollspy Plugin

The Scrollspy (auto updating nav) plugin allows you to target sections of the page based on scroll position. In its basic implementation, as you scroll, you can add .active classes to the navbar based on the scroll position.

If you want to include this plugin functionality individually, then you will need scrollspy.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

You can add scrollspy behavior to your topbar navigation:

Via data attributes: add data-spy="scroll" to the element you want to spy on (typically the body). Then add attribute data-target with the ID or class of the parent element of any Bootstrap .nav component. For this to work, you must have elements in the body of the page that have matching IDs of the links that you are spying on.

Via JavaScript: You can invoke the scrollspy with JavaScript instead of using the data attributes, by selecting the element to spy on, and then invoking the .scrollspy() function:

$('body').scrollspy({ target: '.navbar-example' })

Example

The following example shows the use of scrollspy plugin via data attributes:

<nav id="navbar-example" class="navbar navbar-default navbar-static" role="navigation">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse"
data-target=".bs-js-navbar-scrollspy">
<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 Name</a>
</div>
<div class="collapse navbar-collapse bs-js-navbar-scrollspy">
<ul class="nav navbar-nav">
<li><a href="#ios">iOS</a></li>
<li><a href="#svn">SVN</a></li>
<li class="dropdown">
<a href="#" id="navbarDrop1" class="dropdown-toggle"
data-toggle="dropdown">Java
<b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu"
aria-labelledby="navbarDrop1">
<li><a href="#jmeter" tabindex="-1">jmeter</a></li>
<li><a href="#ejb" tabindex="-1">ejb</a></li>
<li class="divider"></li>
<li><a href="#spring" tabindex="-1">spring</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<div data-spy="scroll" data-target="#navbar-example" data-offset="0"
style="height:200px;overflow:auto; position: relative;">
<h4 id="ios">iOS</h4>
<p>iOS is a mobile operating system developed and distributed by Apple
Inc. Originally released in 2007 for the iPhone, iPod Touch, and Apple
TV. iOS is derived from OS X, with which it shares the Darwin
foundation. iOS is Apple's mobile version of the OS X operating system
used on Apple computers.
</p>
<h4 id="svn">SVN</h4>
<p>Apache Subversion which is often abbreviated as SVN, is a software
versioning and revision control system distributed under an open source
license. Subversion was created by CollabNet Inc. in 2000, but now it
is developed as a project of the Apache Software Foundation, and as
such is part of a rich community of developers and users.
</p>
<h4 id="jmeter">jMeter</h4>
<p>jMeter is an Open Source testing software. It is 100% pure Java
application for load and performance testing.
</p>
<h4 id="ejb">EJB</h4>
<p>Enterprise Java Beans (EJB) is a development architecture for building
highly scalable and robust enterprise level applications to be deployed
on J2EE compliant Application Server such as JBOSS, Web Logic etc.
</p>
<h4 id="spring">Spring</h4>
<p>Spring framework is an open source Java platform that provides
comprehensive infrastructure support for developing robust Java
applications very easily and very rapidly.
</p>
<p>Spring framework was initially written by Rod Johnson and was first
released under the Apache 2.0 license in June 2003.
</p>
</div>

Tab Plugin

Tabs were introduced in the chapter Bootstrap Navigation Elements. By combining a few data attributes, you can easily create a tabbed interface. With this plugin you can transition through panes of local content in tabs or pills, even via dropdown menus.

If you want to include this plugin functionality individually, then you will need tab.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

You can enable tabbable tabs in the following two ways:

Via data attributes: you need to add data-toggle="tab" or data-toggle="pill" to the anchors.

Adding the nav and nav-tabs classes to the tab ul will apply the Bootstrap tab styling, while adding thenav and nav-pills classes will apply pill styling.

Example

An example of tab plugin using data attributes and fade effect is as shown in the following example:

<ul id="myTab" class="nav nav-tabs">
<li class="active">
<a href="#home" data-toggle="tab">
Tutorial Point Home
</a>
</li>
<li><a href="#ios" data-toggle="tab">iOS</a></li>
<li class="dropdown">
<a href="#" id="myTabDrop1" class="dropdown-toggle"
data-toggle="dropdown">Java
<b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1">
<li><a href="#jmeter" tabindex="-1" data-toggle="tab">jmeter</a></li>
<li><a href="#ejb" tabindex="-1" data-toggle="tab">ejb</a></li>
</ul>
</li>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="home">
<p>Tutorials Point is a place for beginners in all technical areas.
This website covers most of the latest technoligies and explains
each of the technology with simple examples. You also have a
<b>tryit</b> editor, wherein you can edit your code and
try out different possibilities of the examples.</p>
</div>
<div class="tab-pane fade" id="ios">
<p>iOS is a mobile operating system developed and distributed by Apple
Inc. Originally released in 2007 for the iPhone, iPod Touch, and
Apple TV. iOS is derived from OS X, with which it shares the
Darwin foundation. iOS is Apple's mobile version of the
OS X operating system used on Apple computers.</p>
</div>
<div class="tab-pane fade" id="jmeter">
<p>jMeter is an Open Source testing software. It is 100% pure
Java application for load and performance testing.</p>
</div>
<div class="tab-pane fade" id="ejb">
<p>Enterprise Java Beans (EJB) is a development architecture
for building highly scalable and robust enterprise level
applications to be deployed on J2EE compliant
Application Server such as JBOSS, Web Logic etc.
</p>
</div>
</div>

Tooltip Plugin

Tooltips are useful when you need to describe a link. The plugin was inspired by jQuery.tipsy plugin written by Jason Frame. Tooltips have since been updated to work without images, animate with a CSS animation, and data-attributes for local title storage.

If you want to include this plugin functionality individually, then you will need tooltip.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element. You can add tooltips in the following two ways:

Via data attributes: To add a tooltip, add data-toggle="tooltip" to an anchor tag. The title of the anchor will be
the text of a tooltip. By default, tooltip is set to top by the plugin.

Tooltip plugin is NOT only-css plugins like dropdown or other plugins discussed in previous chapters. To use this plugin you MUST activate it using jquery (read javascript). To enable all the tooltips on your page just use this script:

$(function () { $("[data-toggle='tooltip']").tooltip(); });

Example

The following example demonstrates the use of tooltip plugin via data attributes.

Popover Plugin

The popover is similar to tooltip, offering an extended view complete with a heading. For the popover to activate, a user just needs to hover the cursor over the element. The content of the popover can be populated entirely using the Bootstrap Data API. This method requires a tooltip.

If you want to include this plugin functionality individually, then you will need popover.js and it has a dependency of tooltip plugin. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

The popover plugin generates content and markup on demand, and by default places popover after their trigger element. You can add popover in the following two ways:

Via data attributes: To add a popover, add data-toggle="popover" to an anchor/button tag. The title of the anchor will be the text of a popover. By default, popover is set to top by the plugin.

Via JavaScript: Enable popovers via JavaScript using the following syntax:

$('#identifier').popover(options)

Popover plugin is NOT only-css plugins like dropdown or other plugins discussed in previous chapters. To use this plugin you MUST activate it using jquery (read javascript). To enable all the popovers on your page just use this script:

$(function () { $("[data-toggle='popover']").popover(); });

Example

The following example demonstrates the use of popover plugin via data attributes.

Alert Plugin

Alert messages are mostly used to display information such as warning or confirmation messages to the end users. Using alert message plugin you can add dismiss functionality to all alert messages.

If you want to include this plugin functionality individually, then you will need alert.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

You can enable dismissal of an alert in the following two ways:

Via data attributes: To dismiss via Data API just add data-dismiss="alert" to your close button to automatically give an alert close functionality.

Button Plugin

Buttons were explained in chapter Bootstrap Buttons. With this plugin you can add in
some interaction such as control button states or create groups of buttons for more components like toolbars.

If you want to include this plugin functionality individually, then you will need button.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Loading State

To add a loading state to a button, simply add data-loading-text="Loading..." as an attribute to the button element as shown in the following example:

When you click on the button the output would be as seen in the following image:

Single toggle

To activate toggling (i.e. change the normal state of a button to a push state and vice versa) on a single button, add data-toggle="button" as an attribute to the button element as shown in the following example:

Usage

Collapse Plugin

The collapse plugin makes it easy to make collapsing divisions of the page. Whether you use it to build accordion navigation or content boxes, it allows for a lot of content options.

If you want to include this plugin functionality individually, then you will need collapse.js. This also requires the Transition Plugin to be included in your version of Bootstrap. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

You can use the collapse plugin:

To create collapsible groups or accordion. This can be created as in the sample example below:

As you can see in the example we have created a simple collapsible component, unlike accordion, we haven't added the attribute data-parent.

Usage

Following table lists the classes collapse plugin utilizes to handle the heavy lifting:

Class

Description

.collapse

hides the content

.collapse.in

shows the content

.collapsing

is added when the transition starts, and removed when it finishes

You can use collapse plugin in two ways:

Via data attributes: Add data-toggle="collapse" and a data-target to the element to automatically assign control of a collapsible element. The data-target attribute will accept a CSS selector to apply the collapse to. Be sure to add the class .collapse to the collapsible element. If you’d like it to default open, include the additional class .in.

To add accordion-like group management to a collapsible control, add the data attribute data-parent="#selector".

Via JavaScript: The collapse method can activated with JavaScript as below:

$('.collapse').collapse()

Carousel Plugin

The Bootstrap carousel is a flexible, responsive way to add a slider to your site. In addition to being responsive, the content is flexible enough to allow images, iframes, videos, or just about any type of content that you might want.

If you want to include this plugin functionality individually, then you will need carousel.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Example

A simple slideshow below shows a generic component for cycling through elements like a carousel, using the Bootstrap carousel plugin. To implement the carousel, you just need to add the code with the markup. There is no need for data attributes, just simple class-based development.

Affix Plugin

The affix plugin allows a <div> to become affixed to a location on the page. You can also toggle it's pinning on and off using this plugin. A common example of this is social icons. They will start in a location, but as the page hits a certain mark, the <div> will become locked in place and will stop scrolling with the rest of the page.

If you want to include this plugin functionality individually, then you will need affix.js. Else, as mentioned in the chapter Bootstrap Plugins Overview, you can include bootstrap.js or the minified bootstrap.min.js.

Usage

You can use the affix plugin via data attributes or manually with your own JavaScript as discussed below.

Via data attributes: To easily add affix behavior to any element, just add data-spy="affix" to the element you want to spy on. Use offsets to define when to toggle the pinning of an element.