Top 3 features of Bootstrap5 - Removed Jquery dependency

Last updated Aug 10, 2021


Bootstap, what is bootstrap the world's most popular framework for building responsive, mobile-first sites
Bootstrap home page changed with their major release v5.1.0

Now here we will know what are the major changes in bootstrap 5

  • New Logo
  • New Offcanvas
  • New Accordian
  • RTL feature
  • New and Updated Forms
  • New Components Utilities API
  • Enhanced Grid and Layout
  • Jquery isn't required any more
  • Enhanced Modularity
  • Enhanced Icons

 

To work with new Bootstrap 5 features we need to add related css and js file into the file

script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js">
</script>

 

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"  crossorigin="anonymous">

 

 

New Logo
Now they changed the logo ass curl brases and added B inside these braces

Bootstrap 5 logo

 

 

New Offcanvas
One of the major feature of the bootstrap5 is Offcanvas
What is Offcanvas component - It is a sidebar component that can be toggled via javascript to appear from the left, right or bottom edge of the viewport

Now let's create simple Offcanvas example with bootstrap5

Create simple HTML file and add Bootstrap5 css and js files

 

Now add our example code which will show offcanvas when we tap on toogle button

let's see the complete code

html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"  crossorigin="anonymous">

</head>
<body>
<div class="container min-vh-100 py-2">
<div class="row">
<div class="col">
<h2 class="font-weight-light">Bootstrap 5 Sidebar</h2>
<p> This is a Bootstrap 5 off-canvas menu example! </p>
<div class="d-flex justify-content-end form-check form-switch form-control-lg">
<input class="form-check-input" type="checkbox" id="toggleSidebar">
<label class="form-check-label ms-1" for="toggleSidebar">Toggle Offcanvas</label>
</div>
<div class="text-center">
<img src="https://icons.getbootstrap.com/assets/img/icons-hero.png" />
</div>
<div class="offcanvas offcanvas-start bg-light" tabindex="-1" id="offcanvasExample">
<div class="offcanvas-header">
<h5 class="offcanvas-title">Offcanvas</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div> Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc. </div>
<div class="dropdown mt-3">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown"> Menu </button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>


<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js">
</script>
<script>
var toggle = document.getElementById("toggleSidebar")
var offcanvas_el = document.getElementById("offcanvasExample")
var offcanvas = new bootstrap.Offcanvas(offcanvas_el, {backdrop: false})

toggle.addEventListener("change", function(){
toggle.checked ? offcanvas.show() : offcanvas.hide()
})

// handle case when sidebar is closed internally using `X`
offcanvas_el.addEventListener('hide.bs.offcanvas', function () {
toggle.checked = false
})

</script>
</body>
</html>

 

New Accordian
Bootstrap5 has one more feature called Accordian. Previously it has .card accordian now they changed to new .accordian component. This new accordian still uses Javascript plugin with some custom css and HTML.

This Accordian includes bootstrap Icons as chevron icons indicating state and clickability.
This new accordian has properties

 

Flush
To remove default background color by add .accordion-flush

Always Open
To open accrodin item when other item opens we need to remove the data-bs-parent attribute from each item

 

Simple Bootstrap Accordian example from official website

<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"  crossorigin="anonymous">

</head>
<body>

<div class="accordion" id="accordionExample">
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Accordion Item #1
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingTwo">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Accordion Item #2
</button>
</h2>
<div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingThree">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Accordion Item #3
</button>
</h2>
<div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
<div class="accordion-body">
<strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
</div>
</div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js">
</script>
<script>
var toggle = document.getElementById("toggleSidebar")
var offcanvas_el = document.getElementById("offcanvasExample")
var offcanvas = new bootstrap.Offcanvas(offcanvas_el, {backdrop: false})

toggle.addEventListener("change", function(){
toggle.checked ? offcanvas.show() : offcanvas.hide()
})

// handle case when sidebar is closed internally using `X`
offcanvas_el.addEventListener('hide.bs.offcanvas', function () {
toggle.checked = false
})

</script>
</body>
</html>

 

RTL (Right to Left)
Finally bootstrap introduced RTL supprt
 
To Enable RTL we need to required two attributes

  • Set dir="rtl" on the <html> element.
  • Add an appropriate lang attribute, like lang="ar", on the <html> element

 

Then we need to add RTl suported CSS file

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.rtl.min.css" integrity="sha384-gXt9imSW0VcJVHezoNQsP+TNrjYXoGcrqBZJpry9zJt8PCQjobwmhMGaDHTASo9N" crossorigin="anonymous">

 

 

Simple new bootstrap 5 RTL example from official website

<!doctype html>
<html lang="ar" dir="rtl">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.rtl.min.css" integrity="sha384-gXt9imSW0VcJVHezoNQsP+TNrjYXoGcrqBZJpry9zJt8PCQjobwmhMGaDHTASo9N" crossorigin="anonymous">

<title>RTL Support</title>
</head>
<body style="padding:30px;">
<h1>RTL Support</h1>



<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>


</body>
</html>

 

API Utilities

Added new API utiles Bootstrap

From official website Utilities

Speaking of utilities, we’ve added a ton of new ones to our arsenal, including:

  • Added positioning utilities: toprightbottom, and left with 050%, and 100% values

  • Added .d-grid option, along with new gap utilities for easy grid layouts

  • Added .fs utilities for font-size

  • Renamed font-weight utilities to .fw

  • Added .rounded-1.rounded-2, and .rounded-3 for new small, medium, and large border-radius utilities

    • Added .overflow-visible and .overflow-scroll utilities

Check out the Migration guide and utilities documentation for more details.

 

 

 

 

 


Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

55 Views

Subscribe For Daily Updates

Flutter Questions
Android Questions