Bootstrap 5·Bootstrap from grid to dashboard

Navbar and navigation

Build a responsive navbar with a mobile toggler and a dropdown.

Beginner 13 min read Lesson 7 of 300 Challenge included
What you will be able to do
  • Use navbar navbar-expand-lg for the base.
  • Add a toggler with aria-controls and aria-expanded.
  • Use navbar-nav for the link list.
  • Mark the current page with aria-current="page".

In plain English

A navbar collapses below a breakpoint and expands above it. The toggler needs aria-controls, aria-expanded and a label. Keep the navigation structure semantic with nav and a list of links.

nav.htmlHTML
<nav class="navbar navbar-expand-lg bg-body-tertiary">
  <div class="container">
    <a class="navbar-brand" href="/">EduByte</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#main" aria-controls="main" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="main">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item"><a class="nav-link active" aria-current="page" href="/tutorials">Tutorials</a></li>
      </ul>
    </div>
  </div>
</nav>
Your turn

Add a second nav item

Easy

Add a References link to the navbar list and mark Tutorials as current.

HTML · starter
<li class="nav-item">
Check your understanding before moving on.
Knowledge checkQuestion 1

Which attribute tells assistive technology whether the collapsed menu is open?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Modals and offcanvas
Lesson 7 of 300 · 0% of course