Bird
Raised Fist0
Bootsrapmarkup~20 mins

Navbar brand and toggler in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Bootstrap Navbar Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ rendering
intermediate
2:00remaining
What is the visual output of this Bootstrap navbar code?
Look at the following Bootstrap 5 navbar code snippet. What will you see rendered in the browser?
Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">MySite</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Features</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
AA navbar with brand name 'MySite' centered and no toggler button visible on any screen size.
BA horizontal navbar with brand name 'MySite' on the left, a toggler button visible on small screens, and two links 'Home' and 'Features' that collapse behind the toggler on small screens.
CA navbar with brand name 'MySite' on the right and the toggler button on the left, with links always visible.
DA vertical sidebar with brand name 'MySite' at the top and two links 'Home' and 'Features' always visible below it.
Attempts:
2 left
💡 Hint
Think about how Bootstrap's navbar-expand-lg class controls when the toggler appears and how the collapse class hides links on small screens.
📝 Syntax
intermediate
1:30remaining
Which option correctly adds an accessible label to the navbar toggler button?
Bootstrap recommends adding an aria-label to the toggler button for accessibility. Which of these button codes correctly includes an accessible label?
A
&lt;button class="navbar-toggler" type="button" aria-description="Toggle navigation"&gt;
  &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
&lt;/button&gt;
B
&lt;button class="navbar-toggler" type="button" aria-labelledby="toggleLabel"&gt;
  &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
&lt;/button&gt;
C
&lt;button class="navbar-toggler" type="button" aria-hidden="true"&gt;
  &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
&lt;/button&gt;
D
&lt;button class="navbar-toggler" type="button" aria-label="Toggle navigation"&gt;
  &lt;span class="navbar-toggler-icon"&gt;&lt;/span&gt;
&lt;/button&gt;
Attempts:
2 left
💡 Hint
The aria-label attribute provides a text label directly on the element for screen readers.
❓ selector
advanced
1:30remaining
Which CSS selector targets only the navbar brand link inside a Bootstrap navbar?
You want to style only the brand link inside a Bootstrap navbar. Which CSS selector correctly targets it?
Anav > .navbar-brand
B.navbar-brand > a
C.navbar .navbar-brand
D.navbar-brand a
Attempts:
2 left
💡 Hint
Remember the brand link has the class 'navbar-brand' and is inside an element with class 'navbar'.
❓ layout
advanced
1:30remaining
What layout behavior does the class 'navbar-expand-md' provide in Bootstrap?
If you use the class 'navbar-expand-md' on a navbar, how does it behave on different screen sizes?
AThe navbar links are collapsed behind the toggler on screens smaller than medium (md) and shown horizontally on medium and larger screens.
BThe navbar links are always collapsed behind the toggler on all screen sizes.
CThe navbar links are always shown horizontally on all screen sizes.
DThe navbar links collapse only on extra large (xl) screens and are horizontal on smaller screens.
Attempts:
2 left
💡 Hint
The 'expand-md' means expand starting at medium screens and up.
🧠 Conceptual
expert
2:00remaining
Why is it important to include the 'aria-controls' attribute on the navbar toggler button?
In Bootstrap navbars, the toggler button often has an attribute like aria-controls="navbarSupportedContent". Why is this attribute important for accessibility?
AIt tells assistive technologies which element the button controls, helping users understand what will be shown or hidden when toggled.
BIt links the button to the CSS styles of the navbar content.
CIt styles the toggler button with a special icon automatically.
DIt makes the toggler button visible only on small screens.
Attempts:
2 left
💡 Hint
Think about how screen readers announce controls and their relationships.

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