Master Bootstrap From Scratch

Clear, interactive, and structured Bootstrap lessons designed for beginners and developers.

Bootstrap Navbar

Bootstrap Navbar is a responsive navigation component used to create the main navigation area of a website. It can contain a brand name, navigation links, buttons, dropdowns and other controls.

Simple Explanation: A Navbar is the main menu of a website. For example, it can contain Home, About, Courses, Services and Contact links at the top of a webpage.

What is a Bootstrap Navbar?

A Bootstrap Navbar is a responsive navigation component that helps users move between important pages and sections of a website.

A Navbar can contain several elements such as a brand, navigation links, dropdown menus, buttons and a responsive toggle button.

Simple Explanation: Think of the Navbar as the main menu of your website. It normally appears at the top of the page and gives users quick access to important sections.

1. Basic Navbar

A basic Navbar can be created using the .navbar and .navbar-expand classes.

Simple Explanation: The .navbar class creates the Navbar, while other Bootstrap classes control its layout, color and responsiveness.

Example

<nav class="navbar navbar-expand-lg bg-body-tertiary">

    <div class="container-fluid">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

        <div class="navbar-nav">

            <a class="nav-link active" href="#">
                Home
            </a>

            <a class="nav-link" href="#">
                Courses
            </a>

            <a class="nav-link" href="#">
                Contact
            </a>

        </div>

    </div>

</nav>
Output:

2. Navbar Brand

The .navbar-brand class is used to display the name or brand of the website.

Simple Explanation: The brand is usually the first element users see in the Navbar. It can contain a company name or website name.

Example

<a class="navbar-brand" href="#">
    CIIT Training Institute
</a>

3. Navbar Links

Navbar links are created using the .nav-link class.

Simple Explanation: Navbar links are the clickable options that allow users to move from one page or section to another.

Example

<nav class="navbar">

    <a class="nav-link" href="#">
        Home
    </a>

    <a class="nav-link" href="#">
        Courses
    </a>

    <a class="nav-link" href="#">
        About
    </a>

    <a class="nav-link" href="#">
        Contact
    </a>

</nav>

4. Navbar Colors

Bootstrap provides background and text utility classes that can be used to change the appearance of a Navbar.

Simple Explanation: We can use Bootstrap background classes such as bg-primary or bg-dark to change the Navbar background.

Example

<nav class="navbar bg-primary">

    <div class="container-fluid">

        <a class="navbar-brand text-white" href="#">
            CIIT
        </a>

    </div>

</nav>
Output:

5. Dark Navbar

A dark Navbar can be created using the navbar-dark approach together with a dark background.

Simple Explanation: A dark Navbar provides a dark background and light-colored navigation text.

Example

<nav class="navbar bg-dark">

    <div class="container-fluid">

        <a class="navbar-brand text-white" href="#">
            CIIT
        </a>

        <a class="nav-link text-white" href="#">
            Courses
        </a>

    </div>

</nav>

6. Navbar with Button

Buttons can be placed inside a Navbar for actions such as Login, Register, Enroll Now or Contact Us.

Simple Explanation: Navigation links are mainly used for navigation, while buttons are useful for important actions.

Example

<nav class="navbar bg-body-tertiary">

    <div class="container-fluid">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

        <button class="btn btn-primary">
            Enroll Now
        </button>

    </div>

</nav>

7. Responsive Navbar

One of the most important features of the Bootstrap Navbar is its responsive behavior.

The Navbar can automatically collapse navigation links on smaller screens using the Bootstrap responsive classes and collapse component.

Simple Explanation: On a desktop screen, the menu can show all links. On a mobile screen, the links can be hidden inside a toggle button and displayed when the user clicks it.

Example

<nav class="navbar navbar-expand-lg bg-body-tertiary">

    <div class="container-fluid">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

        <button class="navbar-toggler"
                type="button"
                data-bs-toggle="collapse"
                data-bs-target="#mainNavbar">

            <span class="navbar-toggler-icon"></span>

        </button>

        <div class="collapse navbar-collapse"
             id="mainNavbar">

            <ul class="navbar-nav me-auto">

                <li class="nav-item">
                    <a class="nav-link" href="#">
                        Home
                    </a>
                </li>

                <li class="nav-item">
                    <a class="nav-link" href="#">
                        Courses
                    </a>
                </li>

                <li class="nav-item">
                    <a class="nav-link" href="#">
                        Contact
                    </a>
                </li>

            </ul>

        </div>

    </div>

</nav>
Output:

8. Navbar with Dropdown

A Navbar can contain dropdown menus to organize multiple related links under one menu item.

Simple Explanation: Suppose we have many courses such as Java, Python and .NET. Instead of showing every course directly, we can put them inside a Courses dropdown.

Example

<nav class="navbar navbar-expand-lg bg-body-tertiary">

    <div class="container-fluid">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

        <ul class="navbar-nav">

            <li class="nav-item dropdown">

                <a class="nav-link dropdown-toggle"
                   href="#"
                   data-bs-toggle="dropdown">

                    Courses

                </a>

                <ul class="dropdown-menu">

                    <li>
                        <a class="dropdown-item" href="#">
                            Java Full Stack
                        </a>
                    </li>

                    <li>
                        <a class="dropdown-item" href="#">
                            Python Full Stack
                        </a>
                    </li>

                    <li>
                        <a class="dropdown-item" href="#">
                            .NET Full Stack
                        </a>
                    </li>

                </ul>

            </li>

        </ul>

    </div>

