Bird
Raised Fist0
Bootsrapmarkup~10 mins

Navbar brand and toggler in Bootsrap - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a brand name inside the navbar.

Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">[1]</a>
</nav>
Drag options to blanks, or click blank then click option'
Acollapse
Bnavbar-toggler
CMySite
Dcontainer-fluid
Attempts:
3 left
💡 Hint
Common Mistakes
Using classes like 'navbar-toggler' instead of the brand name text.
Leaving the blank empty or putting invalid class names.
2fill in blank
medium

Complete the code to add a button that toggles the navbar on small screens.

Bootsrap
<button class="navbar-toggler" type="button" data-bs-toggle="[1]" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
</button>
Drag options to blanks, or click blank then click option'
Acollapse
Bdropdown
Cmodal
Dtooltip
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dropdown' or 'modal' instead of 'collapse' for toggling navbar.
Leaving the attribute empty or incorrect.
3fill in blank
hard

Fix the error in the button's aria-label attribute to improve accessibility.

Bootsrap
<button class="navbar-toggler" type="button" aria-label="[1]">
  <span class="navbar-toggler-icon"></span>
</button>
Drag options to blanks, or click blank then click option'
AToggle navigation
BOpen menu
CClose menu
DExpand navbar
Attempts:
3 left
💡 Hint
Common Mistakes
Using vague or incorrect labels like 'Open menu' or 'Close menu'.
Leaving aria-label empty or missing.
4fill in blank
hard

Fill both blanks to complete the navbar brand link and toggler button.

Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="[1]" href="#">Brand</a>
  <button class="[2]" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
</nav>
Drag options to blanks, or click blank then click option'
Anavbar-brand
Bnavbar-collapse
Cnavbar-toggler
Dnavbar-nav
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'navbar-collapse' or 'navbar-nav' with brand or toggler classes.
Using incorrect classes that do not style or function properly.
5fill in blank
hard

Fill all three blanks to complete the navbar with brand, toggler, and collapsible content.

Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="[1]" href="#">MySite</a>
  <button class="[2]" type="button" data-bs-toggle="collapse" data-bs-target="#[3]" aria-controls="[3]" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="[3]">
    <!-- Navbar content here -->
  </div>
</nav>
Drag options to blanks, or click blank then click option'
Anavbar-brand
Bnavbar-toggler
CnavbarSupportedContent
Dnavbar-collapse
Attempts:
3 left
💡 Hint
Common Mistakes
Using mismatched IDs between button and collapsible div.
Using wrong classes for brand or toggler.

Practice

(1/5)
1. What is the main purpose of the navbar-brand class in a Bootstrap navbar?
easy
A. To create a button that toggles the menu on small screens
B. To add navigation links inside the navbar
C. To display the site name or logo prominently in the navbar
D. To style the background color of the navbar

Solution

  1. Step 1: Understand the role of navbar-brand

    The navbar-brand class is used to show the website's name or logo in the navbar.
  2. Step 2: Differentiate from other navbar elements

    The toggler button is for menu control, links are for navigation, and background color is styling, not branding.
  3. Final Answer:

    To display the site name or logo prominently in the navbar -> Option C
  4. Quick Check:

    navbar-brand = site name/logo [OK]
Hint: Brand means site name or logo in navbar [OK]
Common Mistakes:
  • Confusing navbar-brand with navbar-toggler
  • Thinking navbar-brand adds navigation links
  • Assuming navbar-brand controls styling only
2. Which of the following is the correct HTML structure for a Bootstrap navbar toggler button?
easy
A.
B.
D. Toggle

Solution

  1. Step 1: Check Bootstrap 5 toggler button syntax

    The toggler is a button with class navbar-toggler, type button, and uses data-bs-toggle="collapse" and data-bs-target to control the menu.
  2. Step 2: Verify accessibility attributes

    It includes aria-controls, aria-expanded, and aria-label for screen readers.
  3. Final Answer:

    Option A matches the correct Bootstrap 5 toggler button structure -> Option A
  4. Quick Check:

    Correct toggler uses button with data-bs-toggle and aria-label [OK]
