Bootstrap is a free and open-source collection of CSS and JavaScript/jQuery code used for creating responsive & dynamic websites layout and web applications. Offcanvas is one of the features of Bootstrap to make web pages more attractive, along with enhancing the user experience.
Offcanvas is a sidebar component that helps to toggle the view using Javascript, to appear from the left, right or bottom edge of the viewport. In order to toggle the view, the button can be used as the trigger, which is declared with the specific element, along with using the data attribute to utilize it for invoking the JavaScript. It is similar to the Bootstrap Modal, where only single offcanvas can be displayed at a time. Navigation throughout the page can be done using offcanvas functionality.
Offcanvas Component: Offcanvas contain a header with a close button and the body part. It's good to include a close button or you can provide an explicit source to close it.
Syntax:
<div class="offcanvas offcanvas-start"
id="sidebar">
<div class="offcanvas-header">
<h1 class="offcanvas-title">
Heading
</h1>
<button type="button"
class="btn-close">
</button>
</div>
<div class="offcanvas-body">
<p>Content Body</p>
</div>
</div>
Offcanvas Component Class:
- offcanvas: This class is used to create offcanvas but it hides the content.
- offcanvas show: This class is used to show the offcanvas content in the viewport.
- offcanvas-header: This class is used for the head section of offcanvas.
- offcanvas-body: This class is used to add content to the offcanvas body parts.
Example: This example describes the use of the Basic Offcanvas in Bootstrap.
HTML <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Offcanvas</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="container mt-3"> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasStart" aria-controls="offcanvasStart"> Toggle offcanvas </button> <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasStart" aria-labelledby="offcanvasStartLabel"> <div class="offcanvas-header"> <h3 id="offcanvasStartLabel"> Offcanvas </h3> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> </div> </div> <center> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> </center> </div> </body> </html>
Output:
Offcanvas Placement: The Offcanvas placement can be used to position the offcanvas in various ways, such as top, bottom, right, & start of the viewport. There is no default placement for offcanvas components.
Syntax:
<div class="offcanvas offcanvas-start"
id="offcanvasStart" >
</div>
<div class="offcanvas offcanvas-top"
id="offcanvasTop" >
</div>
<div class="offcanvas offcanvas-end"
id="offcanvasRight" >
</div>
<div class="offcanvas offcanvas-bottom"
id="offcanvasBottom">
</div>
Offcanvas Placement Class:
- offcanvas-start: This class is used to place offcanvas on the left side of the viewport.
- offcanvas-end: This class is used to place offcanvas on the right side of the viewport.
- offcanvas-top: This class is used to place offcanvas on the top side of the viewport.
- offcanvas-bottom: This class is used to place offcanvas on the bottom side of the viewport.
Example: In this example, we will demonstrate offcanvas placement in the viewport.
HTML <!DOCTYPE html> <html lang="en"> <head> <title> Bootstrap Offcanvas </title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="container mt-3"> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasStart" aria-controls="offcanvasStart"> Toggle left offcanvas </button> <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasStart" aria-labelledby="offcanvasStartLabel"> <div class="offcanvas-header"> <h3 id="offcanvasStartLabel"> Offcanvas left </h3> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> </div> </div> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight"> Toggle right offcanvas </button> <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel"> <div class="offcanvas-header"> <h3 id="offcanvasRightLabel"> Offcanvas right </h3> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> </div> </div> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasTop" aria-controls="offcanvasTop"> Toggle top offcanvas </button> <div class="offcanvas offcanvas-top" tabindex="-1" id="offcanvasTop" aria-labelledby="offcanvasTopLabel"> <div class="offcanvas-header"> <h3 id="offcanvasTopLabel"> Offcanvas top </h3> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> </div> </div> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasBottom" aria-controls="offcanvasBottom"> Toggle bottom offcanvas </button> <div class="offcanvas offcanvas-bottom" tabindex="-1" id="offcanvasBottom" aria-labelledby="offcanvasBottomLabel"> <div class="offcanvas-header"> <h3 class="offcanvas-title" id="offcanvasBottomLabel"> Offcanvas bottom </h3> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body small"> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> </div> </div> <br> <center> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> </center> </div> </body> </html>
Output:
Offcanvas Backdrop: The backdrop option specifies that the offcanvas have a dark overlay (the background color of the current page). By default the backdrop is active. Use the data-bs-backdrop attribute and set its value to false to inactive the backdrop.
Syntax:
<div class="offcanvas offcanvas-start"
data-bs-scroll="true"
data-bs-backdrop="false">
Content
</div>
Example 1: In this example, we will demonstrate offcanvas with the default option. By default backdrop option is active and scrolling is inactive.
HTML <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Sidebar</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="offcanvas offcanvas-start" tabindex="-1" id="sidebar" aria-labelledby="offcanvasStartLabel"> <div class="offcanvas-header"> <h1 id="offcanvasStartLabel"> GeeksforGeeks </h1> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Scrolling is inactive (default) </h5> <h5> backdrop is active (default) </h5> <br> <h5> <p> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </p> </h5> </div> </div> <div class="container mt-3"> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="offcanvasStart"> Offcanvas Sidebar </button> <center> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20220129032254/geeks.png" alt="GFG" width="600" height="400"> <br> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <br> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20220129032254/geeks.png" alt="GFG" width="600" height="400"> <br> </center> </div> </body> </html>
Output:
Example 2: In this example, we will demonstrate offcanvas with an inactive backdrop. Use the data-bs-backdrop attribute and set its value to false to inactive the backdrop.
HTML <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Offcanvas</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="offcanvas offcanvas-start" data-bs-backdrop="false" tabindex="-1" id="sidebar" aria-labelledby="offcanvasStartLabel"> <div class="offcanvas-header"> <h1 id="offcanvasStartLabel"> GeeksforGeeks </h1> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Scrolling is inactive (default) </h5> <h5> backdrop is inactive </h5> <br> <h5> <p> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </p> </h5> </div> </div> <div class="container mt-3"> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="offcanvasStart"> Offcanvas Sidebar </button> <center> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20220129032254/geeks.png" alt="GFG" width="600" height="400"> <br> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <br> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20220129032254/geeks.png" alt="GFG" width="600" height="400"> <br> </center> </div> </body> </html>
Output:
Background scrolling: It is by default inactive means background content is not scrollable. Use the data-bs-scroll attribute and set its value to true to activate the background scrolling.
Example 3: In this example, we will demonstrate offcanvas with scrolling and backdrop.
HTML <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Offcanvas</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="offcanvas offcanvas-start" data-bs-scroll="true" tabindex="-1" id="sidebar" aria-labelledby="offcanvasStartLabel"> <div class="offcanvas-header"> <h1 id="offcanvasStartLabel"> GeeksforGeeks </h1> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Scrolling is active </h5> <h5> backdrop is active </h5> <br> <h5> <p> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </p> </h5> </div> </div> <div class="container mt-3"> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="offcanvasStart"> Offcanvas Sidebar </button> <center> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20220129032254/geeks.png" alt="GFG" width="600" height="400"> <br> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <br> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20220129032254/geeks.png" alt="GFG" width="600" height="400"> <br> </center> </div> </body> </html>
Output:
Offcanvas with Dropdown Menu: The Offcanvas facilitates the dropdown menu that contains the list of options that will be only revealed when a user interacts with the menu.
Syntax:
<div class="offcanvas-body>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item"
href="#">
element 1
</a>
</li>
<li>
<a class="dropdown-item"
href="#">element 2
</a>
</li>
</ul>
</div>
Used Classes:
- dropdown-menu: This class is used to create a dropdown menu.
- dropdown-item: This class is used to list dropdown items.
Example: In this example, we will demonstrate offcanvas with the dropdown menu.
HTML <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Sidebar</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="container mt-3"> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasExample" aria-controls="offcanvasExample"> Offcanvas with dropdown menu </button> <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel"> <div class="offcanvas-header"> <h1 class="offcanvas-title" id="offcanvasExampleLabel"> GeeksforGeeks </h1> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <div> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> </div> <br> <div class="dropdown mt-3"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown"> Dropdown Menu </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <li> <a class="dropdown-item" href="#">HTML </a> </li> <li> <a class="dropdown-item" href="#">CSS </a> </li> <li> <a class="dropdown-item" href="#">JAVASCRIPT </a> </li> <li> <a class="dropdown-item" href="#">BOOTSTRAP </a> </li> </ul> </div> </div> </div> <br> <center> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> </center> </div> </body> </html>
Output:
Offcanvas with Vertical Menu: Offcanvas provides a vertical menu to choose from the options, that will be revealed when users interact with the menu.
Syntax:
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link"
href="#">
list Item 1
</a>
</li>
</ul>
Used Classes:
- navbar-nav: This class is used to create a vertical menu.
- nav-link: This class is used to add items to the vertical menu.
Example: In this example, we will demonstrate offcanvas with a vertical menu.
HTML <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Offcanvas</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="container mt-3"> <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasExample" aria-labelledby="offcanvasExampleLabel"> <div class="offcanvas-header"> <h1 class="offcanvas-title" id="offcanvasExampleLabel"> GeeksforGeeks </h1> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> <br> <nav class="navbar bg-light"> <div class="container-fluid"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" href="#"> Link 1 </a> </li> <li class="nav-item"> <a class="nav-link" href="#"> Link 2 </a> </li> <li class="nav-item"> <a class="nav-link" href="#"> Link 3 </a> </li> <li class="nav-item"> <a class="nav-link" href="#"> Link 4 </a> </li> </ul> </div> </nav> </div> </div> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasExample" aria-controls="offcanvasExample"> Offcanvas with vertical menu </button> <br> <center> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> </center> </div> </body> </html>
Output:
Accessibility using Sass Variables:
Sass variables are the variable which are used instead of the attribute value. Here some sass variables are given by bootstrap model. you can use this variable to enhance the styling of offcanvas.
- $offcanvas-padding-y : $modal-inner-padding ;
- $offcanvas-padding-x : $modal-inner-padding ;
- $offcanvas-bg-color : $modal-content-bg ;
- $offcanvas-color : $modal-content-color ;
- $offcanvas-horizontal-width : 400px ;
- $offcanvas-border-color : $modal-content-border-color ;
- $offcanvas-border-width : $modal-content-border-width ;
- $offcanvas-box-shadow : $modal-content-box-shadow-xs ;
Offcanvas Usage:
Syntax:
<a class="btn btn-primary"
data-bs-toggle="offcanvas"
aria-controls="offcanvasStart">
</a>
Used Classes:
- offcanvas: This class is used to create offcanvas but it hides the content.
Via JavaScript:
Syntax:
var offcanvasElementList =
[].slice.call(document.querySelectorAll('.offcanvas'))
var offcanvasList =
offcanvasElementList.map(function (offcanvasEl) {
return new bootstrap.Offcanvas(offcanvasEl) })
- Via Option:
- Backdrop: Its default value is true. You can see the effect of the backdrop on the body while offcanvas is open. As it is already shown in the above examples.
- Scroll: Its default value is false. You can allow body scrolling while offcanvas is open. As it is already shown in the above examples.
- Via Events:
- show.bs.offcanvas: This event fires immediately when the show instance method is called.
- shown.bs.offcanvas: This event is fired when an offcanvas element has been made visible to the user.
- hide.bs.offcanvas: This event is fired immediately when the hide method has been called.
- hidden.bs.offcanvas: This event is fired when an offcanvas element has been hidden from the user.
- Via Method:
- toggle(): This method toggles an offcanvas element to be shown or hidden. Returns to the caller before the offcanvas element has actually been shown or hidden.
- show(): This method shows an offcanvas element. Returns to the caller before the offcanvas element has actually been shown.
- Hide(): Hides an offcanvas element. Returns to the caller before the offcanvas element has actually been hidden.
Example: In this example, we will demonstrate usage of offcanvas from href attribute and data-bs-target attribute.
HTML <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Offcanvas</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> <script src= "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"> </script> </head> <body> <div class="container mt-3"> <a class="btn btn-primary" data-bs-toggle="offcanvas" href="#offcanvasStart" role="button" aria-controls="offcanvasStart"> Link with href </a> <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasStart" aria-controls="offcanvasStart"> Button with data-bs-target </button> <div class="offcanvas offcanvas-start" tabindex="-1" id="offcanvasStart" aria-labelledby="offcanvasStartLabel"> <div class="offcanvas-header"> <h1 id="offcanvasStartLabel"> GeeksforGeeks </h1> <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"> </button> </div> <div class="offcanvas-body"> <h5> Bootstrap is the most popular CSS Framework for developing responsive and mobile-first websites. </h5> </div> </div> <br> <center> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> <h4> A computer science portal for geeks. </h4> <h3> Welcome to GeeksforGeeks Welcome to GeeksforGeeks </h3> </center> </div> </body> </html>
Output:
Reference: https://getbootstrap.com/docs/5.0/components/offcanvas/
Similar Reads
Bootstrap 5 Tutorial Bootstrap 5 is a front-end framework that helps developers create responsive and visually appealing websites quickly and efficiently. Bootstrap 5 simplifies the process of web development with its intuitive design system and extensive components. This version includes improved responsiveness, stream
6 min read
Bootstrap 5 Introduction Bootstrap is a free and open-source collection of CSS and JavaScript/jQuery code used for creating dynamic websites layout and web applications. Bootstrap is one of the most popular front-end frameworks which has really a nice set of predefined CSS codes. Bootstrap uses different types of classes to
4 min read
Layout
Bootstrap 5 Layout BreakpointsBootstrap 5 layout breakpoints are specific screen widths at which the appearance and behavior of elements on a webpage change. These breakpoints enable responsive design, adjusting content layout and design for various devices, like mobile, tablet, and desktop.Core Concept:Breakpoints in responsive
3 min read
Bootstrap 5 Layout ContainersBootstrap5 Layout Containers are considered the most basic layout that can be used and they can be used to contain other layouts. Containers are basically used to add pad the contents inside or center the items inside the container. In this article, we'll see Bootstrap 5 Layout Containers.Layout Con
3 min read
BootStrap 5 Layout Grid SystemBootStrap5 Layout Grid system is responsive. It comes with a flexbox and allows up to 12 columns across the page. You can also group the columns together. The grid system is a powerful mobile-first responsive flexbox grid. How it works: Hereâs how the grid system comes together: Its grid supports si
3 min read
Bootstrap 5 ColumnsBootstrap 5 Columns facilitates the different option for the alignment, ordering, and offsetting of the Columns with the help of flexbox grid system. The different available column classes can be utilized to manage widths of non-grid elements. Bootstrap 5 Columns: The following components is used th
2 min read
Bootstrap 5 GuttersBootstrap 5 Gutters are used to give padding between columns, responsively space, and align content to the grid system. How gutters works? Using the .padding-right and .padding-left classes, we can add padding to the right and left of each column. Gutters, which are produced by horizontal padding, a
2 min read
Bootstrap 5 UtilitiesBootstrap 5 provides a lot of utilities to make a stylish, mobile-friendly, and responsive front-end website without using any CSS code. The utility layout is used for showing, hiding, aligning, and spacing content. Bootstrap 5 utilities for layout: Changing display: Bootstrap 5 provides some displa
2 min read
Bootstrap 5 Z-indexIn Bootstrap 5, the z-index property controls the stacking order of elements. It defines the depth of an element along the z-axis, determining which elements appear above others. Higher values place elements closer to the foreground, while lower values move them to the background. Bootstrap 5 z-inde
2 min read
Content
Bootstrap RebootBootstrap Reboot is used to reboot all the styles of some specific elements. It normalizes HTML elements with opinionated styles, sets better defaults for <html> and <body> elements, optimizes text rendering with native font stacks, and resets margins, paddings, and other styles for cons
2 min read
Bootstrap 5 TypographyBootstrap 5 Typography styles and formats text, providing customized headings, subheadings, lists, paragraphs, and font styles. It supports global settings for font stack, headings, link styles, ensuring consistency across devices. Here's the information represented in a table format: TermDescriptio
2 min read
Bootstrap 5 ImagesBootstrap 5 provides classes for responsive images, ensuring they scale appropriately within their parent elements, maintaining aspect ratio, and enhancing appearance across devices without overflowing.Types of Images:TermDescriptionResponsive imagesResize images according to parent element and scre
1 min read
Bootstrap 5 TablesBootstrap 5 provides a series of classes that can be used to apply various styling to the tables such as changing the heading appearance, making the rows striped, adding or removing borders, making rows hoverable, etc. Bootstrap also provides classes for making tables responsive. Bootstrap 5 Tables:
2 min read
Bootstrap 5 FiguresA Bootstrap5 Figures is a component that provides a way to display a piece of content along with an image. If we want to show the image with an optional component, the figure class in Bootstrap 5 is used. Bootstrap 5 Figures Classes: figure: used to display content, like any image with an optional c
2 min read
Forms
Bootstrap-5 FormsForm controls: <input>, <select>, <textarea> are the tags used for general appearance like input field, select item and textareas. Â Â Â Note: To make the user interface more presentable, use properties like padding, margins as per the need. Example:Â HTML <!DOCTYPE html> <
2 min read
Bootstrap 5 Form ControlsForm controls like <input>, <select>, <textarea> are the tags used to add custom styles, sizing, focus states to  input field, select item, and text-areas etc. Below are utilities of form control:Sizing: This utility is used to set the label of the form input field in different siz
2 min read
Bootstrap 5 SelectBootstrap 5 Select form is used to create customized select elements with custom CSS that changes the elementâs initial appearance. Bootstrap 5 Select Options: Default: It is used to create a default list of options from which a single option can be selected. To create a select option, we use <se
2 min read
Bootstrap 5 Checks and RadiosBootstrap 5 provides us with utility Checks and radios. This utility is used for creating checkboxes and radio without using CSS.Bootstrap 5 Checks and Radios:Checks: The checkboxes are used for selecting one or several options in a list.Radios: The radios are for selecting one option from many opti
2 min read
Bootstrap 5 RangeBootstrap 5 Range is the limit slider between values that can vary. Bootstrap provides us with a custom range of inputs that provides consistent cross-browser styling. The value and background for the range slider are both styled to look the same across all other browsers. Disabled: It is grayed out
2 min read
Bootstrap 5 Input GroupBootstrap 5 Input Group allows extending the default form controls easily by incorporating text, buttons, or button groups on either side of textual inputs, custom selects, and custom file inputs. Bootstrap 5 facilitates several different components that can be utilized to create the basic Input gro
3 min read
Bootstrap 5 Floating labelsBootstrap 5 floating labels are form labels that float over input fields, improving UX. Wrap form controls like <input>, <label>, <textarea>, <select> inside <div> with class .form-floating. Ensure these elements precede <label> inside the floating <div>.Boo
2 min read
Forms Layout
Bootstrap 5 Layout FormsBootstrap 5 Layout forms provide control of the input field and custom positioning. All the fields should be placed inside the <form> tag. By default the form is aligned vertically as the default value for display is block and is set to 100%. We can use additional classes to change this defaul
2 min read
Bootstrap5 Layout UtilitiesBootstrap 5 Layout Utilities facilitate mobile-friendly, responsive websites. They offer numerous utility classes for tasks like displaying, hiding, aligning, and spacing content, enabling versatile modifications tailored to different design requirements. NameDescriptionChanging displayBootstrap 5 p
2 min read
Bootstrap 5 Layout Form GridBootstrap 5 Layout Form Grid is used to create a complex form using grid classes. The form grid layout required multiple columns of different widths and alignments. To create a form grid, we use .row and .col classes. Form Grid Layout used Classes: .row: This class is used to create a row of a form
2 min read
Bootstrap 5 Layout GuttersGutters are the gaps between the columns in bootstrap's grid layout. The gutter modifier classes can be used to change the widths of the gutters. There are 3 primary gutter modifier classes that are listed below: Bootstrap5 Layout Gutter Modifier Classes: g-*: This class is used to set the width of
2 min read
Bootstrap 5 Layout Horizontal formBootstrap 5 Layout Horizontal form is used to create horizontal forms by using the .row class with .col-*-* classes to specify the width of your labels and controls. Also, use the .col-form-label class with <label> element to set the form label in vertically centered. Layout Horizontal form us
2 min read
Bootstrap 5 Layout Horizontal form label sizingBootstrap 5 Layout Horizontal form label sizing is used to set the label of the form input field in different sizes. To set the label size, use the .col-form-label-sm or .col-form-label-lg class to <label> or <legend> tag with the size of .form-control-lg and .form-control-sm. Horizontal
2 min read
Bootstrap 5 Layout Column sizingBootstrap 5 Layout Column sizing is used to set the width of the column element. To create equal widths columns, .col within .row classes are used. We can also use the subset of classes to set split the columns unequally. Layout Column sizing used Classes: .row: This class is used to create rows for
2 min read
Bootstrap 5 Layout Auto-sizingBootstrap5 layout Auto-sizing dynamically calculates the size height, width, and positions of the elements can be adjusted automatically. It uses a flexbox utility to vertically center the contents and changes .col to .col-auto so that your columns only take up as much space as needed.Bootstrap5 Lay
2 min read
Bootstrap 5 Layout Inline formsBootstrap 5 Layout Inline forms consist of a responsive horizontal layout. All of the elements are inline and left-aligned, and labels are alongside, and only apply to forms within viewports. Bootstrap 5 Layout Inline forms used classes:row-cols-lg-auto: This class is used to create horizontal layou
2 min read
Bootstrap 5 ValidationBootstrap 5 Validation refers to the process of enhancing form input accuracy in web development. It utilizes HTML5 validation features, providing feedback to users regarding input correctness. This feature supports customization with custom styles and JavaScript for improved user experience.Bootstr
4 min read
Components
Bootstrap 5 AccordionBootstrap 5 Accordion organizes content into collapsible panels, enabling space-efficient presentation of information. It allows users to toggle between panel visibility, enhancing user experience, and content organization within web applications. iframe { width: 100%; height: 500px;} @media (max-wi
3 min read
Bootstrap 5 AlertsBootstrap 5 Alerts are customizable components used to convey important information to users. They come in various styles such as success, warning, danger, and info, providing visual feedback to users based on different actions or states within a web application. iframe { width: 100%; height: 450px;
2 min read
Bootstrap 5 BadgesBootstrap 5 Badges are small components used to highlight specific information, typically in lists or inline with other content. They provide visual cues through colored backgrounds and customizable text, helping to draw attention to key details or status indicators within a webpage or application.
2 min read
Bootstrap BreadcrumbBootstrap 5 Breadcrumb simplifies website navigation by displaying a sequential path to the current page. It enhances user experience by visually indicating the hierarchical structure of the site, facilitating easy navigation as per Bootstrap 5 documentation. Bootstrap 5 Breadcrumb TermDescriptionBr
2 min read
Bootstrap 5 ButtonsBootstrap 5 Buttons are pre-styled components in the Bootstrap framework, offering consistent design and functionality. They streamline development by providing ready-to-use button styles, sizes, and behaviors, ensuring a cohesive and responsive user interface across web applications with minimal CS
3 min read
Bootstrap 5 | Button groupBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. Button group is a component provided by Bootstrap 5 which helps to combine the buttons in a series in a single line. All types of buttons are supported by it. Syntax: <div class="btn-
4 min read
Bootstrap 5 | CardBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. The card is a component provided by Bootstrap 5 which provides a flexible and extensible content container with multiple variants and options. It includes options for headers and footers
11 min read
Bootstrap 5 CarouselBootstrap 5 Carousel is a slideshow component for cycling through images or slides, allowing users to showcase multiple pieces of content in a visually appealing and interactive way. It offers various options for customization and responsive design.Bootstrap Carousel Classes:ClassDescriptioncarousel
3 min read
Bootstrap 5 | Close buttonBootstrap 5 provides a new component which is a Close button which can be used for dismissing content like modals and alerts. It can be included in the webpage using bootstrap.js or bootstrap.min.js. This component can be combined with models, alerts, and popovers. Disabled close buttons have pointe
1 min read
Bootstrap 5 CollapseBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. Collapse is used to toggle the visibility of content across your project with a few classes and the JavaScript plugins which comes with Bootstrap 5. The working of collapse component is
3 min read
Bootstrap 5 DropdownsBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. Dropdowns are toggleable, contextual overlays for displaying lists of links and more. Theyâre made interactive with the included Bootstrap dropdown JavaScript plugin. Theyâre toggled by
9 min read
Bootstrap 5 List groupBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. List groups are a flexible and powerful component for displaying a series of content. These can be modified and extended to support just about any content within. Use .list-group and .li
5 min read
Bootstrap 5 ModalBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. 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 eve
7 min read
Navbar
Bootstrap 5 Navbar BrandBootstrap 5 Navbar brand is applied to the typical branding logo that sees in the top navigation bar. It may contain an image logo or text, etc. A Navbar helps readers in selecting topics, links, or sub-topics of their interest. Bootstrap 5 Navbar Brand: Text: The text in the user interface is added
3 min read
Bootstrap 5 Navbar Brand TextA navigation bar is used in every website to make it more user-friendly so that the navigation through the website becomes easy and the user can directly search for the topic of their interest. Navbar Brand Text is used to add text in place of the brand logo. We can write text or links using the nav
2 min read
Bootstrap Navbar Brand ImageBootstrap Navbar Brand Image is used to put the image inside of a navbar, a navigation bar component in the Bootstrap framework. It typically appears at the top of a webpage, serving as a visual identifier for the website or application and linking back to the homepage. Pre-requisite: To use images
2 min read
Bootstrap 5 Navbar NavBootstrap 5 Navbar Nav simplifies navigation creation by grouping navigation links within a container element with the nav class. Use nav-item for each link and nav-link for styling. Customize with optional classes like "active" for the current page. Bootstrap 5 Navbar Nav class: There is no specifi
2 min read
Bootstrap 5 Navbar FormsBootstrap 5 Navbar Forms are used to create the components like a search bar, or login within a navbar. Bootstrap 5 Navbar Forms Classes: No special classes are used in Navbar Forms. You can customize the form using Navbar and Form classes Syntax: <nav class="navbar"> <form> <input cl
2 min read
Bootstrap 5 Navbar TextNavbar Text is used to put some text on the navbar. To do so Bootstrap 5 brings the Bootstrap 5 Navbar Text features. Creating a navbar is obvious when we are creating a website, and putting text on the navbar is required to guide the visitors to the right destination. Navbar Text Class: navbar-text
2 min read
Bootstrap 5 OffcanvasBootstrap is a free and open-source collection of CSS and JavaScript/jQuery code used for creating responsive & dynamic websites layout and web applications. Offcanvas is one of the features of Bootstrap to make web pages more attractive, along with enhancing the user experience.Offcanvas is a s
12 min read
Bootstrap 5 PopoversBootstrap 5 Popovers Provides directional placement options (top, bottom, left, right), dismiss on click, and support for disabled elements. Styled with Sass, they feature various methods, options, and events for dynamic interaction and customization. Bootstrap 5 Popovers: AspectDescriptionFour dire
2 min read
Bootstrap 5 ProgressBootstrap 5 is the latest major release by Bootstrap in which they have revamped the UI and made various changes. A progress bar is used to display the progress of a process on a computer. A progress bar displays how much of the process is completed and how much is left. You can add a progress bar o
5 min read
Bootstrap 5 ScrollspyBootstrap 5 Scrollspy is used to automatically update the navigation links based on the scroll position, highlighting the corresponding section in the viewport.To use scrollspy in Bootstrap 5, we need to add the data-bs-spy="scroll" attribute to the element that should be used for scrolling and spec
4 min read
Bootstrap 5 SpinnersIn this article, we will implement spinners in the website using Bootstrap & will also see the implementation of different types of spinners through the example. The spinners are used to specify the loading state of a component or webpage. Bootstrap facilitates the various classes for creating d
3 min read
Bootstrap 5 ToastsBootstrap 5 Toasts are notifications or messages which the users receive whenever they perform certain actions. They can easily be customized. Overview: Toasts need to be initialized. Apply autohide: false so that the toasts don't automatically hide.Placement: You can place toasts as you want. The t
3 min read
Bootstrap 5 TooltipsA Tooltip is used to provide interactive textual hints to the user about the element when the mouse pointer moves over. The tooltip is quite useful for displaying the description of different elements on the webpage. To create a tooltip, we need to add the data-bs-toggle="tooltip" attribute to an el
3 min read
Helpers
Bootstrap 5 ClearfixBootstrap 5 .clearfix helper class facilitates clearing and fixing the floated content in an element or container by adding the clearfix utility. Basically, without clearfix class, the floated content/elements act like they have a position set to absolute and to fix that, we use the clearfix helper
2 min read
Bootstrap 5 Colored linksBootstrap 5 Colored links are used to add colors to the link element. To set the colored links, we use the classes of utilities built on our theme colors. To make different color links, we will use .link-* class and add CSS styles to it. Colored links used Classes: link-primary: This class is used t
2 min read
Bootstrap 5 RatiosBootstrap 5 provides ratios, which can be used to create fixed-ratio containers. These containers maintain a specific aspect ratio, regardless of the size of the screen or the content within them. Bootstrap 5 Ratios: Aspect ratio: The proportionality between an element's height and breadth is known
2 min read
Bootstrap 5 PositionBootstrap 5 Position offers utility classes to control the positioning of elements. It includes classes like "position-static," "position-relative," "position-absolute," etc., facilitating precise element positioning on web pages for improved layout and design control.NameDescriptionposition-staticD
2 min read
Bootstrap 5 Visually hiddenBootstrap 5 Â Visually hidden are used to visually hide an element so that it does not display on the page while still allowing it to be exposed to assistive technologies. .The visually-hidden class hides the element by default and the visually-hidden-focusable class visually hides an element but dis
2 min read
Bootstrap 5 Stretched linkBootstrap 5 Stretched link is used to make any component clickable. Multiple links are not recommended. The card in bootstrap has position:relative by default, so we can easily add .stretched-link class to a link. Bootstrap 5 Stretched link class: stretched-link: It is added to <a> tag to make
2 min read
Bootstrap 5 Text TruncationBootstrap 5 is a catalog of UI components that enables developers to develop their websites and applications in less time by using the pre-built components and utility classes. This article will see Bootstrap 5 Text truncation.Text Truncation is used to truncate long statements and paragraphs using
2 min read
Extend