How to make your Bootstrap menu responsive without bootstrap.js

Bootstrap is absolutely great, I still love it, always will - it seems like nothing could replace it so far. But sometimes all I want to do is a basic design, without carrying all the machinery Bootstrap framework is. I just need to make use of Bootstrap’s well-known grid, a basic navbar and I will handle the rest.

So here I’m going to show you how to make your Bootstrap 5 navbar responsive without bootstrap.js/bootstrap.min.js.

I will assume this is the navbar we want collapsable on smaller devices:

<nav class="navbar navbar-expand-lg navbar-light"> 
  <div class="container">        
    <a class="navbar-brand d-flex align-items-center" href="/">         
      <img class="me-1" height="30" src="/assets/img/logo.png">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">   
      <ul class="navbar-nav">
        <li class="nav-item ms-2">
          <a class="nav-link" href="/themes/">Nav Item</a>
        <li class="nav-item ms-2">
          <a class="nav-link" href="/themes/theme-installation/">Nav Item</a>
        <li class="nav-item ms-2">
          <a class="nav-link" href="/contact/">Nav Item</a>

Code snippet

Place it before closing </body>. You can remove the first line if you already called jquery.

<script src=""></script>

      $( ".collapse" ).toggleClass( 'show' );

That’s it! Hope it helps.

demo   Mediumish - our most loved WordPress theme
Mediumish Theme