Bootstrap Manual
Bootstrap Manual
Bootstrap Tutorial
Bootstrap is the most popular and powerful front-end (HTML, CSS, and
JavaScript) framework for faster and easier responsive web development.
Bootstrap gives you ability to create flexible and responsive web layouts with
much less efforts.
You can save a lot of time and effort with Bootstrap. So bookmark this website
and continue on.
Tip: Our Bootstrap tutorials will help you to learn the basic as well as advanced
features of the Bootstrap step-by-step through easy-to-understand explanation
of every topic. If you're a beginner, start with the basics and gradually move
forward by learning a little bit every day.
The list does not end here, there are many other interesting things that you can
do with Bootstrap. You will learn about all of them in detail in upcoming chapters.
Advantages of Using Bootstrap
If you have had some experience with any front-end framework, you might be
wondering what makes Bootstrap so special. Here are some advantages why one
should opt for Bootstrap framework:
Save lots of time — You can save lots of time and efforts using the Bootstrap
predefined design templates and classes and concentrate on other
development work.
Responsive features — Using Bootstrap you can easily create responsive
websites that 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 the design and layout of your
web pages will be consistent.
Easy to use — Bootstrap is very easy to use. Anybody with the basic working
knowledge of HTML, CSS and JavaScript can start development with Bootstrap.
Compatible with browsers — Bootstrap is created with modern web browsers in
mind and it is compatible with all modern browsers such as Chrome, Firefox,
Safari, Internet Explorer, etc.
Open Source — And the best part is, it is completely free to download and use.
Further you will learn how to utilize the ready to use Bootstrap components such
as input groups, button groups, media objects, navbar, panels, pagination, labels
and badges, progress bars, etc. as well as how to customize them to create their
different variations.
Finally, you will explore some advanced features of the Bootstrap like creating
modal window, dynamic tabs, tooltips, alerts, accordion menu, carousel, scrollspy,
etc. as well as how to customize them or extend their existing functionality using
the available options and methods.
Tip: Every chapter in this tutorial contains lots of real-world examples that you
can try and test using an online editor. These examples will help you to better
understand the concept or topic. It also contains smart workarounds as well as
useful tips and important notes.
Chapter 2
If you're just starting out in the world of web development, start learning from
here »
Well, let's get started creating our first Bootstrap powered web page.
Let's walk through the following steps. At the end of this tutorial, you'll have
made a simple Bootstrap powered web page that displays "Hello world" message
in your web browser.
Step 1: Creating a Basic HTML file
Open up your favorite code editor and create a new HTML file. Start with an
empty window and type the following code and save it as "basic.html" on your
desktop.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1, shrink-to-fit=no">
<title>Basic HTML File</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
Tip: Always include the viewport <meta> tag inside the <head> section of your
document to enable touch zooming and ensure proper rendering on mobile
devices.
You should include JavaScript files at the bottom of the page, right before the
closing </body> tag to improve the performance of your web pages, as shown in
the following example:
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1, shrink-to-fit=no">
<title>Basic Bootstrap Template</title>
<!-- Bootstrap CSS file -->
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/boo
tstrap.min.css">
</head>
<body>
<h1>Hello, world!</h1>
<!-- JS files: jQuery first, then Popper.js, then Bootstrap
JS -->
<script src="https://code.jquery.com/jquery-
3.5.1.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popp
er.min.js"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/boots
trap.min.js"></script>
</body>
</html>
And we're all set! After adding the Bootstrap's CSS and JS files and the required
jQuery and Popper.js library, we can begin to develop any site or application with
the Bootstrap framework.
The attributes integrity and crossorigin have been added to CDN links to
implement Subresource Integrity (SRI). It is a security feature that enables you
to mitigate the risk of attacks originating from compromised CDNs, by ensuring
that the files your website fetches (from a CDN or anywhere) have been delivered
without unexpected or malicious modifications. It works by allowing you to
provide a cryptographic hash that a fetched file must match.
Tip: If the visitor to your website has already downloaded the Bootstrap's CSS
and JS 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.
To open this file in a web browser, navigate to it, then right click on it, and select
your favorite web browser. Alternatively, you can open your browser and drag
this file to it.
Note: It is important that the extension .html is specified, some text editors, such
as Notepad on Windows, will automatically save it as .txt otherwise.
Download and unzip the compiled Bootstrap. Now if you look inside the folders
you'll find it contains the compiled CSS and JS files (bootstrap.*), as well as the
compiled and minified CSS and JS (bootstrap.min.*). Use
the bootstrap.min.css and bootstrap.min.js files.
Using the minified version of CSS and JS files will improve the performance of
your website and saves the precious bandwidth because of lesser HTTP request
and download size.
Tip: Please note that Bootstrap's JavaScript plugins require jQuery to be included.
You can download the latest version of jQuery form
here https://jquery.com/download/. You also need to include Popper.js before
Bootstrap's JS in order for tooltips to work!
Chapter 3
Bootstrap 4 includes predefined grid classes for quickly making grid layouts for
different types of devices like cell phones, tablets, laptops and desktops, etc. For
example, you can use the .col-* classes to create grid columns for extra small
devices mobile phones in portrait mode, similarly you can use the .col-sm-
* classes to create grid columns for small screen devices like mobile phone in
landscape mode, the .col-md-* classes for medium screen devices like tablets,
the .col-lg-* classes for large devices like desktops, and the .col-xl-* classes
for extra large desktop screens.
The following table summarizes some of the key features of the new grid system.
Number of columns 12
Nestable Yes
The above table demonstrates one important thing, applying any .col-sm-* class
to an element will not only affect its styling on small devices, but also on
medium, large and extra large devices having screen width greater than or equal
to 540px, if a .col-md-*, .col-lg-* or .col-xl-* class is not present. Similarly,
the .col-md-* class will not only affect the styling of elements on medium
devices, but also on large and extra large devices if a .col-lg-* or .col-xl- 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
that acts as a wrapper for your rows and columns using the .container class,
after that create rows inside the container using the .row class, and to create
columns inside any row you can use the .col-*, .col-sm-*, .col-md-*, .col-lg-
* and .col-xl-* classes. The columns are actual content area where we will place
our contents. Let's put all these things into real action. Let's see how it actually
works:
Creating Two Column Layouts
The following example will show you how to create two column layouts for
medium, large and extra large devices like tables, laptops and desktops etc.
However, on mobile phones (screen width less than 768px), the columns will
automatically become horizontal.
Example
Try this code »
<div class="container">
<!--Row with two equal columns-->
<div class="row">
<div class="col-md-6">Column left</div>
<div class="col-md-6">Column right</div>
</div>
Note: In a grid layout, content must be placed inside columns (.col and .col-*)
and only columns may be the immediate children of rows (.row). Rows should be
placed inside a .container (fixed-width) or .container-fluid (full-width) for
proper padding and alignment.
Tip: Grid column widths are set in percentages, so they're always fluid and sized
relative to their parent element. In addition, each column has horizontal padding
(called a gutter) for controlling the space between individual columns.
Since the Bootstrap grid system is based on 12 columns, therefore to keep the
columns in a one line (i.e. side by side), the sum of the grid column numbers
within a single row should not be greater than 12. If you go through the above
example code carefully you will find the numbers of grid columns (i.e. col-md-*)
add up to twelve (6+6, 4+8 and 3+9) for every row.
Example
Try this code »
<div class="container">
<!--Row with three equal columns-->
<div class="row">
<div class="col-lg-4">Column left</div>
<div class="col-lg-4">Column middle</div>
<div class="col-lg-4">Column right</div>
</div>
Let's try out the following example to understand how it exactly works:
Example
Try this code »
<div class="container">
<!--Row with two equal columns-->
<div class="row">
<div class="col">Column one</div>
<div class="col">Column two</div>
</div>
Additionally, you can also set the width of one column and let the sibling
columns automatically resize around it equally. You may use the predefined grid
classes or inline widths.
If you try the following example you'll find columns in a row with class .col has
equal width.
Example
Try this code »
<div class="container">
<!--Row with two equal columns-->
<div class="row">
<div class="col">Column one</div>
<div class="col">Column two</div>
</div>
Example
Try this code »
<div class="container">
<div class="row">
<div class="col-md-4 col-lg-3">Column one</div>
<div class="col-md-8 col-lg-6">Column two</div>
<div class="col-md-12 col-lg-3">Column three</div>
</div>
</div>
As you can see in the example above the sum of the medium grid column
numbers (i.e. col-md-*) is 3 + 9 + 12 = 24 > 12, therefore the
third <div> element with the class .col-md-12 that is adding the extra columns
beyond the maximum 12 columns in a .row, gets wrapped onto a new line as one
contiguous unit on the medium screen size devices.
Similarly, you can create even more adaptable layouts for your websites using the
Bootstrap's grid column wrapping 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 large screen size devices like laptops and desktops it is rendered as
three column grid layout which has 3 columns and 4 rows and finally in extra
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 grid system. Let's start with the primary target device. Suppose
our primary target device is laptop or normal desktop. Since our laptop layout
has 3 columns and 4 rows i.e. 3x4 grid layout, so the HTML code for making such
grid structure would look something like this.
Example
Try this code »
<div class="container">
<div class="row">
<div class="col-lg-4"><p>Box 1</p></div>
<div class="col-lg-4"><p>Box 2</p></div>
<div class="col-lg-4"><p>Box 3</p></div>
<div class="col-lg-4"><p>Box 4</p></div>
<div class="col-lg-4"><p>Box 5</p></div>
<div class="col-lg-4"><p>Box 6</p></div>
<div class="col-lg-4"><p>Box 7</p></div>
<div class="col-lg-4"><p>Box 8</p></div>
<div class="col-lg-4"><p>Box 9</p></div>
<div class="col-lg-4"><p>Box 10</p></div>
<div class="col-lg-4"><p>Box 11</p></div>
<div class="col-lg-4"><p>Box 12</p></div>
</div>
</div>
If you see the output of the above example in a laptop or desktop which has
screen or viewport width greater than or equal to 992px but less than 1200px,
you will find the layout has 4 rows where each row has 3 equal columns resulting
in 3x4 grid layout.
Now it's time to customize our layout for other devices. Let's first start by
customizing it for tablet device. Since inside the tablet our layout rendered as 2x6
grids (i.e. 2 columns and 6 rows). So, go ahead and add the class .col-md-6 on
every column.
Example
Try this code »
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-6"><p>Box 1</p></div>
<div class="col-lg-4 col-md-6"><p>Box 2</p></div>
<div class="col-lg-4 col-md-6"><p>Box 3</p></div>
<div class="col-lg-4 col-md-6"><p>Box 4</p></div>
<div class="col-lg-4 col-md-6"><p>Box 5</p></div>
<div class="col-lg-4 col-md-6"><p>Box 6</p></div>
<div class="col-lg-4 col-md-6"><p>Box 7</p></div>
<div class="col-lg-4 col-md-6"><p>Box 8</p></div>
<div class="col-lg-4 col-md-6"><p>Box 9</p></div>
<div class="col-lg-4 col-md-6"><p>Box 10</p></div>
<div class="col-lg-4 col-md-6"><p>Box 11</p></div>
<div class="col-lg-4 col-md-6"><p>Box 12</p></div>
</div>
</div>
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 extra large devices like a large desktop
screen by adding the class .col-xl-3 on each column, as every row in our extra
large device layout contains 4 columns. Here's the final code after combining the
whole process.
Example
Try this code »
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
1</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
2</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
3</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
4</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
5</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
6</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
7</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
8</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
9</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
10</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
11</p></div>
<div class="col-lg-4 col-md-6 col-xl-3"><p>Box
12</p></div>
</div>
</div>
Tip: According to the above illustration there is no need to customize the layout
for mobile phones; since columns on extra small devices will automatically
become horizontal and rendered as 1x12 column grid layout in absence of .col-
* or .col-sm-* classes.
Example
Try this code »
<div class="container">
<div class="row">
<div class="col-sm-8">Column left</div>
<div class="col-sm-4">
<!--Column right with nested rows and columns-->
<div class="row">
<div class="col-12"></div>
</div>
<div class="row">
<div class="col-6"></div>
<div class="col-6"></div>
</div>
</div>
</div>
</div>
Example
Try this code »
<div class="container">
<div class="row justify-content-md-center">
<div class="col-md-3">Column left</div>
<div class="col-md-auto">Variable width column</div>
<div class="col-md-3">Column right</div>
</div>
<div class="row">
<div class="col">Column left</div>
<div class="col-auto">Variable width column</div>
<div class="col">Column right</div>
</div>
</div>
<div class="container">
<div class="row align-items-start">
<div class="col">Column one</div>
<div class="col">Column two</div>
<div class="col">Column three</div>
</div>
<div class="row align-items-center">
<div class="col">Column one</div>
<div class="col">Column two</div>
<div class="col">Column three</div>
</div>
<div class="row align-items-end">
<div class="col">Column one</div>
<div class="col">Column two</div>
<div class="col">Column three</div>
</div>
</div>
Individual columns inside a row can also be aligned vertically. Here's an example:
Example
Try this code »
<div class="container">
<div class="row">
<div class="col align-self-start">Column one</div>
<div class="col align-self-center">Column two</div>
<div class="col align-self-end">Column three</div>
</div>
</div>
Note: You can skip the number in .col-* grid class and just use the .col class to
create equal size columns for all devices (extra small, small, medium, large, and
extra large).
Horizontal Alignment of Grid Columns
You can use the classes .justify-content-start, .justify-content-center,
and .justify-content-end to align the grid columns horizontally at the left,
center and right of a container, respectively. Let's check out the following
example to see how it works:
Example
Try this code »
<div class="container">
<div class="row justify-content-start">
<div class="col-4">Column one</div>
<div class="col-4">Column two</div>
</div>
<div class="row justify-content-center">
<div class="col-4">Column one</div>
<div class="col-4">Column two</div>
</div>
<div class="row justify-content-end">
<div class="col-4">Column one</div>
<div class="col-4">Column two</div>
</div>
</div>
Example
Try this code »
<div class="container">
<div class="row justify-content-around">
<div class="col-4">Column one</div>
<div class="col-4">Column two</div>
</div>
<div class="row justify-content-between">
<div class="col-4">Column one</div>
<div class="col-4">Column two</div>
</div>
</div>
Reordering of Grid Columns
You can even change the visual order of your grid columns without changing
their order in actual markup. Use the class .order-last to order the column in
last, whereas use the class .order-first to order the column at first place. Let's
checkout an example:
Example
Try this code »
<div class="container">
<div class="row">
<div class="col order-last">First, but ordered at
last</div>
<div class="col">Second, but unordered</div>
<div class="col order-first">Last, but ordered at
first</div>
</div>
</div>
You can also use the .order-* classes to order the grid columns depending on
the order numbers. Grid column with higher order number comes after the grid
column with lower order number or grid column with no order classes. It includes
support for 1 through 12 across all five grid tiers.
Example
Try this code »
<div class="container">
<div class="row">
<div class="col order-4">First, but ordered at
last</div>
<div class="col">Second, but ordered at first</div>
<div class="col order-1">Last, but ordered at
second</div>
</div>
</div>
Offsetting the Grid Columns
You can also move grid columns to the right for alignment purpose using the
column offset classes like .offset-sm-*, .offset-md-*, .offset-lg-*, and so on.
These classes offset the columns by simply increasing its left margin by specified
number of columns. For example, the class .offset-md-4 on column .col-md-
8 moves it to the right over four columns from its original position. Try out the
following example to see how it works:
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 offset-sm-4"><!--Column with 4
columns offset--></div>
</div>
</div>
You can also offset columns using the margin utility classes. These classes are
useful in the situations where the width of the offset is not fixed. Here's an
example:
Example
Try this code »
<div class="container">
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4 ml-auto"><!--Offset this column to
right--></div>
</div>
<div class="row">
<div class="col-auto mr-auto"></div>
<div class="col-auto"><!--Move this column away from
previous column--></div>
</div>
</div>
Note: You can use the class .col-auto to create columns that only take up as
much space as needed, i.e. the column sizes itself based on the contents.
Example
Try this code »
Example
Try this code »
<div class="container">
<!-- Break columns on all devices -->
<div class="row">
<div class="col">.col</div>
<div class="col">.col</div>
<div class="w-100"></div>
<div class="col">.col</div>
<div class="col">.col</div>
</div>
<!-- Break columns on all devices except extra large devices
-->
<div class="row">
<div class="col">.col</div>
<div class="col">.col</div>
<div class="w-100 d-xl-none"></div>
<div class="col">.col</div>
<div class="col">.col</div>
</div>
</div>
We hope you've understood the basics of new Bootstrap 4 grid system. In next
few chapters you'll learn how to create basic web page layouts using this flexbox
grid system.
Chapter 4
The process of creating the fixed yet responsive layout basically starts with
the .container class. After that you can create rows with the .row class to wrap the
horizontal groups of columns. Rows must be placed within a .container for proper
alignment and padding.
Further columns can be created inside a row using predefined grid classes
like .col-*, .col-sm-*, .col-md-*, .col-lg-* and .col-xl-* where * represent grid
number and should be from 1 to 12. Please check out the Bootstrap grid
system tutorial to learn more about grid classes.
Note: Actual content like text, images, videos, tables, etc. should be placed within
columns, and only columns may be the immediate children of rows.
The following example creates a fixed width responsive layout that is 720px pixels
wide on medium devices having screen width greater than or equal to 768px like
tablets, whereas 960px wide on large devices having screen width greater than or
equal to 992px like small laptops, and 1140px wide on extra large devices having
screen width greater than or equal to 1200px like desktops.
However, if the device's viewport width is less than 768px but greater than or
equal to 576px the layout will be 540px wide. For viewport width less than 576px
the layout will cover 100% width. Also, columns will be stacked vertically navbar
will be collapsed in both cases.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Fixed Layout Example</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-
3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-3">
<div class="container">
<a href="#" class="navbar-brand mr-3">Tutorial
Republic</a>
<button type="button" class="navbar-toggler" data-
toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarCollapse">
<div class="navbar-nav">
<a href="#" class="nav-item nav-link
active">Home</a>
<a href="#" class="nav-item nav-
link">Services</a>
<a href="#" class="nav-item nav-link">About</a>
<a href="#" class="nav-item nav-
link">Contact</a>
</div>
<div class="navbar-nav ml-auto">
<a href="#" class="nav-item nav-
link">Register</a>
<a href="#" class="nav-item nav-link">Login</a>
</div>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Learn to Create Websites</h1>
<p class="lead">In today's world internet is the most
popular way of connecting with the people. At <a
href="https://www.tutorialrepublic.com"
target="_blank">tutorialrepublic.com</a> you will learn the
essential web development technologies along with real life
practice examples, so that you can create your own website to
connect with the people around the world.</p>
<p><a href="https://www.tutorialrepublic.com"
target="_blank" class="btn btn-success btn-lg">Get started
today</a></p>
</div>
<div class="row">
<div class="col-md-4">
<h2>HTML</h2>
<p>HTML is the standard markup language for
describing the structure of the web pages. Our HTML tutorials
will help you to understand the basics of latest HTML5 language,
so that you can create your own web pages or website.</p>
<p><a href="https://www.tutorialrepublic.com/html-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-4">
<h2>CSS</h2>
<p>CSS is used for describing the presentation of
web pages. CSS can save a lot of time and effort. Our CSS
tutorials will help you to learn the essentials of latest CSS3,
so that you can control the style and layout of your
website.</p>
<p><a href="https://www.tutorialrepublic.com/css-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-4">
<h2>Bootstrap</h2>
<p>Bootstrap is a powerful front-end framework for
faster and easier web development. Our Bootstrap tutorials will
help you to learn all the features of latest Bootstrap 4
framework so that you can easily create responsive websites.</p>
<p><a
href="https://www.tutorialrepublic.com/twitter-bootstrap-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
</div>
<hr>
<footer>
<div class="row">
<div class="col-md-6">
<p>Copyright © 2019 Tutorial Republic</p>
</div>
<div class="col-md-6 text-md-right">
<a href="#" class="text-dark">Terms of Use</a>
<span class="text-muted mx-2">|</span>
<a href="#" class="text-dark">Privacy Policy</a>
</div>
</div>
</footer>
</div>
</body>
</html>
— The output of the above example will look something like this:
We've used the margin utility classes such as .mb-3, .ml-auto, mx-2 etc. to adjust
spacing between the elements. Whereas the classes .text-dark, .text-muted, .text-
md-right are text utility classes to adjust color and alignment of text. You'll learn
about them in later chapters.
Chapter 5
The class .container-fluid simply applies the width: 100% instead of different width
for different viewport sizes. However, the layout will still responsive and you can
use the grid classes as usual. See the tutorial on Bootstrap grid system to learn
more about grid classes.
The following example will create a fluid layout that covers 100% width of the
screen.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Fluid Layout Example</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-
3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-3">
<div class="container-fluid">
<a href="#" class="navbar-brand mr-3">Tutorial
Republic</a>
<button type="button" class="navbar-toggler" data-
toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarCollapse">
<div class="navbar-nav">
<a href="#" class="nav-item nav-link
active">Home</a>
<a href="#" class="nav-item nav-
link">Services</a>
<a href="#" class="nav-item nav-link">About</a>
<a href="#" class="nav-item nav-
link">Contact</a>
</div>
<div class="navbar-nav ml-auto">
<a href="#" class="nav-item nav-
link">Register</a>
<a href="#" class="nav-item nav-link">Login</a>
</div>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="jumbotron">
<h1>Learn to Create Websites</h1>
<p class="lead">In today's world internet is the most
popular way of connecting with the people. At <a
href="https://www.tutorialrepublic.com"
target="_blank">tutorialrepublic.com</a> you will learn the
essential web development technologies along with real life
practice examples, so that you can create your own website to
connect with the people around the world.</p>
<p><a href="https://www.tutorialrepublic.com"
target="_blank" class="btn btn-success btn-lg">Get started
today</a></p>
</div>
<div class="row">
<div class="col-md-4">
<h2>HTML</h2>
<p>HTML is the standard markup language for
describing the structure of the web pages. Our HTML tutorials
will help you to understand the basics of latest HTML5 language,
so that you can create your own web pages or website.</p>
<p><a href="https://www.tutorialrepublic.com/html-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-4">
<h2>CSS</h2>
<p>CSS is used for describing the presentation of
web pages. CSS can save a lot of time and effort. Our CSS
tutorials will help you to learn the essentials of latest CSS3,
so that you can control the style and layout of your
website.</p>
<p><a href="https://www.tutorialrepublic.com/css-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-4">
<h2>Bootstrap</h2>
<p>Bootstrap is a powerful front-end framework for
faster and easier web development. Our Bootstrap tutorials will
help you to learn all the features of latest Bootstrap 4
framework so that you can easily create responsive websites.</p>
<p><a
href="https://www.tutorialrepublic.com/twitter-bootstrap-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
</div>
<hr>
<footer>
<div class="row">
<div class="col-md-6">
<p>Copyright © 2019 Tutorial Republic</p>
</div>
<div class="col-md-6 text-md-right">
<a href="#" class="text-dark">Terms of Use</a>
<span class="text-muted mx-2">|</span>
<a href="#" class="text-dark">Privacy Policy</a>
</div>
</div>
</footer>
</div>
</body>
</html>
— The output of the above example will look something like this:
Chapter 6
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. See the following
Illustration.
Creating Responsive Layout with Bootstrap
With the Bootstrap 4 powerful mobile first flexbox grid system creating the
responsive and mobile friendly websites and applications has become much
easier.
Bootstrap 4 is responsive and mobile friendly from the start. Its five tier grid
classes provides better control over the layout as well as how it will be rendered
on different types of devices like mobile phones, tablets, laptops and desktops,
large screen devices, and so on.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1, shrink-to-fit=no">
<title>Bootstrap 4 Responsive Layout Example</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-
3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-3">
<div class="container-fluid">
<a href="#" class="navbar-brand mr-3">Tutorial
Republic</a>
<button type="button" class="navbar-toggler" data-
toggle="collapse" data-target="#navbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarCollapse">
<div class="navbar-nav">
<a href="#" class="nav-item nav-link
active">Home</a>
<a href="#" class="nav-item nav-
link">Services</a>
<a href="#" class="nav-item nav-link">About</a>
<a href="#" class="nav-item nav-
link">Contact</a>
</div>
<div class="navbar-nav ml-auto">
<a href="#" class="nav-item nav-
link">Register</a>
<a href="#" class="nav-item nav-link">Login</a>
</div>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Learn to Create Websites</h1>
<p class="lead">In today's world internet is the most
popular way of connecting with the people. At <a
href="https://www.tutorialrepublic.com"
target="_blank">tutorialrepublic.com</a> you will learn the
essential web development technologies along with real life
practice examples, so that you can create your own website to
connect with the people around the world.</p>
<p><a href="https://www.tutorialrepublic.com"
target="_blank" class="btn btn-success btn-lg">Get started
today</a></p>
</div>
<div class="row">
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>HTML</h2>
<p>HTML is the standard markup language for
describing the structure of the web pages. Our HTML tutorials
will help you to understand the basics of latest HTML5 language,
so that you can create your own website.</p>
<p><a href="https://www.tutorialrepublic.com/html-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>CSS</h2>
<p>CSS is used for describing the presentation of
web pages. CSS can save a lot of time and effort. Our CSS
tutorials will help you to learn the essentials of latest CSS3,
so that you can control the style and layout of your
website.</p>
<p><a href="https://www.tutorialrepublic.com/css-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>JavaScript</h2>
<p>JavaScript is the most popular and widely used
client-side scripting language. Our JavaScript tutorials will
provide in-depth knowledge of the JavaScript including ES6
features, so that you can create interactive websites.</p>
<p><a
href="https://www.tutorialrepublic.com/javascript-tutorial/"
target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>Bootstrap</h2>
<p>Bootstrap is a powerful front-end framework for
faster and easier web development. Our Bootstrap tutorials will
help you to learn all the features of latest Bootstrap 4
framework so that you can easily create responsive websites.</p>
<p><a
href="https://www.tutorialrepublic.com/twitter-bootstrap-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>PHP</h2>
<p>PHP is the most popular server-side scripting
language for creating dynamic web pages. Our PHP tutorials will
help you to learn all the features of latest PHP7 scripting
language so that you can easily create dynamic websites.</p>
<p><a
href="https://www.tutorialrepublic.com/twitter-bootstrap-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>SQL</h2>
<p>SQL is a standard language designed for managing
data in relational database management system. Our SQL tutorials
will help you to learn the fundamentals of the SQL language so
that you can efficiently manage your databases.</p>
<p><a
href="https://www.tutorialrepublic.com/twitter-bootstrap-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>References</h2>
<p>Our references section outlines all the standard
HTML5 tags and CSS3 properties along with other useful
references such as color names and values, character entities,
web safe fonts, language codes, HTTP messages, and more.</p>
<p><a
href="https://www.tutorialrepublic.com/twitter-bootstrap-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
<div class="col-md-6 col-lg-4 col-xl-3">
<h2>FAQ</h2>
<p>Our Frequently Asked Questions (FAQ) section is
an extensive collection of FAQs that provides quick and working
solution of common questions and queries related to web design
and development with live demo.</p>
<p><a
href="https://www.tutorialrepublic.com/twitter-bootstrap-
tutorial/" target="_blank" class="btn btn-success">Learn More
»</a></p>
</div>
</div>
<hr>
<footer>
<div class="row">
<div class="col-md-6">
<p>Copyright © 2019 Tutorial Republic</p>
</div>
<div class="col-md-6 text-md-right">
<a href="#" class="text-dark">Terms of Use</a>
<span class="text-muted mx-2">|</span>
<a href="#" class="text-dark">Privacy Policy</a>
</div>
</div>
</footer>
</div>
</body>
</html>
Tip: Open the output of this example in new blank window (click the link
inside the CodeLab editor) 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).
Chapter 7
Bootstrap Typography
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 »
Example
Try this code »
<h2>
Fancy display heading
<small class="text-muted">With faded secondary text</small>
</h2>
— The output of the above example will look something like this:
Display Headings
Bootstrap 4 introduces display headings that can be used when you need a
heading to stand out. Display headings are displayed in larger font-size but
lighter font-weight.
Example
Try this code »
You can also make a paragraph stand out by adding the class .lead on it.
Example
Try this code »
Tip: In CSS rem stands for "root em". 1rem is equal to the font size of the root
element (i.e. the <html> element), which is 16px in most browsers by default.
You can easily align text left, right, and center inside a paragraph using the text
alignment classes.
Example
Try this code »
You can also align text based on screen size using the responsive text alignment
classes. These classes use the same viewport width breakpoints as the grid
system.
Example
Try this code »
Example
Try this code »
— The output of the above example will look something like this:
Text Transformation
You can also transform the text to lowercase, uppercase or make them capitalize.
Example
Try this code »
— The output of the above example will look something like this:
Text Coloring
Colors are the powerful method of conveying important information in website
design.
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 »
— 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 <blockquote> element and bootstrap's style sheet will do the
rest.
Moreover, for identifying the source you can add a <footer> element with
class .blockquote-footer, and wrap the name of the source work in <cite>, like
this:
Example
Try this code »
<blockquote class="blockquote">
<p class="mb-0">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>
<footer class="blockquote-footer">by <cite>Albert
Einstein</cite></footer>
</blockquote>
— The output of the above example will look something like this:
You can also align blockquotes to right or center by simply applying the text
alignment classes .text-right or .text-center on the <blockquote> element.
Chapter 8
Bootstrap Tables
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 quick and
easy way.
Example
Try this code »
<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>Clark</td>
<td>Kent</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
<td>John</td>
<td>Carter</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>Peter</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
— The output of the above example will look something like this:
You can also create inverted version of this table, i.e. table with light text on dark
backgrounds, by adding an extra class .table-dark to the .table base class, like
this:
Example
Try this code »
— The output of the above example will look something like this:
Tip: You can add an extra class .table-dark to the .table element to create dark
version of any table such as stripped, hoverable, bordered, compact table, and so
on.
Creating Tables with Striped Rows
You can create table with alternate background like zebra-stripes by simply
adding the Bootstrap's class .table-striped to the .table base class.
Example
Try this code »
Similarly, you can also create inverted or dark version of the stripped table
adding an extra class .table-dark to the table, as shown in the following example:
Example
Try this code »
Example
Try this code »
— 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:
— The output of the above example will look something like this:
Creating Small or Compact Table
You can also make your tables more compact and save the space through adding
an extra class .table-sm to the .table base class. The class .table-sm makes the
table compact by cutting the cell padding in half. Here's an example of a small
table:
Example
Try this code »
The following example uses the class .thead-light to create a table with light
head.
Example
Try this code »
<table class="table">
<thead class="thead-light">
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Clark</td>
<td>Kent</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
<td>John</td>
<td>Carter</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>Peter</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
— The output of the above example will look something like this:
Likewise, you can use the class .thead-dark to create a table with dark head.
Example
Try this code »
<table class="table">
<thead class="thead-dark">
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Clark</td>
<td>Kent</td>
<td>[email protected]</td>
</tr>
<tr>
<td>2</td>
<td>John</td>
<td>Carter</td>
<td>[email protected]</td>
</tr>
<tr>
<td>3</td>
<td>Peter</td>
<td>Parker</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
— 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="table-primary">
<td>1</td>
<td>Credit Card</td>
<td>04/07/2019</td>
<td>Waiting for statement</td>
</tr>
<tr class="table-secondary">
<td>2</td>
<td>Insurance</td>
<td>02/07/2019</td>
<td>Cancelled</td>
</tr>
<tr class="table-success">
<td>3</td>
<td>Water</td>
<td>01/07/2019</td>
<td>Paid</td>
</tr>
<tr class="table-info">
<td>4</td>
<td>Internet</td>
<td>05/07/2019</td>
<td>Change plan</td>
</tr>
<tr class="table-warning">
<td>5</td>
<td>Electricity</td>
<td>03/07/2019</td>
<td>Pending</td>
</tr>
<tr class="table-danger">
<td>6</td>
<td>Telephone</td>
<td>06/07/2019</td>
<td>Due</td>
</tr>
<tr class="table-active">
<td>7</td>
<td>DTH</td>
<td>04/07/2019</td>
<td>Deactivated</td>
</tr>
<tr class="table-light">
<td>8</td>
<td>Car Service</td>
<td>08/07/2019</td>
<td>Call in to confirm</td>
</tr>
<tr class="table-dark">
<td>9</td>
<td>Gas</td>
<td>06/07/2019</td>
<td>Payment failed</td>
</tr>
</tbody>
</table>
— The output of the above example will look something like this:
Creating Responsive Tables with Bootstrap
You can also create responsive tables to enable horizontal scrolling on small
devices.
To make any table responsive just place the table inside a <div> element and
apply the class .table-responsive on it. You can also specify when the table should
have a scrollbar, based on the screen width, using the classes .table-responsive{-
sm|-md|-lg|-xl}
Example
Try this code »
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Row</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Biography</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Clark</td>
<td>Kent</td>
<td>[email protected]</td>
<td>Lorem ipsum dolor sit amet...</td>
</tr>
<tr>
<td>2</td>
<td>John</td>
<td>Carter</td>
<td>[email protected]</td>
<td>Vestibulum consectetur scelerisque...</td>
</tr>
<tr>
<td>3</td>
<td>Peter</td>
<td>Parker</td>
<td>[email protected]</td>
<td>Integer pulvinar leo id risus...</td>
</tr>
</tbody>
</table>
</div>
Chapter 9
Bootstrap Lists
In this tutorial you will learn how to style HTML 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, e.g. 1, ⅵ, etc.
Definition list — A list of terms with their associated descriptions.
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:
Example
Try this code »
<ul class="list-inline">
<li class="list-inline-item">Home</li>
<li class="list-inline-item">Products</li>
<li class="list-inline-item">About Us</li>
<li class="list-inline-item">Contact</li>
</ul>
— The output of the above example will look something like this:
Creating Horizontal Definition Lists
The terms and descriptions in a definition list can also be aligned horizontally
side-by-side using the Bootstrap grid system's predefined classes. Here's an
example:
Example
Try this code »
<dl class="row">
<dt class="col-sm-3">User Agent</dt>
<dd class="col-sm-9">An HTML user agent is any device that
interprets HTML documents.</dd>
<dt class="col-sm-3 text-truncate">Client-side
Scripting</dt>
<dd class="col-sm-9">Client-side scripting generally refers
to the category of computer programs on the web that are
executed by the user's web browser.</dd>
<dt class="col-sm-3">Document Tree</dt>
<dd class="col-sm-9">The tree of elements encoded in the
source document.</dd>
</dl>
— The output of the above example will look something like this:
Note: For longer definition terms, you can optionally apply the class .text-
truncate on the <dt> element to truncate the text with an ellipsis (…).
In the next chapter you will learn how to create even more flexible and complex
list of elements using the Bootstrap list group component.
Chapter 10
Example
Try this code »
<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>
<li class="list-group-item">Videos</li>
</ul>
— The output of the above example will look something like this:
List Group with Linked Items
You can also hyperlink list group items with the little change in HTML markup.
Just replace the <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. Here's an example:
Example
Try this code »
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action
active">
<i class="fa fa-home"></i> Home
</a>
<a href="#" class="list-group-item list-group-item-action">
<i class="fa fa-camera"></i> Pictures <span class="badge
badge-pill badge-primary pull-right">145</span>
</a>
<a href="#" class="list-group-item list-group-item-action">
<i class="fa fa-music"></i> Music <span class="badge
badge-pill badge-primary pull-right">50</span>
</a>
<a href="#" class="list-group-item list-group-item-action">
<i class="fa fa-film"></i> Videos <span class="badge
badge-pill badge-primary pull-right">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 the sidebar
navigation menu, e.g. displaying the list of products 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 list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h4>Asteroid detected near earth</h4>
<small>1 days ago</small>
</div>
<p>Pulvinar leo id risus pellentesque vestibulum. Sed
diam libero, sodales eget sapien vel, porttitor bibendum enim.
Donec sed nibh vitae lorem porttitor blandit in nec ante.</p>
</a>
<a href="#" class="list-group-item list-group-item-action
active">
<div class="d-flex w-100 justify-content-between">
<h4>Scientists found massive black hole</h4>
<small>2 days ago</small>
</div>
<p>Vestibulum id metus ac nisl bibendum scelerisque non
non purus. Suspendisse varius nibh non aliquet sagittis. In
tincidunt orci sit amet elementum vestibulum.</p>
</a>
<a href="#" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h4>NASA launches solar probe</h4>
<small>3 days ago</small>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Nam eu sem tempor, varius quam at, luctus dui. Mauris
magna metus, dapibus nec turpis vel, semper malesuada ante.</p>
</a>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<ul class="list-group">
<li class="list-group-item">A simple default list group
item</li>
<li class="list-group-item list-group-item-primary">A simple
primary list group item</li>
<li class="list-group-item list-group-item-secondary">A
simple secondary list group item</li>
<li class="list-group-item list-group-item-success">A simple
success list group item</li>
<li class="list-group-item list-group-item-danger">A simple
danger list group item</li>
<li class="list-group-item list-group-item-warning">A simple
warning list group item</li>
<li class="list-group-item list-group-item-info">A simple
info list group item</li>
<li class="list-group-item list-group-item-light">A simple
light list group item</li>
<li class="list-group-item list-group-item-dark">A simple
dark list group item</li>
</ul>
— 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 .active to specify the active list group item. Here's an
example:
Example
Try this code »
<div class="list-group">
<a href="#" class="list-group-item list-group-item-action">A
simple default list group item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-primary">A simple primary list group item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-secondary">A simple secondary list group
item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-success">A simple success list group item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-danger">A simple danger list group item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-warning">A simple warning list group item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-info">A simple info list group item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-light">A simple light list group item</a>
<a href="#" class="list-group-item list-group-item-action
list-group-item-dark">A simple dark list group item</a>
</div>
Please, check out the Bootstrap tabs chapter to learn how to create dynamic
vertical tabs using the list group component without using any JavaScript code.
Chapter 11
Bootstrap Forms
In this tutorial you will learn how to create elegant forms with Bootstrap.
The following section will give you the detailed overview of all these form layouts
as well as the various form related Bootstrap components one by one. Well let's
get started.
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="form-group">
<label class="form-check-label"><input type="checkbox">
Remember me</label>
</div>
<button type="submit" class="btn btn-primary">Sign
in</button>
</form>
— The output of the above example will look something like this:
Note: All textual form controls, like <input>, <textarea>, and <select> require
the class .form-control for general styling. The .form-control class also makes them
100% wide. To change their width or use them inline, you can utilize the
predefined grid classes.
Creating Horizontal Form Layout
You can also create horizontal form layouts where labels and form controls are
aligned side-by-side using the Bootstrap grid classes. To create a horizontal form
layout add the class .row on form groups and use the .col-*-* grid classes to
specify the width of your labels and controls.
Also, be sure to apply the class .col-form-label on the <label> elements, so that
they're vertically centered with their associated form controls. Let's check out an
example:
Example
Try this code »
<form>
<div class="form-group row">
<label for="inputEmail" class="col-sm-2 col-form-
label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control"
id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-
label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control"
id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group row">
<div class="col-sm-10 offset-sm-2">
<label class="form-check-label"><input
type="checkbox"> Remember me</label>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-primary">Sign
in</button>
</div>
</div>
</form>
— The output of the above example will look something like this:
Example
Try this code »
<form class="form-inline">
<div class="form-group mr-2">
<label class="sr-only" for="inputEmail">Email</label>
<input type="email" class="form-control" id="inputEmail"
placeholder="Email">
</div>
<div class="form-group mr-2">
<label class="sr-only"
for="inputPassword">Password</label>
<input type="password" class="form-control"
id="inputPassword" placeholder="Password">
</div>
<div class="form-group mr-2">
<label><input type="checkbox" class="mr-1"> Remember
me</label>
</div>
<button type="submit" class="btn btn-primary">Sign
in</button>
</form>
— The output of the above example will look something like this:
Check out the snippets section for examples of some beautifully designed
Bootstrap forms.
The .form-control-plaintext class removes the default styling from the form field,
but preserves the correct margin and padding. Let's take a look at an example:
Example
Try this code »
<form>
<div class="form-group row">
<label for="inputEmail" class="col-sm-2 col-form-
label">Email</label>
<div class="col-sm-10">
<input type="text" readonly class="form-control-
plaintext" id="inputEmail" value="[email protected]">
</div>
</div>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-
label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control"
id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group row">
<div class="col-sm-10 offset-sm-2">
<div class="checkbox">
<label><input type="checkbox"> Remember
me</label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-primary">Sign
in</button>
</div>
</div>
</form>
— The output of the above example will look something like this:
Example
Try this code »
Example
Try this code »
Example
Try this code »
However, if you want to disable all controls within a <form> at once place them
inside a <fieldset> element and apply the attribute on it, as shown in the
following example:
Example
Try this code »
<form>
<fieldset disabled>
<div class="form-group row">
<label for="inputEmail" class="col-sm-2 col-form-
label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control"
id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-
label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control"
id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group row">
<div class="col-sm-10 offset-sm-2">
<label class="form-check-label"><input
type="checkbox"> Remember me</label>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-
primary">Sign in</button>
</div>
</div>
</fieldset>
</form>
— The output of the above example will look something like this:
Example
Try this code »
Example
Try this code »
<div class="form-row">
<div class="form-group col-sm-6">
<label for="inputCity">City</label>
<input type="text" class="form-control" id="inputCity">
</div>
<div class="form-group col-sm-4">
<label for="inputState">State</label>
<select id="inputState" class="form-control">
<option>Select</option>
</select>
</div>
<div class="form-group col-sm-2">
<label for="inputZip">Zip</label>
<input type="text" class="form-control" id="inputZip">
</div>
</div>
Tip: You can alternatively use the class .form-row in place of .row while creating
form layouts. The .form-row class is a variation of standard Bootstrap
grid .row which overrides the default column gutters for tighter and more
compact layouts.
Height Sizing of Inputs and Select Boxes
You can easily change the height of your text input and select boxes to match
the button sizes. Use the form control height sizing classes like .form-control-
lg, .form-control-sm on the <input> and <select> boxes to create it's larger or
smaller sizes.
Example
Try this code »
<form>
<div class="form-group row">
<label class="col-sm-2 col-form-label col-form-label-
lg">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control form-
control-lg" placeholder="Large input">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control"
placeholder="Default input">
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control form-
control-sm" placeholder="Small input">
</div>
</div>
<hr>
<div class="form-group row">
<label class="col-sm-2 col-form-label col-form-label-
lg">State</label>
<div class="col-sm-10">
<select class="form-control form-control-lg">
<option>Large select</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">State</label>
<div class="col-sm-10">
<select class="form-control">
<option>Default select</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label col-form-label-
sm">State</label>
<div class="col-sm-10">
<select class="form-control form-control-sm">
<option>Small select</option>
</select>
</div>
</div>
</form>
Example
Try this code »
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control">
<small class="form-text text-muted">
Your password must be 8-20 characters long, contain
letters, numbers and special characters, but must not contain
spaces.
</small>
</div>
— The output of the above example will look something like this:
Similarly, you can also place inline help text using the <small> element. No need to
use .form-text in this case. The following example shows how to implement this:
Example
Try this code »
<form class="form-inline">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control mx-sm-3">
<small class="text-muted">Must be 8-20 characters
long.</small>
</div>
</form>
— The output of the above example will look something like this:
Let's check out the following example to see how it actually works:
Example
Try this code »
Note: For custom Bootstrap form validation messages, you'll need to disables the
browser default feedback tooltips by adding the novalidate boolean attribute to
the <form> element. However, it still provides access to the form validation APIs in
JavaScript.
Here's the custom JavaScript code that displays error messages and disables form
submission if there are invalid fields. See the JavaScript closures chapter to learn
about self-executing function.
Example
Try this code »
<script>
// Self-executing function
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom
Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-
validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms,
function(form) {
form.addEventListener('submit', function(event)
{
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
— The output of the above example will look something like this:
If you require server-side validation, you can indicate invalid and valid form fields
with the .is-invalid and .is-valid. The .invalid-feedback and .valid-feedback are
also supported with these classes. Try out the following example to see how it
works:
Example
Try this code »
<form>
<div class="form-group">
<label for="inputEmail">Email</label>
<input type="email" class="form-control is-valid"
id="inputEmail" placeholder="Email"
value="[email protected]" required>
<div class="valid-feedback">Good! Your email address
looks valid.</div>
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" class="form-control is-invalid"
id="inputPassword" placeholder="Password" required>
<div class="invalid-feedback">Opps! You have entered an
invalid password.</div>
</div>
<div class="form-group">
<label class="form-check-label"><input type="checkbox">
Remember me</label>
</div>
<button type="submit" class="btn btn-primary">Sign
in</button>
</form>
— The output of the above example will look something like this:
You can alternatively swap the .{valid|invalid}-feedback classes
for .{valid|invalid}-tooltip classes to display the validation feedback text in a
tooltip style.
Also, be sure to apply the style position: relative or class .position-relative on the
parent element for proper feedback tooltip positioning. Here's an example:
Example
Try this code »
<form>
<div class="form-group position-relative">
<label for="inputEmail">Email</label>
<input type="email" class="form-control is-valid"
id="inputEmail" placeholder="Email"
value="[email protected]" required>
<div class="valid-tooltip">Good! Your email address
looks valid.</div>
</div>
<div class="form-group position-relative">
<label for="inputPassword">Password</label>
<input type="password" class="form-control is-invalid"
id="inputPassword" placeholder="Password" required>
<div class="invalid-tooltip">Opps! You have entered an
invalid password.</div>
</div>
<div class="form-group">
<label class="form-check-label"><input type="checkbox">
Remember me</label>
</div>
<button type="submit" class="btn btn-primary">Sign
in</button>
</form>
— The output of the above example will look something like this:
Note: Background icons for <select> elements only work properly with .custom-
select, not with .form-control. We will learn about Bootstrap custom forms in next
chapter.
Example
Try this code »
<form>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="firstName">First
Name:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="firstName"
placeholder="First Name" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="lastName">Last
Name:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="lastName"
placeholder="Last Name" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label"
for="inputEmail">Email Address:</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="inputEmail"
placeholder="Email Address" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label"
for="phoneNumber">Mobile Number:</label>
<div class="col-sm-9">
<input type="number" class="form-control"
id="phoneNumber" placeholder="Phone Number" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Date of
Birth:</label>
<div class="col-sm-3">
<select class="custom-select">
<option>Date</option>
</select>
</div>
<div class="col-sm-3">
<select class="custom-select">
<option>Month</option>
</select>
</div>
<div class="col-sm-3">
<select class="custom-select">
<option>Year</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label"
for="postalAddress">Postal Address:</label>
<div class="col-sm-9">
<textarea rows="3" class="form-control"
id="postalAddress" placeholder="Postal Address"
required></textarea>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label" for="ZipCode">Zip
Code:</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="ZipCode"
placeholder="Zip Code" required>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Gender:</label>
<div class="col-sm-9 mt-2">
<label class="mb-0 mr-3">
<input type="radio" class="mr-1" name="gender"> Male
</label>
<label class="mb-0 mr-3">
<input type="radio" class="mr-1" name="gender">
Female
</label>
</div>
</div>
<div class="form-group row">
<div class="col-sm-9 offset-sm-3">
<label class="checkbox-inline">
<input type="checkbox" class="mr-1" value="agree"> I
agree to the <a href="#">Terms and Conditions</a>.
</label>
</div>
</div>
<div class="form-group row">
<div class="col-sm-9 offset-sm-3">
<input type="submit" class="btn btn-primary"
value="Submit">
<input type="reset" class="btn btn-secondary"
value="Reset">
</div>
</div>
</form>
Chapter 12
Bootstrap Custom Forms
In this tutorial you will learn how to create custom form controls with Bootstrap.
In the following sections, you'll see how to create those custom form elements
one by one.
Example
Try this code »
Example
Try this code »
— The output of the above example will look something like this:
You can also place these custom checkboxes and radio buttons inline by simply
adding a class .custom-control-inline on the wrapper <div> element, like this:
Example
Try this code »
— 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:
Creating Toggle Switches
The switch markup is similar to custom checkbox, the only difference is it uses
the .custom-switch class in place of .custom-checkbox to render a toggle switch.
Switches also support the disabled attribute. Let's check out an example:
Example
Try this code »
— The output of the above example will look something like this:
<select class="custom-select">
<option selected>Custom select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
— The output of the above example will look something like this:
You can also create small and large custom selects to match similarly
sized Bootstrap text inputs.
Example
Try this code »
Bootstrap custom select also supports multiple and size attributes like normal
select:
Example
Try this code »
Example
Try this code »
— The output of the above example will look something like this:
By default range inputs have implicit values for min and max—0 and 100,
respectively. But, you may specify new values for those using
the min and max attributes.
Also, range inputs "snap" to integer values by default. To change this, you can
specify a step value. In the following example, we've doubled the number of steps
by using the step="0.5".
Example
Try this code »
Example
Try this code »
<div class="custom-file">
<input type="file" class="custom-file-input"
id="customFile">
<label class="custom-file-label" for="customFile">Choose
file</label>
</div>
— The output of the above example will look something like this:
Tip: Bootstrap hides the default file <input> via opacity and style the <label> to
look like an input instead. The button is generated and positioned
with ::after pseudo element. Finally, the transparent <input> is placed above the
styled <label> using the CSS positioning with proper width and height to trigger
the file picker dialog box.
Chapter 13
Bootstrap Input Groups
In this tutorial you will learn how to use the Bootstrap input group component.
In the following sections you'll see how to extend text-based input fields by
adding the text, icons or buttons before, after, or on both sides of it to make your
form more attractive.
Further, use the class .input-group-prepend to place the addons before the input,
whereas use the class .input-group-append to place the addons after the input.
Also, be sure to wrap the text or icon in a <span> and apply the class .input-group-
text on it for proper rendering and styling. Try out the following example to see
how it works:
Example
Try this code »
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<span class="fa fa-user"></span>
</span>
</div>
<input type="text" class="form-control"
placeholder="Username">
</div>
</div>
<div class="col-sm-4">
<div class="input-group">
<input type="text" class="form-control"
placeholder="Amount">
<div class="input-group-append">
<span class="input-group-text">.00</span>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
<input type="text" class="form-control"
placeholder="US Dollar">
<div class="input-group-append">
<span class="input-group-text">.00</span>
</div>
</div>
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="row">
<div class="col-sm-6">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<input type="checkbox">
</span>
</div>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<input type="radio">
</span>
</div>
<input type="text" class="form-control">
</div>
</div>
</div>
— The output of the above example will look something like this:
Placing Multiple Inputs or Addons
You can also place multiple inputs side-by-side within an input group easily, like
this:
Example
Try this code »
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Your Name</span>
</div>
<input type="text" class="form-control" placeholder="First
name">
<input type="text" class="form-control" placeholder="Last
name">
</div>
— The output of the above example will look something like this:
Similarly, you can also place multiple addons side-by-side within an input group.
You can also mix it with checkbox and radio inputs, as shown in the following
example:
Example
Try this code »
<div class="row">
<div class="col-sm-6">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">
<input type="checkbox">
</span>
<span class="input-group-text">$</span>
</div>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
<span class="input-group-text">0.00</span>
</div>
<input type="text" class="form-control">
</div>
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="row">
<div class="col-sm-5">
<div class="input-group">
<input type="text" class="form-control"
placeholder="Search...">
<div class="input-group-append">
<button type="button" class="btn btn-secondary">
<i class="fa fa-search"></i>
</button>
</div>
</div>
</div>
<div class="col-sm-7">
<div class="input-group">
<input type="text" class="form-control"
placeholder="Type something...">
<div class="input-group-append">
<button type="submit" class="btn btn-
primary">Submit</button>
<button type="reset" class="btn btn-
danger">Reset</button>
</div>
</div>
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="row">
<div class="col-sm-6">
<div class="input-group">
<div class="input-group-prepend">
<button type="button" class="btn btn-outline-
secondary dropdown-toggle" data-
toggle="dropdown">Dropdown</button>
<div class="dropdown-menu">
<a href="#" class="dropdown-item">Action</a>
<a href="#" class="dropdown-item">Another
action</a>
</div>
</div>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-append">
<button type="button" class="btn btn-outline-
secondary dropdown-toggle" data-
toggle="dropdown">Dropdown</button>
<div class="dropdown-menu">
<a href="#" class="dropdown-item">Action</a>
<a href="#" class="dropdown-item">Another
action</a>
</div>
</div>
</div>
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="row">
<div class="col-sm-6">
<div class="input-group">
<div class="input-group-prepend">
<button type="button" class="btn btn-outline-
secondary">Action</button>
<button type="button" class="btn btn-outline-
secondary dropdown-toggle dropdown-toggle-split" data-
toggle="dropdown">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a href="#" class="dropdown-item">Action</a>
<a href="#" class="dropdown-item">Another
action</a>
</div>
</div>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-6">
<div class="input-group">
<input type="text" class="form-control">
<div class="input-group-append">
<button type="button" class="btn btn-outline-
secondary">Action</button>
<button type="button" class="btn btn-outline-
secondary dropdown-toggle dropdown-toggle-split" data-
toggle="dropdown">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a href="#" class="dropdown-item">Action</a>
<a href="#" class="dropdown-item">Another
action</a>
</div>
</div>
</div>
</div>
</div>
— The output of the above example will look something like this:
The contents within the .input-group will automatically resize — there is no need
for repeating the form control size classes on each element. Here's an example:
Example
Try this code »
<!-- Larger input group -->
<div class="input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text">Large</span>
</div>
<input type="text" class="form-control">
</div>
<!-- Default input group -->
<div class="input-group mt-2">
<div class="input-group-prepend">
<span class="input-group-text">Default</span>
</div>
<input type="text" class="form-control">
</div>
<!-- Smaller input group -->
<div class="input-group input-group-sm mt-2">
<div class="input-group-prepend">
<span class="input-group-text">Small</span>
</div>
<input type="text" class="form-control">
</div>
— The output of the above example will look something like this:
Chapter 14
Bootstrap Buttons
In this tutorial you will learn how to create and modify buttons with Bootstrap.
The following example will show you how to create different styles of buttons in
Bootstrap:
Example
Try this code »
Example
Try this code »
— The output of the above example will look something like this:
Changing the Sizes of Buttons
Bootstrap gives you option further to scaling a button up or down. You can make
buttons larger or smaller through adding an extra class .btn-lg or .btn-sm, like this:
Example
Try this code »
— 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 .btn-block to the buttons, like this:
Example
Try this code »
— The output of the above example will look something like this:
Bootstrap Disabled Buttons
Sometimes we need to disable a button for certain reasons, for example, a user in
case is not eligible to perform this particular action, or we want to ensure that
user should performed all other required actions before proceed to this particular
action. Let's see how to do that.
Example
Try this code »
— The output of the above example will look something like this:
Example
Try this code »
Note: The .disabled class only make links visually appear like disabled, however
the link will remain clickable unless you remove the href attribute from it.
Alternatively, you could implement custom JavaScript to prevent those clicks.
Example
Try this code »
— The output of the above example will look something like this:
Creating Spinner Buttons
With Bootstrap you can easily include spinner icon in a button to indicate the
loading state in your application. Check out the following example to see how it
works:
Example
Try this code »
In the next chapter you will learn how to combine multiple buttons horizontally
or vertically in a line like toolbars using the Bootstrap button groups component.
Chapter 15
To create a button groups just wrap a series of buttons with .btn class in
a <div> element and apply the class .btn-group on it, as demonstrated in the
following example:
Example
Try this code »
<div class="btn-group">
<button type="button" class="btn btn-primary">Home</button>
<button type="button" class="btn btn-primary">About</button>
<button type="button" class="btn btn-
primary">Services</button>
</div>
— The output of the above example will look something like this:
Creating Button Toolbar
You can also combine sets of button groups together for creating more complex
components like button toolbar. To create button toolbar just wrap sets of
button groups in a <div> element and apply the class .btn-toolbar on it, as shown
in the following example:
Example
Try this code »
Example
Try this code »
Example
Try this code »
<div class="btn-group">
<a href="#" class="btn btn-primary">Home</a>
<a href="#" class="btn btn-primary">About</a>
<div class="btn-group">
<a href="#" class="btn btn-primary dropdown-toggle"
data-toggle="dropdown">Services</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Web Design</a>
<a class="dropdown-item" href="#">Web
Development</a>
</div>
</div>
</div>
— The output of the above example will look something like this:
Vertically Stacked Button Groups
You can also make the button groups appear vertically stacked rather than
horizontally. To do this just replace the class .btn-group with the .btn-group-
vertical, like this:
Example
Try this code »
<div class="btn-group-vertical">
<a href="#" class="btn btn-primary">Home</a>
<a href="#" class="btn btn-primary">About</a>
<div class="btn-group">
<a href="#" class="btn btn-primary dropdown-toggle"
data-toggle="dropdown">Services</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Web Design</a>
<a class="dropdown-item" href="#">Web
Development</a>
</div>
</div>
</div>
— The output of the above example will look something like this:
Creating Justified Button Groups
You can also stretch your button groups to fill all the available width by applying
the flex utility class .d-flex to the .btn-group element. Every button has equal
width in this case.
Example
Try this code »
— The output of the above example will look something like this:
Chapter 16
Bootstrap Images
In this tutorial you will learn how to style images, as well as how to create
responsive images and videos 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 »
— The output of the above example will look something like this:
Creating Responsive Images and Videos
With Bootstrap you can make the images responsive too. Just add the class .img-
fluid to the <img> tag. This class mainly applies the styles max-
width: 100%; and height: auto; to the image so that it scales nicely to fit the
containing element — in case if the width of the image is larger than the
containing element itself. Check out the following example to see how it works:
Example
Try this code »
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 web page layout.
You can also make the video or slideshow embedded in a web page responsive
without affecting its original aspect ratio. To do this wrap any embed like
an <iframe>, or <video> in a <div> element and apply the class .embed-responsive, and
an aspect ratio class such as .embed-responsive-16by9.
Example
Try this code »
In the above example, we've created the 4 responsive videos with 4 different
aspect ratios (21:9, 16:9, 4:3, and 1:1) by using the classes .embed-responsive-
21by9, .embed-responsive-16by9, .embed-responsive-4by3, and .embed-responsive-1by1,
respectively.
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.
Horizontal Alignment of Images
You can align the images left or right within a larger box using the .pull-
left or .pull-right classes. You can also use the text alignment classes such
as .text-left, .text-right, and .text-center on the parent container to align the
inline images horizontally left, right, and center.
However, to center align the block-level images you need to use the .mx-
auto margin utility class.
Example
Try this code »
Bootstrap Cards
In this tutorial you will learn how to use Bootstrap card component.
In the following sections, you will see what you can do with card component.
Example
Try this code »
Example
Try this code »
<div class="card">
<div class="card-body">This is some text within a padded
box.</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
Example
Try this code »
Feel free to mix and match multiple content types to create the card you need.
The following example will create a fixed-width card with images, text, list group,
and links.
Example
Try this code »
Example
Try this code »
<div class="row">
<div class="col-sm-6">
<div class="card text-white bg-primary mb-4">
<div class="card-body">
<h5 class="card-title">Primary card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-white bg-secondary mb-4">
<div class="card-body">
<h5 class="card-title">Secondary card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-white bg-success mb-4">
<div class="card-body">
<h5 class="card-title">Success card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-white bg-danger mb-4">
<div class="card-body">
<h5 class="card-title">Danger card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-white bg-warning mb-4">
<div class="card-body">
<h5 class="card-title">Warning card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-white bg-info mb-4">
<div class="card-body">
<h5 class="card-title">Info card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card text-white bg-dark">
<div class="card-body">
<h5 class="card-title">Dark card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card bg-light">
<div class="card-body">
<h5 class="card-title">Light card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
</div>
— The output of the above example will look something like this:
<div class="row">
<div class="col-sm-6">
<div class="card border-primary mb-4">
<div class="card-body text-primary">
<h5 class="card-title">Primary card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card border-secondary mb-4">
<div class="card-body text-secondary">
<h5 class="card-title">Secondary card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card border-success mb-4">
<div class="card-body text-success">
<h5 class="card-title">Success card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card border-danger mb-4">
<div class="card-body text-danger">
<h5 class="card-title">Danger card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card border-warning mb-4">
<div class="card-body text-warning">
<h5 class="card-title">Warning card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card border-info mb-4">
<div class="card-body text-info">
<h5 class="card-title">Info card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card border-dark mb-4">
<div class="card-body text-dark">
<h5 class="card-title">Dark card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="card border-light mb-4">
<div class="card-body text-muted">
<h5 class="card-title">Light card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
</div>
</div>
</div>
— The output of the above example will look something like this:
<div class="card-group">
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins
ago</small>
</div>
</div>
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Vestibulum id metus ac nisl
bibendum nibh scelerisque non purus in suspendisse.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins
ago</small>
</div>
</div>
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Pulvinar leo id risus enim.
Bibendum varius tincidunt pellentesque malesuada in.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins
ago</small>
</div>
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="card-deck">
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nam eu sem tempor.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins
ago</small>
</div>
</div>
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Vestibulum id metus ac nisl
bibendum nibh scelerisque non purus in suspendisse.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins
ago</small>
</div>
</div>
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Pulvinar leo id risus enim.
Bibendum varius tincidunt pellentesque malesuada in.</p>
</div>
<div class="card-footer">
<small class="text-muted">Last updated 3 mins
ago</small>
</div>
</div>
</div>
— The output of the above example will look something like this:
Creating Card Columns
With Bootstrap 4 you can also create grid of cards like Pinterest by wrapping
them in .card-columns. Cards are built with CSS column properties instead of
flexbox for easier alignment. Cards are ordered from top to bottom and left to
right. Let's check out an example:
Example
Try this code »
<div class="card-columns">
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Lorem ipsum dolor sit amet,
consectetur adipi elit. Nam eu sem tempor, varius quam at,
luctus dui. Mauris magna metus.</p>
<p class="card-text"><small class="text-muted">Last
updated 3 mins ago</small></p>
</div>
</div>
<div class="card p-3">
<blockquote class="blockquote mb-0 card-body">
<p>Nam eget purus consectetur in vehicula. Nullamr
ultrices nisl risus, viverra libero.</p>
<footer class="blockquote-footer">
<small class="text-muted">Someone famous</small>
</footer>
</blockquote>
</div>
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Vestibulum id metus ac nisl
bibendum scelerisque non dignissim purus.</p>
<p class="card-text"><small class="text-muted">Last
updated 2 mins ago</small></p>
</div>
</div>
<div class="card bg-primary text-white text-center p-3">
<blockquote class="blockquote mb-0">
<p>Pulvinar leo risus vestibulum. Sed diam on sodales
eget.</p>
<footer class="blockquote-footer text-white">
<small>Someone famous</small>
</footer>
</blockquote>
</div>
<div class="card text-center">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Enim arcu, interdum dignissim
venenatis velc.</p>
<p class="card-text"><small class="text-muted">Last
updated 1 mins ago</small></p>
</div>
</div>
<div class="card">
<img src="images/thumbnail.svg" class="card-img-top"
alt="...">
</div>
<div class="card p-3 text-right">
<blockquote class="blockquote mb-0">
<p>Quis quam ut magna consequat faucibus. Pellentesque
eget nisi suscipit tincidunt. Pellentesque quam.</p>
<footer class="blockquote-footer">
<small class="text-muted">Someone famous</small>
</footer>
</blockquote>
</div>
<div class="card">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Convallis eget pretium, bibendum
non leo. Proien suscipit purus adipiscing dolor gravida
fermentum sapien blandit praest interdum vel metus.</p>
<p class="card-text"><small class="text-muted">Last
updated 3 mins ago</small></p>
</div>
</div>
</div>
— The output of the above example will look something like this:
— The output of the above example will look something like this:
Card Image Overlays
You can even turn an image into a card background and place the card's text on
the top it using the class .card-img-overlay in place of .card-body. Depending
on the image, you may need additional styles for better adjustments. Here's an
example:
Example
Try this code »
Note: The card content should not be larger than the height of the image. If
content is larger than the image the content will be displayed outside the image.
Text Alignment inside Card
You can easily change the text alignment of any card—entirely or specific parts—
with the text alignment utility classes. Let's check out an example:
Example
Try this code »
Example
Try this code »
Try out the following example to see how this actually works:
Example
Try this code »
Example
Try this code »
<div class="media">
<img src="images/avatar.svg" class="mr-3" alt="Sample
Image">
<div class="media-body">
<h5 class="mt-0">Jhon Carter <small><i>Posted on January
10, 2019</i></small></h5>
<p>This is really an excellent feature! I love it. One
day I'm definitely going to use this Bootstrap media object
component into my application.</p>
</div>
</div>
— The output of the above example will look something like this:
You can also create other variation of the media component. Apply the image
modifier classes like .rounded or .rounded-circle to the image to create rounded
corner or circular image.
Example
Try this code »
<div class="media">
<img src="images/avatar.svg" class="rounded-circle mr-3"
alt="Sample Image">
<div class="media-body">
<h5 class="mt-0">Jhon Carter <small><i>Posted on January
10, 2019</i></small></h5>
<p>This is really an excellent feature! I love it. One
day I'm definitely going to use this Bootstrap media object
component into my application.</p>
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="media">
<img src="images/avatar.svg" class="rounded-circle mr-3"
alt="Sample Image">
<div class="media-body">
<h5 class="mt-0">Jhon Carter <small><i>Posted on January
10, 2019</i></small></h5>
<p>This is really an excellent feature! I love it. One
day I'm definitely going to use this Bootstrap media object
component into my application.</p>
<!-- Nested media object -->
<div class="media mt-2">
<img src="images/avatar.svg" class="rounded-circle
mr-3" alt="Sample Image">
<div class="media-body">
<h5 class="mt-0">Clark Kent <small><i>Posted on
January 12, 2019</i></small></h5>
<p>Thanks, you found this component useful.
Don't forget to check out other Bootstrap components as well.
They're also very useful.</p>
</div>
</div>
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="media">
<div class="media-body">
<h5 class="mt-0">Jhon Carter <small><i>Posted on January
10, 2019</i></small></h5>
<p>This is really an excellent feature! I love it. One
day I'm definitely going to use this Bootstrap media object
component into my application.</p>
</div>
<img src="images/avatar.svg" class="ml-3" alt="Sample
Image">
</div>
— The output of the above example will look something like this:
Besides that you can also align the images or other media at the middle or
bottom of the content block using the flexbox utilities classes, for example, you
can use the class .align-self-center for vertical center alignment, and the
class .align-self-end for bottom alignment. By default, the media inside a media
object is top aligned. Here's an example:
Example
Try this code »
Example
Try this code »
<ul class="list-unstyled">
<li class="media">
<img src="images/avatar.svg" class="mr-3" alt="Sample
Image">
<div class="media-body">
<h5 class="mt-0">List-based media object</h5>
<p>Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Nam eu sem tempor, varius quam at, luctus dui.
Mauris magna metus, dapibus nec turpis vel, semper malesuada
ante.</p>
</div>
</li>
<li class="media my-2">
<img src="images/avatar.svg" class="mr-3" alt="Sample
Image">
<div class="media-body">
<h5 class="mt-0">List-based media object</h5>
<p>Vestibulum quis quam ut magna consequat faucibus.
Pellentesque eget nisi a mi suscipit tincidunt. Ut tempus dictum
risus. Pellentesque viverra sagittis quam at mattis.</p>
</div>
</li>
<li class="media">
<img src="images/avatar.svg" class="mr-3" alt="Sample
Image">
<div class="media-body">
<h5 class="mt-0">List-based media object</h5>
<p>Amet nibh libero, in gravida nulla. Nulla vel
metus scelerisque ante sollicitudin commodo. Cras purus odio,
vestibulum in vulputate at, tempus viverra turpis.</p>
</div>
</li>
</ul>
Chapter 19
Bootstrap Icons
In this tutorial you will learn how to use icons in Bootstrap.
However, you can still include icons in your project using several external font
based icon library. The most popular and highly compatible icon library for
Bootstrap is Font Awesome. It provides 675 icons which are available in font
format for better usability and scalability.
The advantage of using font icons is, you can create icons of any color just
through applying the CSS color property. Let's see how to include font-awesome
icons in a web page.
Example
Try this code »
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1, shrink-to-fit=no">
<title>Including Font Awesome in Bootstrap Template</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/boo
tstrap.min.css" integrity="sha384-
ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T
" crossorigin="anonymous">
<!-- Font Awesome CSS -->
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/font-
awesome/4.7.0/css/font-awesome.min.css" integrity="sha384-
wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN
" crossorigin="anonymous">
</head>
<body>
<h1><i class="fa fa-globe"></i> Hello, world!</h1>
<!-- JS files: jQuery first, then Popper.js, then Bootstrap
JS -->
<script src="https://code.jquery.com/jquery-
3.3.1.slim.min.js" integrity="sha384-
q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo
" crossorigin="anonymous"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd
/popper.min.js" integrity="sha384-
UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1
" crossorigin="anonymous"></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/boots
trap.min.js" integrity="sha384-
JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM
" crossorigin="anonymous"></script>
</body>
</html>
Where fa-class-name is the name of the particular icon class (e.g. fa-search, fa-
user, fa-star, fa-calendar, fa-globe, etc.) defined in font-awesome.min.css file.
For example, to use search icon you can place the following code just about
anywhere:
Example
Try this code »
Similarly, you can place icons inside the headings, paragraphs, tables, or
anywhere you want. In the next chapter you will see how to use these icons
in Bootstrap nav components.
Note: Remember to leave a space after the closing tag of icon element (i.e.
after </i> tag), when using the icons along with the strings of text such as inside
buttons or navigation links, to ensure proper spacing between the icon and text.
Chapter 20
Example
Try this code »
<nav class="nav">
<a href="#" class="nav-item nav-link active">Home</a>
<a href="#" class="nav-item nav-link">Profile</a>
<a href="#" class="nav-item nav-link">Messages</a>
<a href="#" class="nav-item nav-link disabled" tabindex="-
1">Reports</a>
</nav>
— The output of the above example will look something like this:
Note: You can use the class .disabled to make a link look like disabled. But,
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.
Alignment of Nav Items
By default, navs are left-aligned, but you can easily align them to center or right
using flexbox utilities.
The following example uses the class .justify-content-center to align nav items to
center.
Example
Try this code »
— The output of the above example will look something like this:
Similarly, you can align nav items to right using the class .justify-content-end, like
this:
Example
Try this code »
Example
Try this code »
— The output of the above example will look something like this:
Example
Try this code »
You can also add icons to your tab items to make it more attractive, as shown
here:
Example
Try this code »
— The output of the above example will look something like this:
Creating the Pills Nav
Similarly, you can create pill based navigation by adding the class .nav-pills on
the basic nav instead of class .nav-tabs, as shown in the following example:
Example
Try this code »
Similarly, like nav tabs you can also add icons to your pills nav to make it more
attractive:
Example
Try this code »
Additionally, you can apply the class .flex-column on the .nav element to make the
pills nav appear vertically stacked, as shown in the following example:
Example
Try this code »
Example
Try this code »
Example
Try this code »
— The output of the above example will look something like this:
Example
Try this code »
Alternatively, you can use the class .nav-justified instead of.nav-fill, if you want
nav that fills all horizontal space as well as every nav item has the same width.
Example
Try this code »
Bootstrap Navbar
In this tutorial you will learn how to create static and fixed positioned responsive
navigation headers using the Bootstrap navbar component.
You can also create different variations of the navbar such as navbars with
dropdown menus and search boxes as well as fixed positioned navbar with much
less effort. The following example will show you how to create a simple static
navbar with navigation links.
Example
Try this code »
— The output of the above example will look something like this:
Moreover, instead of plain text, you can also place your logo image inside the
navbar. However, you need to set the logo height manually to fit it properly
inside the navbar, as shown here:
Example
Try this code »
Note: Use the utility classes such as .ml-auto, .mr-auto, .justify-content-between, etc.
to align the nav links, forms, buttons or text inside the navbar.
Example
Try this code »
— The output of the above example will look something like this:
Tip: To create navbars that is not fixed on the top or bottom, place it anywhere
within a .container, which sets the width of your site and content.
Placing Search Form inside Navbar
Search form is very common component of the navbars and you have seen it on
various website quite often. You can place various form controls and components
within a navbar using the class .form-inline on the <form> element, as shown in the
following example:
Example
Try this code »
— The output of the above example will look something like this:
Changing the Color Scheme of Navbars
You can also change the color scheme of the navbar by using the .navbar-
light for the light background colors, or .navbar-dark for the dark background
colors. Then, customize it with the background-color utility classes, such as .bg-
dark, .bg-primary, and so on.
Example
Try this code »
— The output of the above example will look something like this:
Bootstrap Fixed Navbar
Bootstrap also provides mechanism to create navbar that is fixed on the top or
bottom of the viewport and will scroll with the content on the page.
Example
Try this code »
Example
Try this code »
Tip: Place the fixed .navbar content inside the .container or .container-fluid for
proper padding and alignment with the rest of the content.
Note: Remember to add padding (at least 70px) to the top or bottom of
the <body> element to prevent the content to go underneath the navbar while
implementing the fixed top or bottom navbar. Also, be sure to add your
custom style sheet after the core Bootstrap CSS file, otherwise style rules in your
style sheet may be overridden by the Bootstrap's one.
Chapter 22
Bootstrap Breadcrumbs
In this tutorial you will learn how to create breadcrumbs with Bootstrap.
You can create static breadcrumbs layouts with Bootstrap simply using the
class .breadcrumb on the ordered lists, as demonstrated in the following example:
Example
Try this code »
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a
href="#">Products</a></li>
<li class="breadcrumb-item active">Accessories</li>
</ol>
</nav>
— The output of the above example will look something like this:
The default breadcrumb separator is /. But, you can change it with a little custom
CSS, for example, if you want to use > as separator, you can apply the following
style rules:
Example
Try this code »
.breadcrumb-item + .breadcrumb-item::before {
content: ">";
}
— The output of the above example will look something like this:
Tip: Separators inside the breadcrumb components are added automatically via
CSS through the ::before pseudo-element and the content property.
Chapter 23
Bootstrap Pagination
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
Try this code »
<nav>
<ul class="pagination">
<li class="page-item"><a href="#" class="page-
link">Previous</a></li>
<li class="page-item"><a href="#" class="page-
link">1</a></li>
<li class="page-item"><a href="#" class="page-
link">2</a></li>
<li class="page-item"><a href="#" class="page-
link">3</a></li>
<li class="page-item"><a href="#" class="page-
link">4</a></li>
<li class="page-item"><a href="#" class="page-
link">5</a></li>
<li class="page-item"><a href="#" class="page-
link">Next</a></li>
</ul>
</nav>
— The output of the above example will look something like this:
Example
Try this code »
<nav>
<ul class="pagination">
<li class="page-item disabled"><a href="#" class="page-
link" tabindex="-1">Previous</a></li>
<li class="page-item active"><a href="#" class="page-
link">1</a></li>
<li class="page-item"><a href="#" class="page-
link">2</a></li>
<li class="page-item"><a href="#" class="page-
link">3</a></li>
<li class="page-item"><a href="#" class="page-
link">4</a></li>
<li class="page-item"><a href="#" class="page-
link">5</a></li>
<li class="page-item"><a href="#" class="page-
link">Next</a></li>
</ul>
</nav>
— 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
Try this code »
<nav>
<ul class="pagination">
<li class="page-item disabled"><span class="page-
link">Previous</span></li>
<li class="page-item active"><a href="#" class="page-
link">1</a></li>
<li class="page-item"><a href="#" class="page-
link">2</a></li>
<li class="page-item"><a href="#" class="page-
link">3</a></li>
<li class="page-item"><a href="#" class="page-
link">4</a></li>
<li class="page-item"><a href="#" class="page-
link">5</a></li>
<li class="page-item"><a href="#" class="page-
link">Next</a></li>
</ul>
</nav>
Example
Try this code »
— The output of the above example will look something like this:
Alignment of Pagination
By default pagination is aligned horizontally left. To align it in the center of the
page add the class .justify-content-center to the .pagination base class, as shown
below:
Example
Try this code »
<nav>
<ul class="pagination justify-content-center">
<li class="page-item"><a href="#" class="page-
link">Previous</a></li>
<li class="page-item"><a href="#" class="page-
link">1</a></li>
<li class="page-item"><a href="#" class="page-
link">2</a></li>
<li class="page-item"><a href="#" class="page-
link">3</a></li>
<li class="page-item"><a href="#" class="page-
link">4</a></li>
<li class="page-item"><a href="#" class="page-
link">5</a></li>
<li class="page-item"><a href="#" class="page-
link">Next</a></li>
</ul>
</nav>
— The output of the above example will look something like this:
Similarly, you can use the class .justify-content-end to align the pagination to the
right:
Example
Try this code »
<nav>
<ul class="pagination justify-content-end">
<li class="page-item"><a href="#" class="page-
link">Previous</a></li>
<li class="page-item"><a href="#" class="page-
link">1</a></li>
<li class="page-item"><a href="#" class="page-
link">2</a></li>
<li class="page-item"><a href="#" class="page-
link">3</a></li>
<li class="page-item"><a href="#" class="page-
link">4</a></li>
<li class="page-item"><a href="#" class="page-
link">5</a></li>
<li class="page-item"><a href="#" class="page-
link">Next</a></li>
</ul>
</nav>
— The output of the above example will look something like this:
Chapter 24
Bootstrap Badges
In this tutorial you will learn how to create badges with Bootstrap.
The following example will show you how to create inline badges using the
Bootstrap.
Example
Try this code »
Example
Try this code »
— The output of the above example will look something like this:
Creating Pill Badges
Similarly, you can create pill shape badges (i.e. badges with more rounded
corners) using the .badge-pill modifier class, as demonstrated in the following
example:
Example
Try this code »
— 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:
Chapter 25
Example
Try this code »
<div class="progress">
<div class="progress-bar" style="width: 50%"></div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="progress">
<div class="progress-bar" style="width: 60%">
60%
</div>
</div>
— The output of the above example will look something like this:
If you are showing percentage label you should also apply a min-width to the progress bar to
ensure that the label text remains readable even for low percentage, like this:
Example
Try this code »
<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
Try this code »
Example
Try this code »
<div class="progress">
<div class="progress-bar progress-bar-striped" style="width:
60%;"></div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-
animated" style="width: 60%"></div>
</div>
Changing Progress Bar Value Dynamically
Static progress bars aren't very impressive. The following example will give you a rough idea of
how to update the status of a Bootstrap progress bar dynamically using jQuery.
Example
Try this code »
Example
Try this code »
<div class="progress">
<div class="progress-bar bg-success" style="width: 40%">
Program Files (40%)
</div>
<div class="progress-bar bg-warning" style="width: 25%">
Residual Files (25%)
</div>
<div class="progress-bar bg-danger" style="width: 15%">
Junk Files (15%)
</div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="progress">
<div class="progress-bar bg-info" style="width: 20%"></div>
</div>
<div class="progress">
<div class="progress-bar bg-success" style="width:
40%"></div>
</div>
<div class="progress">
<div class="progress-bar bg-warning" style="width:
80%"></div>
</div>
<div class="progress">
<div class="progress-bar bg-danger" style="width:
90%"></div>
</div>
— The output of the above example will look something like this:
Example
Try this code »
<div class="progress">
<div class="progress-bar progress-bar-striped bg-info"
style="width: 20%"></div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-success"
style="width: 40%"></div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-warning"
style="width: 80%"></div>
</div>
<div class="progress">
<div class="progress-bar progress-bar-striped bg-danger"
style="width: 90%"></div>
</div>
— The output of the above example will look something like this:
Chapter 26
Bootstrap Spinners
In this tutorial you will learn how to use the Bootstrap spinner component.
Moreover, you can easily customize the appearance, alignment, and sizing of the
spinners with the pre-defined utility classes. Now, let's see how to create them.
To create a spinner or loading indicator, you can use the .spinner-border class:
Example
Try this code »
<div class="spinner-border">
<span class="sr-only">Loading...</span>
</div>
The special .sr-only class hides an element to all devices except screen readers.
Creating Colored Spinner
You can use the text color utility classes to customize the color of spinners.
Example
Try this code »
Example
Try this code »
<div class="spinner-grow">
<span class="sr-only">Loading...</span>
</div>
Similarly, like the border spinners you can also customize the colors of growing
spinners using the text color utility classes, as shown in the following example:
Example
Try this code »
Example
Try this code »
Alternatively, you can use the custom CSS or inline styles to change the size as
needed.
Example
Try this code »
Here's an example where we've placed the spinners inside the disabled buttons.
Example
Try this code »
Example
Try this code »
Bootstrap Jumbotron
In this tutorial you will learn how to use Bootstrap jumbotron component.
Example
Try this code »
<div class="jumbotron">
<h1>Learn to Create Websites</h1>
<p class="lead">In today's world internet is the most
popular way of connecting with the people. At <a
href="https://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="https://www.tutorialrepublic.com"
target="_blank" class="btn btn-primary btn-lg">Start learning
today</a></p>
</div>
— The output of the above example will look something like this:
Example
Try this code »
Color Classes
You can use the contextual color classes to emphasize the text and convey
meaning through color. Here's the complete list of available contextual color
classes.
.text-reset Reset the color of a text or link (inherits the color Example
from its parent).
Border Classes
You can use the border utility classes to quickly style the border and border-
radius of an element. They are very useful for images, buttons, or any other
element.
Spacing Classes
You can use the spacing utility classes to quickly adjust the margin and padding
of an element.
The # character in the classes .mt-#, .pt-#, etc. represents the size of the margin or
padding. The value of the size can be an integer from 0 to 5, or auto.
Tip: You can also apply negative margins using the margin utility classes. Just
append the size number with the character n, like .mt-n1, .mb-n2, and so on.
Float Classes
You can use the float utility classes to quickly float an element to the left or right
or remove float from an element altogether. Here's the list of available float
classes.
.float-*-left Float an element to the left on based on the viewport size. Example
.float-*-right Float an element to the right on based on the viewport size. Example
Sizing Classes
You can use the sizing utility classes to easily make an element as wide or as tall.
.w-25 Set the width of an element to 25% of its parent element. Example
.w-50 Set the width of an element to 50% of its parent element. Example
.w-75 Set the width of an element to 75% of its parent element. Example
.w-100 Set the width of an element to 100% of its parent element. Example
.w-auto Set the width of an element to auto, i.e. the browser will Example
calculate and select a width for the specified element.
.h-25 Set the height of an element to 25% of its parent element. Example
.h-50 Set the height of an element to 50% of its parent element. Example
.h-75 Set the height of an element to 75% of its parent element. Example
.h-auto Set the height of an element to auto, i.e. the browser will Example
calculate and select a height for the specified element.
.vw-100 Set the width of an element to 100% of the width of the Example
viewport.
.vh-100 Set the height of an element to 100% of the height of the Example
viewport.
.align-baseline Align the baseline of the element with the baseline of Example
its parent.
.align-top Align the top of the element with the top of the Example
entire line.
.align-bottom Align the bottom of the element with the bottom of Example
the entire line.
.align-text-top Align the top of the element with the top of the Example
parent element's font.
.align-text-bottom Align the bottom of the element with the bottom of Example
the parent element's font.
Position Classes
You can use the position utility classes to quickly configuring the position of an
element.
.d-none Hide an element. It does not take up any space in the Example
layout.
For a complete set of flex utility classes, please check out the Bootstrap flex
reference page.
Tip: You can create print variant of the display classes to change the display value
of elements when printing by simply inserting the string print- after .d-, for
example, .d-print-none, .d-print-inline, .d-print-block, .d-print-table, and so on.
Miscellaneous Classes
Here's the list some more utility classes that can used for various purposes.
.close Create generic close icon for dismissing content like Example
modals and alerts.