Hint: Toggler is a button with data-bs-toggle="collapse" [OK]
Common Mistakes:
  • Using <div> instead of <button> for toggler
  • Wrong data attributes like data-toggle instead of data-bs-toggle
  • Missing aria-label for accessibility
3. Given this Bootstrap navbar snippet, what will happen when viewed on a small screen?
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">MySite</a>
  <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navMenu" aria-controls="navMenu" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navMenu">
    <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="#">About</a></li>
    </ul>
  </div>
</nav>
medium
A. The navbar-brand will disappear on small screens
B. The menu items will always be visible and the toggler button does nothing
C. The toggler button will open a modal instead of collapsing the menu
D. The menu items will be hidden and can be toggled by clicking the hamburger button

Solution

  1. Step 1: Understand navbar-expand-lg behavior

    The class navbar-expand-lg means the navbar expands (shows menu) on large screens and collapses on smaller screens.
  2. Step 2: Check toggler and collapse relationship

    The toggler button controls the div with collapse navbar-collapse and id navMenu. On small screens, the menu is hidden and toggled by the button.
  3. Final Answer:

    The menu items will be hidden and can be toggled by clicking the hamburger button -> Option D
  4. Quick Check:

    navbar-expand-lg collapses menu on small screens [OK]
Hint: navbar-expand-lg hides menu below large screens [OK]
Common Mistakes:
  • Thinking menu is always visible
  • Assuming navbar-brand disappears on small screens
  • Confusing toggler with modal trigger
4. Identify the error in this Bootstrap navbar toggler button code:
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#menu" aria-controls="menu" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
</button>
medium
A. Missing closing tag for button
B. Incorrect data attribute names; should use data-bs-toggle and data-bs-target
C. aria-expanded should be true by default
D. navbar-toggler-icon class is invalid

Solution

  1. Step 1: Check Bootstrap 5 data attribute naming

    Bootstrap 5 requires data-bs-toggle and data-bs-target instead of data-toggle and data-target.
  2. Step 2: Verify other attributes

    The button is properly closed, aria-expanded can be false initially, and navbar-toggler-icon is a valid class.
  3. Final Answer:

    Incorrect data attribute names; should use data-bs-toggle and data-bs-target -> Option B
  4. Quick Check:

    Bootstrap 5 uses data-bs-* attributes [OK]
Hint: Bootstrap 5 uses data-bs-toggle, not data-toggle [OK]
Common Mistakes:
  • Using old Bootstrap 4 data attributes
  • Changing aria-expanded default incorrectly
  • Misnaming navbar-toggler-icon class
5. You want to create a responsive Bootstrap navbar with a brand logo image and a toggler that controls the menu. Which of the following code snippets correctly implements both the brand and toggler with accessibility in mind?
hard

Solution

  1. Step 1: Check brand logo and alt text

    includes an img with descriptive alt="Site Logo", which is good for accessibility. has empty alt, which is less accessible.
  2. Step 2: Verify toggler button attributes

    uses correct Bootstrap 5 attributes data-bs-toggle="collapse" and data-bs-target="#navbarMenu" with proper aria attributes. uses old data-toggle and misses some aria attributes. incorrectly uses data-bs-toggle="dropdown" which is wrong for toggling collapse.
  3. Final Answer:

    Option A correctly implements brand logo with alt and toggler with proper attributes -> Option A
  4. Quick Check:

    Brand with alt + toggler with data-bs-toggle="collapse" [OK]
Hint: Use img alt and data-bs-toggle="collapse" for toggler [OK]
Common Mistakes:
  • Missing alt text on brand logo image
  • Using old data-toggle instead of data-bs-toggle
  • Using dropdown toggle instead of collapse toggle
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard