Responsive Sticky Navbar in Bootstrap 5

Responsive Sticky Navbar in Bootstrap 5
Code Snippet:Bootstrap 5 - Sticky Navbar
Author: Web Zone
Published: January 10, 2024
Last Updated: January 22, 2024
Downloads: 1,268
License: MIT
Edit Code online: View on CodePen
Read More

A sticky navbar is a great way to improve the usability of your website. This code snippet helps you to create a responsive sticky navbar for your Bootstrap 5 projects. It uses Bootstrap native navbar with sticky classes. The navbar will remain at the top of the page as you scroll, making it easy for users to navigate your website.

How to Create Responsive Sticky Navbar Bootstrap 5

1. Start by including the Bootstrap 5 CSS file in your HTML. Copy and paste the following link in the <head> section of your HTML document.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css">

2. In the <body> section, create a top header to add a professional touch to your website. Add a responsive and sticky navbar to your website using the code below. Place it after the top header.

<!-- Top Header -->
<div class="top-header py-4">
  <div class="container">
    <h1>Web Zone</h1>
  </div>
</div>

<!-- Navbar  -->
<nav class="navbar sticky-top navbar-expand-lg navbar-dark bg-dark bg-gradient">
  <div class="container">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a href="#" class="nav-link">About</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">Blog</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">Pricing</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">FAQ's</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">Contact</a>
      </li>
    </ul>
  </div>
</nav>

<!-- Main Content -->
<div class="main">
  <div class="container">
    <div class="box border mt-5 p-5">
      <p>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quaerat
        dolor placeat fuga sapiente ipsa et enim? Dolor, ab error? Nihil
        inventore natus vel nemo praesentium expedita laudantium cum
        blanditiis minus?
      </p>
    </div>
    <div class="box border mt-5 p-5">
      <p>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quaerat
        dolor placeat fuga sapiente ipsa et enim? Dolor, ab error? Nihil
        inventore natus vel nemo praesentium expedita laudantium cum
        blanditiis minus?
      </p>
    </div>
    <div class="box border mt-5 p-5">
      <p>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quaerat
        dolor placeat fuga sapiente ipsa et enim? Dolor, ab error? Nihil
        inventore natus vel nemo praesentium expedita laudantium cum
        blanditiis minus?
      </p>
    </div>
    <div class="box border mt-5 p-5">
      <p>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quaerat
        dolor placeat fuga sapiente ipsa et enim? Dolor, ab error? Nihil
        inventore natus vel nemo praesentium expedita laudantium cum
        blanditiis minus?
      </p>
    </div>
    <div class="box border mt-5 p-5">
      <p>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quaerat
        dolor placeat fuga sapiente ipsa et enim? Dolor, ab error? Nihil
        inventore natus vel nemo praesentium expedita laudantium cum
        blanditiis minus?
      </p>
    </div>
  </div>
</div>

Within the <ul> tag of the navbar, add your navigation links. Update the href attributes to point to the relevant sections of your website.

3. If needed, you can add custom CSS styles to modify the appearance.

.navbar{
    /* Your custom CSS styles goes here */
}

That’s all! hopefully, You’ve successfully implemented a responsive sticky navbar on your website. Customize it further to suit your website’s theme and content. This navigation enhancement ensures a seamless user experience, making your website more accessible and visually appealing.

If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X