What is Bootstrap?
Bootstrap is a free, open-source, potent CSS framework and toolkit used to create modern and responsive websites and web applications. It is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites. Nowadays, websites are perfect for all browsers and all sizes of screens.
What is Bootstrap Cheat Sheet?
Bootstrap CheatSheet is a collection of all the classes, variables, and mixins you are ever going to need to create an interactive website or application.
Table of Content
Bootstrap is used to provide styles, layout options, and custom components for creating and styling a variety of forms.
Form control
Default class for styling elements.
.form-control
Select
Shows a collapsible list of values that can be selected.
.form-select
Checks and
radio
Used for radio-buttons and checkboxes
.form-check
Range
Defines the range
.form-control-range
Layout
Two major layout options. Fluid and fixed layout
Validation
Used to apply validation.
:valid|invalid
Datalist
Style the data list using form-control classes.
Input
group
Added as a wrapper around each input type or form control.
.input-group
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Form</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<script src=
</script>
</head>
<body>
<h1 class="text-success text-center">
GeeksforGeeks
</h1>
<h2 class="text-center">Stacked form</h2>
<div class="container">
<form action="#">
<div class="form-group">
<label for="fname">First Name:</label>
<input type="text" class="form-control" id="fname"
placeholder="Enter First Name" name="fname">
</div>
<div class="form-group">
<label for="lname">Last Name:</label>
<input type="text" class="form-control" id="lname"
placeholder="Enter Last Name" name="lname">
</div>
<div class="form-group">
<label for="email">Email Id:</label>
<input type="email" class="form-control" id="email"
placeholder="Enter Email Id" name="email">
</div>
<div class="form-group">
<label for="contact">Contact No:</label>
<input type="text" class="form-control" id="contact"
placeholder="Enter Contact Number" name="contact">
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember">
Remember me
</label>
</div>
<button type="submit" class="btn bg-success">
Submit
</button>
</form>
</div>
</body>
</html>
Input Groups in Bootstrap are used to extend the default form controls by adding text or buttons on either side of textual inputs, custom file selectors, or custom inputs. The following classes are used to add the groups to either side of the input boxes.
Prepend
Adds group to the front of the input.
.input-group-prepend
Append
Add group behind the input.
.input-group-append
Text
Styles the text that is displayed inside the group.
.input-group-text
Small
Makes input groups smaller.
.input-group-sm
Large
Makes input groups larger.
.input-group-lg
Group
Makes size of the input group default.
.input-group
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href=
<title>Input Groups in Bootstrap</title>
</head>
<body>
<div class="container">
<h5>Sizing</h5>
<div class="input-group input-group-sm mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="small">Small</span>
</div>
<input type="text" class="form-control">
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="medium">Default</span>
</div>
<input type="text" class="form-control">
</div>
<div class="input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text" id="large">Large</span>
</div>
<input type="text" class="form-control">
</div>
<br>
<h5>Prepend Group Example</h5>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="username">@</span>
</div>
<input type="text" class="form-control" placeholder="Username">
</div>
<br>
<h5>Append Group Example</h5>
<div class="input-group">
<input type="text" class="form-control" placeholder="Email">
<div class="input-group-append">
<span class="input-group-text" id="email">@example.com</span>
</div>
</div>
</div>
</body>
</html>
A navigation bar is used in every website to make the website more user-friendly. Bootstrap provides various types of navbars.
Basic
Creates default navbar
.navbar
Inverted
Inverts the color of default navbar
.navbar-inverse
Colored
Changes background color
.bg-*
Right-aligned
Right aligns the navbar
.navbar-right
Fixed
Fixes the navigation bar at the top of the webpage.
.navbar-fixed-top
Dropdown
Makes a drop-down interface.
.dropdown
Collapsible
Makes a collapsible navbar
.navbar-collapse
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Navbar Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">WebsiteName</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
Page 1<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Page 1.1</a></li>
<li><a href="#">Page 1.2</a></li>
<li><a href="#">Page 1.3</a></li>
</ul>
</li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</nav>
</body>
</html>
Alerts provide contextual feedback messages for typical user actions with a handful of available and flexible alert messages. Alerts are available for any length of text, as well as an optional close button. There are eight types of alerts available in Bootstrap 5. Each of the classes has different colors associated with them.
Primary
Alert is blue in color..
.alert-primary
Secondary
Shows alert in the secondary background color.
.alert-secondary
Success
Shows the alert green color.
.alert-success
Danger
Alert is red in color.
.alert-danger
Warning
Shows the alert in the color yellow
.alert-warning
Info
Shows the alert in the color light blue.
.alert-info
Light
Alert is in light gray background color.
.alert-light
Dark
Shows the alert in dark gray background color.
.alert-dark
Dismissible
Shows alert with a close button.
.alert-dismissible
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>
Bootstrap 5 | Alerts
</title>
<link rel="stylesheet" href=
</head>
<body>
<div style="text-align: center;
width:600px;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
</div>
<div id="canvas" style="width: 600px;
height: 200px; margin: 20px;">
<div class="alert alert-primary" role="alert">
Primary Alert
<div class="alert alert-secondary" role="alert">
Secondary Alert
</div>
<div class="alert alert-success" role="alert">
Success Alert
</div>
<div class="alert alert-danger" role="alert">
Danger Alert
</div>
<div class="alert alert-warning" role="alert">
Warning Alert
</div>
<div class="alert alert-info" role="alert">
Info Alert
</div>
<div class="alert alert-light" role="alert">
Light Alert
</div>
<div class="alert alert-dark" role="alert">
Dark Alert
</div>
</div>
</body>
</html>
Badges are numerical indicators to highlight the number of items associated with a link or new or unread item. The class. badge within the <span> element is used to create badges. We can have some variations in badges using the following classes:
Contextual variations
Used to change the appearance of a badge.
.badge .bg-*
Pill
Badges
Used to make badges more rounded
.rounded-pill
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<script src=
</script>
</head>
<body>
<div style="text-align: center;width: 600px;">
<h5 style="color: green;">
GeeksforGeeks
</h5>
</div>
<div id="canvas" style="width: 600px;
height: 200px;margin:20px;">
<h5>
Primary
<span class="badge bg-primary">
GeeksforGeeks
</span>
</h5>
<h5>
Secondary
<span class="badge bg-secondary">
GeeksforGeeks
</span>
</h5>
<h5>
Success
<span class="badge bg-success">
GeeksforGeeks
</span>
</h5>
<h5>
Danger
<span class="badge bg-danger">
GeeksforGeeks
</span>
</h5>
<h5>
Light
<span class="badge bg-light text-dark">
GeeksforGeeks
</span>
</h5>
<h5>
Dark
<span class="badge bg-dark">
GeeksforGeeks
</span>
</h5>
<h5>Pill Badge
<span class="badge badge-warning badge-pill">
2
</span>
</h5>
<h5>Badge inside an element
<button type="button" class="btn btn-primary">
Notifications
<span class="badge bg-secondary">
10
</span>
</button
></h5>
</div>
</body>
</html>
It is used to indicate the current page location with a navigational hierarchy to provide links back to each previous page the user navigated through as well. It adds separators automatically using CSS. It provides a backlink to each previous page the user navigates through.
Syntax:
<ol class="breadcrumb"> <li class="breadcrumb-item"> Content .. </li> </ol>
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>
Breadcrumbs Example
</title>
<link rel="stylesheet"
href=
integrity=
"sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"
crossorigin="anonymous">
</head>
<body>
<div style="text-align: center;width: 600px;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
</div>
<div style="width: 600px;height: 200px;
margin:20px;">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active">
GeeksforGeeks
</li>
</ol>
</nav>
</div>
</body>
</html>
Bootstrap provides us with different classes that can be used with different tags, such as <button>, <a>, <input>, and <label> to apply custom button styles. Bootstrap also provides classes that can be used for changing the state and size of buttons, and also, provides classes for applying toggle,checkbox, and radio buttons-like effects.
Solid
Used to create solid button styles.
.btn-*
Outlined
Creates outlined buttons.
.btn-outline-*
Changing Size
Changes the size of button.
.btn-lg|sm|block
Toggle
Toggles the state of the button
<button data-toggle=”button”>
Radio
Creates radio styled buttons
<input type=”checkbox”>
Checkbox
Creates checkbox styled buttons
<input type= “radio”>
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet"
href=
integrity=
"sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
rossorigin="anonymous">
<title>Button Example</title>
<style>
h1 {
color: green;
text-align: center;
}
div.one {
margin-top: 40px;
text-align: center;
}
a,
button {
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<h1>GeeksForGeeks</h1>
<div class="one">
<button type="button" class="btn btn-primary">
Primary</button>
<button type="button" class="btn btn-secondary">
Secondary</button>
<button type="button" class="btn btn-success">
Success</button>
<button type="button" class="btn btn-danger">
Danger</button>
<button type="button" class="btn btn-warning">
Warning</button>
<button type="button" class="btn btn-info">
Info</button>
<button type="button" class="btn btn-light">
Light</button>
<button type="button" class="btn btn-dark">
Dark</button>
<button type="button" class="btn btn-link">
Link</button>
</div>
<div class="one">
<button type="button" class="btn btn-outline-primary">
outline</button>
<button type="button" class="btn btn-secondary btn-lg">
Large</button>
<button type="button" class="btn btn-success btn-sm">
Small</button>
<a href="#" class="btn btn-danger active" role="button" aria-pressed="true">
Active</a>
<a href="#" class="btn btn-warning disabled" role="button" aria-disabled="true" tabindex="-1">
Disabled</a>
<button type="button" class="btn btn-info" data-toggle="button"
aria-pressed="false" autocomplete="off">
Toggle
</button>
<div class="btn-group-toggle" data-toggle="buttons">
<label class="btn btn-light active">
<input type="checkbox" checked autocomplete="off">
Checked</label>
<label class="btn btn-dark">
<input type="radio" name="options" id="option1" autocomplete="off">
Radio</label>
</div>
</div>
</div>
</body>
</html>
Bootstrap allows us to group a series of buttons together in a single line vertically or horizontally(without spaces) using the button group class. These classes are as follows:
Style
Add styles to buttons
.btn-primary|default|success|info|link
Size
Changes the sizing of buttons.
.btn-group-*
Nesting
Stacks the button in vertical manner
.btn-group-vertical
Vertical
Creates a dropdown menu within the buttons
.btn-group
Button
toolbar
Combine button groups into button toolbars
.btn-toolbar
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<script src=
</script>
</head>
<body>
<p>Styling Button Groups</p>
<div class="btn-group">
<button type="button" class="btn btn-danger">Click</button>
<button type="button" class="btn btn-warning">Click</button>
<button type="button" class="btn btn-success">Click</button>
</div>
<br />
<p>Sizing Button Groups</p>
<div>
<div class="btn-group btn-group-lg">
<button type="button" class="btn btn-danger">Click</button>
<button type="button" class="btn btn-warning">Click</button>
<button type="button" class="btn btn-success">Click</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-danger">Click</button>
<button type="button" class="btn btn-warning">Click</button>
<button type="button" class="btn btn-success">Click</button>
</div>
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-danger">Click</button>
<button type="button" class="btn btn-warning">Click</button>
<button type="button" class="btn btn-success">Click</button>
</div>
<div class="btn-group btn-group-xs">
<button type="button" class="btn btn-danger">Click</button>
<button type="button" class="btn btn-warning">Click</button>
<button type="button" class="btn btn-success">Click</button>
</div>
</div>
<br>
<p>Vertical Button groups</p>
<div class="btn-group-vertical">
<button type="button" class="btn btn-danger">Click</button>
<button type="button" class="btn btn-warning">Click</button>
<button type="button" class="btn btn-success">Click</button>
</div>
<p>Nesting of button groups</p>
<div class="btn-group">
<button type="button" class="btn btn-danger">Click</button>
<button type="button" class="btn btn-warning">Click</button>
<div class="btn-group">
<button type="button" class="btn btn-success
dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown</button>
<ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<li><a class="dropdown-item" href="#">Item 1</a></li>
<li><a class="dropdown-item" href="#">Item 2</a></li>
</ul>
</div>
</div>
</body>
</html>
A card is a flexible and extensible content container. It includes options for headers and footers, a wide variety of content, contextual background colors, and powerful display options.
Basic
The building block of a card is the card-body and card.
.card .card-body
Headers and footers
Provides header and footer to the card.
.card-header|footer
Title and
Links
Gives a title and link to the card.
.card-title|link
Images
Used to add images to the card.
.card-img
Overlays
Adds overlay to the card image
.card-img-overlay
Card Group
Used to add groups to the card
.card-deck
List
group
Creates a list of content in card.
.card
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Card</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<script src=
</script>
</head>
<body>
<div class="container">
<h4>Basic Card</h4>
<h2 style="color:green;">GeeksforGeeks</h2>
<div class="card">
<div class="card-body">
A computer science portal for geeks
</div>
</div>
<br />
<h4>Header and Footer card</h4>
<div class="card">
<div class="card-header">Header</div>
<div class="card-body">Content</div>
<div class="card-footer">Footer</div>
</div>
<br />
<h4>Title and links card</h4>
<div class="card">
<div class="card-body">
<h4 class="card-title">Card title</h4>
<p class="card-text">
Some example text. Some example text.
</p>
<a href="#" class="card-link">Card link</a>
<a href="#" class="card-link">Another link</a>
</div>
</div>
<br />
<h4>Card with images</h4>
<div class="card" style="width:200px">
<img class="card-img-top"
src=
alt="Card image" style="width:100%">
<div class="card-body">
<h4 class="card-title">Developer Guy</h4>
<p class="card-text">
Developer Guy love to develop
front-end and back-end
</p>
</div>
</div>
<br />
<h4>Card group</h4>
<div class="card-deck">
<div class="card-text-white bg-primary">
<div class="card-body">
<h4 class="card-title">PRIMARY</h4>
</div>
</div>
<div class="card-text-white bg-success">
<div class="card-body">
<h4 class="card-title">SUCCESS</h4>
</div>
</div>
<div class="card-text-white bg-danger">
<div class="card-body">
<h4 class="card-title">DANGER</h4>
</div>
</div>
</div>
<br />
<h4>List Groups</h4>
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item">Bootstrap</li>
<li class="list-group-item">HTML</li>
<li class="list-group-item">JavaScript</li>
</ul>
</div>
</div>
</body>
</html>
Carousal is used in bootstrap to create slideshows of images on a website. It is used to cycle through a series of images and text. Significant parts of a carousal are:
Slide
The content and image of each slide is defined here
.carousel .slide
Fade
Used to add a fading effect to the transition.
.carousel-fade
Indicators
The indicators are the little dots at the bottom of each slide.
.carousel-indicators
Captions
Adds text associated with image to the carousal.
.carousel-captions
Controls
Alows us to go back and forth.
.carousel-control-next|previous-icon
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Carousel</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
</head>
<body>
<center>
<h1 class="text-success">GeeksforGeeks</h1>
<h4>Bootstrap | Carousel</h4>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img src=
</div>
<div class="item">
<img src=
</div>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</center>
</body>
</html>
Bootstrap’s grid system allows up to 12 columns across the page. The grid system helps align page elements based on sequenced columns and rows. We use this column-based structure to place text, images, and functions in a consistent way throughout the design.
Container
It is a container of row elements
.container
Row
Container for column elements
.row
Column
Used to specify the number of available columns.
.col
column reset
Used to resolve issues regarding viewport.
.clearfix
column
offset
Moves the columns to the right by x columns.
.col-md|lg|cs-offset-value
Extra Small
Used for portrait mobile phones.
.col-xs
Small
Used for Landscapes phones
.col-sm
Medium
Used for Tablets/Phablets
.col-md
large
Used for Small-sized Desktops/Laptops
.col-lg
Extra large
Used for Larger-sized Desktops/Laptops
.col-xl
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<script src=
</script>
</head>
<body>
<header>
<div class="container">
<h1 style="color: green">GeeksforGeeks</h1>
<strong>
A computer Science portal for Geeks
</strong>
</div>
</header>
<div class="container">
<div class="row">
<div class="bg bg-secondary w-100">
First Row
</div>
</div>
<div class="row">
<div class="bg bg-primary w-100">
Second row
</div>
</div>
</div>
<br />
<div class="container">
<div class="row">
<div class="col-xs-2 col-sm-6 col-md-3
col-lg-4 col-xl-6">
<div class="well bg bg-success">
First Column
</div>
</div>
<div class="col-xs-2 col-sm-6 col-md-3
col-lg-4 col-xl-6">
<div class="well bg bg-danger">
Second Column
</div>
</div>
<div class="col-xs-2 col-sm-6 col-md-3
col-lg-4 col-xl-6">
<div class="well bg bg-warning">
Third Column
</div>
</div>
<div class="col-xs-2 col-sm-6 col-md-3
col-lg-4 col-xl-6">
<div class="well bg bg-primary">
Fourth Column
</div>
</div>
</div>
</div>
<footer>
<hr />
<div class="container">
<p>
Visit
</a>
our website
</p>
<p>
Like
</a>
us on facebook
</p>
</div>
</footer>
</body>
</html>
Pagination is used to enable navigation between pages on a website. The pagination used in Bootstrap has a large block of connected links that are hard to miss and easily scalable.
Basic
Specifies pagination on a list group.
.pagination
Disabled
Makes pagination appear unclickable.
.disabled
Active
Highlights the currently active page
.active
Sizing
Changes the sizing of the pagination group
.pagination-sm|md|lg
Alignment
Sets the alignement of pagination group
.justify-content-center|end
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Pagination</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<script src=
</script>
</head>
<body>
<div class="container">
<h5>Basic Pagination</h5>
<ul class="pagination">
<li class="page-item">
<a class="page-link" href="#">Previous</a>
</li>
<li class="page-item">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item">
<a class="page-link" href="#">3</a>
</li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
<br />
<h5>Disabled and active</h5>
<ul class="pagination">
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">
Previous
</a>
</li>
<li class="page-item">
<a class="page-link" href="#">
1
</a>
</li>
<li class="page-item">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item active">
<a class="page-link" href="#">3</a>
</li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
<h5>Pagination Sizing</h5>
<b>Large Pagination</b>
<ul class="pagination pagination-lg">
<li class="page-item">
<a class="page-link" href="#">Previous</a>
</li>
<li class="page-item">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item">
<a class="page-link" href="#">3</a>
</li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
<b>Small Pagination</b>
<ul class="pagination pagination-sm">
<li class="page-item">
<a class="page-link" href="#">Previous</a>
</li>
<li class="page-item">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item">
<a class="page-link" href="#">3</a>
</li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
<b>Normal Pagination</b>
<ul class="pagination">
<li class="page-item">
<a class="page-link" href="#">Previous</a>
</li>
<li class="page-item">
<a class="page-link" href="#">1</a>
</li>
<li class="page-item">
<a class="page-link" href="#">2</a>
</li>
<li class="page-item">
<a class="page-link" href="#">3</a>
</li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</div>
</body>
</html>
Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They’re made interactive with the included Bootstrap dropdown JavaScript plugin.
Divider
Creates a horizontal list to divide dropdown menu
.dropdown
Header
Adds header section inside the dropdown list.
.dropdown-header
Disable and active items
Used to diable and enable list of items.
.active|disabled
Dropdown position
Sets the position of dropdown list.
.dropright|dropleft
Dropdown Menu Right Aligned
Right aligns the dropdown menu.
.dropdown-menu-right
Dropup
Expands the menu list upwards.
.dropup
Dropdown text
Adds plain text in the dropdown menu list.
.dropdown-item-text
Grouped Buttons with a Dropdown
Creates a group of buttons in the dropdown list.
.btn-group
Split Button Dropdowns
Splits the dropdown buttons.
.dropdown-toggle-split
Vertical Button Group Dropdown List
Creates a vertical button group.
.btn-group-vertical
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href=
integrity=
"sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"
crossorigin="anonymous">
<script src=
integrity=
"sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous">
</script>
<script src=
integrity=
"sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"
crossorigin="anonymous">
</script>
</head>
<body style="text-align: center;">
<div class="container mt-3" style="width: 700px;">
<h1 style="color: green;">
GeeksforGeeks
</h1>
<div class="dropdown dropright">
<button type="button" class="btn btn-success dropdown-toggle"
data-toggle="dropdown">
Select Subjects
</button>
<div class="dropdown-menu">
<strong class="dropdown-header ">
CS Subjects
</strong>
<a class="dropdown-item" href="#">
Data Structure
</a>
<a class="dropdown-item" href="#">
Algorithm
</a>
<a class="dropdown-item" href="#">
Operating System
</a>
<a class="dropdown-item active" href="#">
Computer Networks
</a>
<div class="dropdown-divider "></div>
<strong class="dropdown-header">
Other Subjects
</strong>
<a class="dropdown-item" href="#">
Physics
</a>
<a class="dropdown-item disabled" href="#">
Mathematics
</a>
<a class="dropdown-item" href="#">
Chemistry
</a>
</div>
</div>
</div>
</body>
</html>
List Groups are used to display a series of content. We can modify them to support any content as per our needs. The use of List-Groups is just to display a series or list of content in an organized way.
Disabled
Makes the list group disabled.
.disabled
Active
Indicates the currently active item.
.active
Hyperlinks and Buttons
Creates actionable list items with multiple states.
.list-group-item-action
Flush
Flush class to remove some borders and rounded corners data
.list-group-flush
Contextual
Style list items with suitable backgrounds and colors.
.list-group-item-primary|secondary|info|light
Badges
Adds badges to list group items.
.badge
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>List Groups example</title>
<link rel="stylesheet"
href=
integrity=
"sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS"
crossorigin="anonymous">
<script src=
integrity=
"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous">
</script>
<script src=
integrity=
"sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k"
crossorigin="anonymous">
</script>
</head>
<body>
<p>To do list</p>
<ul class="list-group">
<li class="list-group-item active">study</li>
<li class="list-group-item disabled">pay bills</li>
<li class="list-group-item">call mom</li>
<li class="list-group-item
list-group-item-info">
Info list group item
</li>
</ul>
<div>
<a href="#" class="list-group-item list-group-item-action">drop an email</a>
</div>
<button type="button" class="list-group-item list-group-item-action">
UPDATES
<span class="badge badge-pill badge-danger">2</span>
</button>
</body>
</html>
Popovers are used to display additional information about any element and are displayed with a click of a mouse pointer over that element.
Syntax: data-toggle="popover" title="Popover Header" data-content="Some content inside the box"
The data-toggle attribute defines the Popover, the title attribute defines the Tile for the Popover and the data-content attribute is used to store the content to be displayed in the respective Popover.
Right-alignment
Displays the popover at right of the element.
data-placement= “right”
Left-alignment
Displays the popover at left of the element.
data-placement= “left”
Bottom-alignment
Displays the popover at bottom of the element.
data-placement= “bottom”
Top-alignment
Displays the popover at top of the element.
data-placement= “top”
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Example</title>
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
</head>
<body>
<div class="container">
<h3>Popover Example</h3>
<a href="#" data-toggle="popover" title="Popover Header"
data-content="Some content inside the popover">
GeeksforGeeks</a>
</div>
<script>
$(document).ready(function () {
$('[data-toggle="popover"]').popover();
});
</script>
</body>
</html>
The spinners are used to specify the loading state of a component or webpage. Bootstrap facilitates the various classes for creating different styles of spinners by modifying their appearance, size, and placement.
Border
Used to rotate the spinner
.spinner-border
Grow
Used for growing spinners.
.spinner-grow
Margin
Adds margins to the spinners.
.m-
value
Placement
Places spinners at different positions
.d-flex
Size
Changes the size of the spinners.
.spinner-border-sm|md|lg|xl
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width">
<link href=
rel="stylesheet">
</head>
<body>
<h2 class="text-success text-center">
GeeksforGeeks
</h2>
<h5 class="text-info text-center">
Bootstrap Spinner Border
</h4>
<div class="d-flex justify-content-center">
<div class="spinner-border text-secondary"
role="status">
</div>
<span>Please Wait </span>
</div>
<br/>
<h5 class="text-info text-center">
Bootstrap Spinner Grow
</h5>
<div class="d-flex justify-content-center">
<span>
<h5>Processing</h5>
</span>
<div class="spinner-grow text-primary"
role="status">
</div>
</div>
<br/>
<h5 class="text-info text-center">
Spinner Placement using Bootstrap classes
</h5>
<br/>
<h5 class=" text-center">
Using the Text Placement Classes
</h5>
<div class="text-center">
<div class="spinner-border m-5 " role="status">
</div>
</div>
<h5 class="text-center">
Using the Flex Box Classes
</h5>
<div class="d-flex justify-content-center">
<div class="spinner-border" role="status">
</div>
</div>
</body>
</html>
Bootstrap Scrollspy targets the navigation bar contents automatically on scrolling the area. Scrollspy is used to update the navigation links when scrolling the page. The following attributes are added with the elements for the implementation of this feature.
Data-spy
This element is added to the scrollable area.
data-spy=”scroll”
Data-target
Connects the navigation bar with the scrollable area.
data-target = “.id”
Data-offset
Specifies the number of pixels to offset from the top.
data-offset = “value”
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<style>
body {
position: relative;
}
ul.nav-pills {
top: 20px;
position: fixed;
}
div.col-sm-9 div {
height: 250px;
font-size: 18px;
}
a {
color: green;
}
#section1 {
color: white;
background-color: green;
}
#section2 {
color: green;
background-color: white;
}
#section3 {
color: white;
background-color: green;
}
#section4 {
color: green;
background-color: white;
}
@media screen and (max-width: 810px) {
#section1,
#section2,
#section3,
#section4 {
margin-left: 150px;
}
}
</style>
</head>
<body data-spy="scroll" data-target="#myScrollspy" data-offset="20">
<div class="container">
<div class="row">
<nav class="col-sm-3" id="myScrollspy">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="#section1">
Section 1</a>
</li>
<li><a href="#section2">Section 2</a></li>
<li><a href="#section3">Section 3</a></li>
<li><a href="#section4">Section 4</a></li>
</ul>
</nav>
<div class="col-sm-9">
<div id="section1">
<center>
<h1>Section 1</h1>
<h3>GeeksforGeeks</h3>
<h5>A computer science portal for geeks.</h5>
<h6> This portal has been created to
provide well written, well thought
and well explained solutions for
selected questions related to
programming, algorithms, other
computer science subjects.
</h6>
<p>Scroll this section and see the
navigation list while scrolling.
</p>
</center>
</div>
<div id="section2">
<center>
<h1>Section 2</h1>
<h3>GeeksforGeeks</h3>
<h5>A computer science portal for geeks.</h5>
<h6> This portal also provide GATE
previous year papers, short notes
for the aspirants.
</h6>
<p>Scroll this section and see the
navigation list while scrolling.
</p>
</center>
</div>
<div id="section3">
<center>
<h1>Section 3</h1>
<h3>GeeksforGeeks</h3>
<h5>A computer science portal for geeks.</h5>
<h6>This portal also provide interview
questions asked by private and
public sectors.
</h6>
<p>Scroll this section and see the
navigation list while scrolling.
</p>
</center>
</div>
<div id="section4">
<center>
<h1>Section 4</h1>
<h3>GeeksforGeeks</h3>
<h5>A computer science portal for geeks.</h5>
<h6>It also provide Internship aor
contributor program for students.
</h6>
<p>Scroll this section and see the
navigation list while scrolling.
</p>
</center>
</div>
</div>
</div>
</div>
</body>
</html>
A tooltip is quite useful for showing the description of different elements in the webpage. The tooltip can be invoked on any element in a webpage. Tooltips on bootstrap depend on the 3rd party library Tether for positioning. We can even customize this tooltip according to our requirements. Some of them are:
Placement
Used to place a tooltip.
data-placement = “top|bottom|right|left”
Html
Adds HTML to a tooltip.
data-html = “true”
Offset
Sets the offset of the tool-tip relative to target.
data-offset = “number|string”
Animation
Adds or removes animation to tooltip.
data-animation = “true|false”
Trigger
Adds the event which will trigger tooltip.
data-trigger = “hover focus”
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tooltip</title>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
<script src=
<script src=
</head>
<body style="text-align:center;">
<div class="container">
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h2>Positioning Tooltip</h2>
<button data-toggle="tooltip" data-placement="top"
title="Top tooltip">Top
</button>
<button data-toggle="tooltip" data-placement="bottom"
title="Bottom tooltip">Bottom
</button>
<button data-toggle="tooltip" data-placement="left"
title="Left tooltip">Left
</button>
<button data-toggle="tooltip" data-placement="right"
title="Right tooltip">Right
</button>
</div>
<script>
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
</html>
Bootstrap Jumbotron is a responsive component whose main goal is to draw the visitor’s attention or highlight a special piece of information. Inside a Jumbotron, you can make use of almost any other Bootstrap code to further increase its engagement value.
Fluid Jumbotron: To create a full-width Jumbotron we use the jumbotron-fluid class along with the Jumbotron class.
Code:
HTML
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href=
integrity=
"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
</head>
<body>
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">Jumbotron Example</h1>
<p class="lead">
This is a modified jumbotron that
occupies the entire horizontal
space of its parent.
</p>
</div>
</div>
</body>
</html>
Toast is used to create something like an alert box which is shown for a short time like a couple of
seconds when something happens. Like when the user clicks on a button or submits a form and many other
actions.
.toast: It helps to create a toast.
.toast-header: It helps to create the toast header.
.toast-body: It helps to create toast body
.toast(“show”): It shows the toast
.toast(“hide”): It hides the toast
.toast(“dispose”): It disposes of the toast
Some of the events of toast are:
show.bs.toast
Occurs when the toast is about to be shown.
shown.bs.toast
Occurs when the toast is shown.
hide.bs.toast
Happens when the toast is about to be hidden.
hidden.bs.toast
Happens when the toast is fully hidden.
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Toast Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href=
<script src=
</script>
<script src=
</script>
<script src=
</script>
</head>
<body style="text-align: center">
<h1 style="color:green">GeeksforGeeks</h1>
<div class="container mt-3">
<h3>.toast(options)</h3>
<p>
When we click the button below there
would be delay of the toast to 8000
milliseconds.
</p>
<button type="button" class="btn btn-primary"
id="myBtn">Show Toast</button>
<div class="toast mt-3">
<div class="toast-header">
Toast Header
</div>
<div class="toast-body">
Some text inside the toast body
</div>
</div>
</div>
<script>
$(document).ready(function () {
$('#myBtn').click(function () {
$('.toast').toast({
animation: false,
delay: 2000
});
$('.toast').toast('show');
});
});
</script>
</body>
</html>
Modals are used to add dialogs to your site for lightboxes, user notifications, or completely custom content. Modals are built with HTML, CSS, and JavaScript. They’re positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead.
Syntax:
<div class="modal"> Contents... <div>
Popovers
Added inside the modal.
.modal
Content
Triggers same modal with different data
.modal-content
Extra Large Modal
Provides the largest modal size with a max-width of 1140px.
.modal-xl
Large Modal
Provides a large modal size with a max-width of 800px.
.modal-lg
Small Modal
Provides a small modal size with a max-width of 300px.
.modal-sm
Code:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no">
integrity=
"sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src=
integrity=
"sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
integrity=
"sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<link rel="stylesheet"
href=
integrity=
"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<title>bootstrap | Modal</title>
<style>
h1,h6 {
margin: 2%;
}
.btn {
margin-left: 2%;
}
</style>
</head>
<body>
<center>
<h1 style="color:green;">GeeksforGeeks</h1>
<button type="button" class="btn btn-primary" data-toggle="modal"
data-target="#exampleModal">Launch Modal</button>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title" id="exampleModalLabel" style="color:green;">
GeeksforGeeks
</h6>
<button type="button" class="close" data-dismiss="modal"aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>The Content inside the modal </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">okay</button>
</div>
</div>
</div>
</div>
</body>
</html>
Borders are generally used to display an outline around a box or table cell or any other HTML element. In Bootstrap, there are different classes available to add or remove borders. The classes that are used to add borders are referred to as Additive classes and those that are used to remove borders are referred to as subtractive classes.
Border
Adds a border all around the element.
.border
Border top
Adds a border on top edge of the element.
.border-top
Border right
Adds a border on the right of the element.
.border-right
Border bottom
Adds a border on the bottom of the element.
.border-bottom
Border left
Adds a border on the left of the element.
.border-left
Radius
Makes the corner of the border curved.
.rounded
Color
Used to add color to the border.
.border-*
Code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Borders Example</title>
<link rel="stylesheet" href=
<script src=
<script src=
<script src=
<style>
/* CSS for Square boxes */
span {
display: inline-block;
width: 70px;
height: 70px;
margin: 6px;
background-color: #DCDCDC;
}
</style>
</head>
<body>
<div class="container">
<h4>Additive Border Classes</h4>
<span class="border border-dark"></span>
<span class="border-top border-dark"></span>
<span class="border-right border-dark"></span>
<span class="border-bottom border-dark"></span>
<span class="border-left border-dark"></span>
</div>
<div class="container">
<h4>Subtractive Border Classes</h4>
<span class="border border-dark"></span>
<span class="border border-0 border-dark"></span>
<span class="border border-top-0 border-dark"></span>
<span class="border border-right-0 border-dark"></span>
<span class="border border-bottom-0 border-dark"></span>
<span class="border border-left-0 border-dark"></span>
</div>
<div>
<h4>Color Border:</h4>
<span class="border border-primary"></span>
<span class="border border-secondary"></span>
<span class="border border-success"></span>
<span class="border border-danger"></span>
<span class="border border-warning"></span>
<span class="border border-info"></span>
<span class="border border-light"></span>
<span class="border border-dark"></span>
</div>
<div>
<h4>Border Radius</h4>
<span class="rounded"></span>
<span class="rounded-top"></span>
<span class="rounded-right"></span>
<span class="rounded-bottom"></span>
<span class="rounded-left"></span>
<span class="rounded-circle"></span>
<span class="rounded-0"></span>
</div>
</body>
</html>
We have Completer tutorial post with the proper roadmap of Bootstrap that includes Bootstrap 4 and Bootstrap 5 . This tutorial contains each and every classes of any component with multiple possible examples.
Learn to code easily with our course
Coding for Everyone . This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated :
11 Jul, 2023
Like Article
Save Article
Share your thoughts in the comments
Add Your Comment
Please Login to comment...