Bootstrap
Bootstrap
o Bootstrap is the most popular HTML, CSS and JavaScript framework for
developing a responsive and mobile friendly website.
o It is absolutely free to download and use.
o It is a front-end framework used for easier and faster web development.
o It includes HTML and CSS based design templates for typography, forms,
buttons, tables, navigation, modals, image carousels and many others.
o It can also use JavaScript plug-ins.
o It facilitates you to create responsive designs.
History of Bootstrap
Bootstrap was developed by Mark Otto and Jacob Thornton at Twitter. It was released
as an open source product in August 2011 on GitHub.
Responsive web design is about creating web sites which automatically adjust
themselves to look good on all devices, from small phones to large desktops.
CSS: Bootstrap comes with the feature of global CSS settings, fundamental HTML
elements style and an advanced grid system.
JavaScript Plugins: Bootstrap also contains a lot of custom jQuery plugins. You can
easily include them all, or one by one.
Bootstrap Versions
Bootstrap 5 (released 2021) is the newest version of Bootstrap (released 2013); with
new components, faster stylesheet and more responsiveness.
Bootstrap 5 supports the latest, stable releases of all major browsers and platforms.
However, Internet Explorer 11 and down is not supported.
The main differences between Bootstrap 5 and Bootstrap 3 & 4, is that Bootstrap 5
has switched to vanilla JavaScript instead of jQuery.
You can:
For CS
Copy this stylesheet link to the <head> tag of your desired HTML file.
<link href="https://cdn.jsdelivr.net/npm/[email protected]
alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-
GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
crossorigin="anonymous">
For JS
<script src="https://cdn.jsdelivr.net/npm/[email protected]
alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-
w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7C
XvN" crossorigin="anonymous"></script>
Or
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-
oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]
alpha1/dist/js/bootstrap.min.js" integrity="sha384-
mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD
" crossorigin="anonymous">
</script>
Method 2: Downloading files locally
Another way of importing Bootstrap to HTML is to directly download the files locally
to your HTML project folder. The files can be downloaded from the following links:
Bootstrap 5: https://getbootstrap.com/docs/5.3/getting-started/download/
For CSS:
Include a link to the bootstrap.min.css file in the <head> portion of your HTML file.
Doing this enables you to use the Bootstrap CSS components as per your need.
For JS:
Add a link to the bootstrap.min.js file before the end of the <body> portion of your
HTML file. Doing this enables you to use Bootstrap JS components.
Note that the jquery.min.js and popper.min.js files must be included before
loading bootstrap.min.js, even if you have downloaded the files locally.
Bootstrap 5 uses HTML elements and CSS properties that require the HTML5
doctype.
Always include the HTML5 doctype at the beginning of the page, along with the lang
attribute and the correct title and character set:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 5 Example</title>
<meta charset="utf-8">
</head>
</html>
2. Bootstrap 5 is mobile-first
To ensure proper rendering and touch zooming, add the following <meta> tag inside
the <head> element:
The width=device-width part sets the width of the page to follow the screen-width of
the device (which will vary depending on the device).
The initial-scale=1 part sets the initial zoom level when the page is first loaded by the
browser.
3. Containers
Example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]
alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-
GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j
6gD" crossorigin="anonymous">
</head>
<body>
<h1>Hello, world!</h1>
<script src="https://cdn.jsdelivr.net/npm/[email protected]
alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-
w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXv
N" crossorigin="anonymous"></script>
</body>
</html>
Available breakpoints
Bootstrap includes six default breakpoints, sometimes referred to as grid tiers, for
building responsively. These breakpoints can be customized if you’re using our
source Sass files.
Small sm ≥576px
Medium md ≥768px
Large lg ≥992px
Each breakpoint was chosen to comfortably hold containers whose widths are
multiples of 12. Breakpoints are also representative of a subset of common device
sizes and viewport dimensions—they don’t specifically target every use case or
device. Instead, the ranges provide a strong and consistent foundation to build on for
nearly any device.
Containers
Containers are a fundamental building block of Bootstrap that contain, pad, and align
your content within a given device or viewport.
The table below illustrates how each container’s max-width compares to the
original .container and .container-fluid across each breakpoint.
Default container
Our default .container class is a responsive, fixed-width container, meaning its max-
width changes at each breakpoint.
<div class="container">
<!-- Content here -->
</div>
Responsive containers
Responsive containers allow you to specify a class that is 100% wide until the
specified breakpoint is reached, after which we apply max-widths for each of the
higher breakpoints. For example, .container-sm is 100% wide to start until
the sm breakpoint is reached, where it will scale up with md, lg, xl, and xxl.
<div class="container-fluid">
...
</div>
Example-
<!-- Container with dark background and white text color -->
<div class="container bg-dark text-white">
<h1>This is a heading</h1>
<p>This is a paragraph of text.</p>
</div>
<h1>This is a heading</h1>
</div>
span span span span span span span span span span span span
1 1 1 1 1 1 1 1 1 1 1 1
span 4 span 8
span 6 span 6
span 12
You can use the Bootstrap's predefined grid classes for quickly making the
layouts for different types of devices like mobile phones, tablets, laptops,
desktops, and so on.
For example, you can use the .col-* classes to create grid columns for extra
small devices like mobile phones in portrait mode, and the .col-sm-* classes for
mobile phones in landscape mode.
Similarly, you can use the .col-md-* classes to create grid columns for medium
screen devices like tablets, the .col-lg-* classes for devices like small laptops,
the .col-xl-* classes for laptops and desktops, and the .col-xxl-* classes for large
desktop screens.
The following table summarizes how the Bootstrap 5 grid system works across different
screen sizes:
# of 12 12 12 12 12 12
columns
Similarly, the .col-md-* class will not only have an effect on medium devices, but
also on large and extra large devices if a .col-lg-*, .col-xl-*, or .col-xxl-* 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 any container classes such as .container,
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-*, .col-xl-* and .col-xxl-* classes.
The columns are actual content area where we will place our contents.
<div class="row">
</div>
<div class="row">
</div>
<div class="row">
</div>
</div>
Note: In a grid layout, content must be placed inside the columns (.col and .col-
*) and only columns may be the immediate children of rows (.row). Also, rows
should be placed inside a container (either fixed or fluid) for proper padding
and alignment.
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
<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.
Row columns
Use the responsive .row-cols-* classes to quickly set the number of columns that best
render your content and layout. Whereas normal .col-* classes apply to the individual
columns (e.g., .col-md-4), the row columns classes are set on the parent .row as a
shortcut. With .row-cols-auto you can give the columns their natural width.
Use these row columns classes to quickly create basic grid layouts or to control your
card layouts.
Example
<div class="row">
<div class="col-8">
.col-8
<div class="row">
<div class="col-6">.col-6</div>
<div class="col-6">.col-6</div>
</div>
</div>
<div class="col-4">.col-4</div>
</div>
Example
<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>