</nav>
Output:

9. Navbar with Search Form

A search form can be placed inside a Navbar so that users can search for content directly from the menu.

Simple Explanation: A search box inside the Navbar allows users to quickly find courses, pages, products or other information.

Example

<nav class="navbar bg-body-tertiary">

    <div class="container-fluid">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

        <form class="d-flex">

            <input class="form-control me-2"
                   type="search"
                   placeholder="Search">

            <button class="btn btn-primary"
                    type="submit">

                Search

            </button>

        </form>

    </div>

</nav>
Output:

10. Navbar with Container

The .container or .container-fluid class can be used inside a Navbar to control its content width.

Simple Explanation: container keeps the content within a responsive maximum width, while container-fluid uses almost the full available width.

Example

<nav class="navbar bg-body-tertiary">

    <div class="container">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

        <a class="nav-link" href="#">
            Courses
        </a>

    </div>

</nav>

11. Fixed Navbar

Bootstrap provides utilities that can keep a Navbar fixed to a particular position on the screen.

Common classes include fixed-top and fixed-bottom.

Simple Explanation: A fixed Navbar stays attached to the top or bottom of the browser window even when the page is scrolled.

Fixed Top Example

<nav class="navbar fixed-top bg-body-tertiary">

    <div class="container">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

    </div>

</nav>
Important: The live output is not fixed on this lesson page because a fixed Navbar can cover the page's existing header and navigation.

12. Sticky Navbar

The sticky-top utility can be used to make an element behave like a sticky element while scrolling.

Simple Explanation: A sticky Navbar behaves normally until it reaches the top of the screen. After that, it remains visible while the user continues scrolling.

Example

<nav class="navbar sticky-top bg-body-tertiary">

    <div class="container">

        <a class="navbar-brand" href="#">
            CIIT
        </a>

    </div>

</nav>
Note: sticky-top is a Bootstrap utility class that uses CSS sticky positioning.

13. Real-World CIIT Training Institute Example

A training institute website can use a Navbar to provide quick access to important sections such as Home, Courses, Internship, Placement and Contact.

Simple Explanation: The Navbar acts as the main menu of the institute website. Students can use it to quickly navigate to courses and other important sections.

Example

<nav class="navbar navbar-expand-lg bg-body-tertiary">

    <div class="container-fluid">

        <a class="navbar-brand fw-bold"
           href="#">

            CIIT Training Institute

        </a>

        <button class="navbar-toggler"
                type="button"
                data-bs-toggle="collapse"
                data-bs-target="#ciitNavbar">

            <span class="navbar-toggler-icon"></span>

        </button>

        <div class="collapse navbar-collapse"
             id="ciitNavbar">

            <ul class="navbar-nav me-auto mb-2 mb-lg-0">

                <li class="nav-item">

                    <a class="nav-link active"
                       href="#">

                        Home

                    </a>

                </li>

                <li class="nav-item">

                    <a class="nav-link"
                       href="#">

                        Courses

                    </a>

                </li>

                <li class="nav-item">

                    <a class="nav-link"
                       href="#">

                        Internship

                    </a>

                </li>

                <li class="nav-item">

                    <a class="nav-link"
                       href="#">

                        Placement

                    </a>

                </li>

                <li class="nav-item">

                    <a class="nav-link"
                       href="#">

                        Contact

                    </a>

                </li>

            </ul>

            <button class="btn btn-primary">
                Enroll Now
            </button>

        </div>

    </div>

</nav>
Output:

Important Bootstrap Navbar Classes

Class Purpose
.navbar Creates the main Navbar component.
.navbar-brand Displays the website or company brand.
.navbar-nav Contains the navigation links.
.nav-item Represents an individual navigation item.
.nav-link Styles a navigation link.
.navbar-expand-lg Controls when the Navbar expands on larger screens.
.navbar-toggler Creates the responsive toggle button.
.navbar-collapse Contains collapsible Navbar content.
.fixed-top Fixes the Navbar to the top.
.sticky-top Makes the Navbar sticky while scrolling.

Common Mistakes

  • Forgetting the .navbar class.
  • Using an incorrect ID between data-bs-target and navbar-collapse.
  • Forgetting Bootstrap JavaScript when using the responsive toggle or dropdown.
  • Using too many links inside the Navbar.
  • Not testing the Navbar on mobile screen sizes.
  • Using fixed-top without considering the content that may appear underneath it.
  • Not providing a meaningful active link for the current page.

Summary

  • Bootstrap Navbar is used to create the main navigation area of a website.
  • .navbar-brand is used for the website or company name.
  • .navbar-nav contains navigation items.
  • .nav-link creates navigation links.
  • .navbar-toggler provides a responsive menu button on smaller screens.
  • Navbar can contain dropdowns, buttons and search forms.
  • fixed-top can keep the Navbar at the top.
  • A responsive Navbar improves navigation on both desktop and mobile devices.