Bird
Raised Fist0
Bootsrapmarkup~20 mins

Nav tabs and pills in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Bootstrap Nav 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 nav tabs code?
Look at the following Bootstrap nav tabs code snippet. What will you see rendered in the browser?
Bootsrap
<ul class="nav nav-tabs" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
  </li>
</ul>
AA single button labeled 'Home' with no tabs or pills.
BTwo vertical pills labeled 'Home' and 'Profile' with 'Profile' pill highlighted as active.
CA dropdown menu with options 'Home' and 'Profile'.
DTwo horizontal tabs labeled 'Home' and 'Profile' with 'Home' tab highlighted as active.
Attempts:
2 left
💡 Hint
Remember that 'nav-tabs' class creates horizontal tabs and 'active' class highlights the selected tab.
❓ selector
intermediate
1:30remaining
Which CSS selector targets the active pill in Bootstrap nav pills?
Given Bootstrap nav pills, which CSS selector correctly styles the active pill?
A.nav-pills .nav-link.active
B.nav-tabs .nav-item.active
C.nav-pills .nav-item.selected
D.nav-tabs .nav-link.current
Attempts:
2 left
💡 Hint
Active pills use the 'active' class on the 'nav-link' element inside 'nav-pills'.
🧠 Conceptual
advanced
1:30remaining
What ARIA role should be used on the container of Bootstrap nav tabs for accessibility?
For better accessibility, which ARIA role attribute is recommended on the container element of Bootstrap nav tabs?
Arole="tablist"
Brole="navigation"
Crole="menu"
Drole="listbox"
Attempts:
2 left
💡 Hint
Tabs are a set of related tabs, so the container needs a role that groups them as tabs.
❓ layout
advanced
2:00remaining
How to make Bootstrap nav pills stack vertically on small screens?
You want Bootstrap nav pills to display horizontally on large screens but stack vertically on small screens. Which class combination achieves this?
AAdd 'd-block d-sm-flex' to the nav element
BAdd 'flex-row flex-sm-column' to the nav element
CAdd 'flex-column flex-md-row' to the nav element
DAdd 'flex-column flex-sm-row' to the nav element
Attempts:
2 left
💡 Hint
Use Bootstrap's responsive flex utility classes with the right breakpoint.
📝 Syntax
expert
2:30remaining
What error does this Bootstrap nav tabs code cause?
Examine this Bootstrap nav tabs snippet. What error or issue will it cause when rendered?
Bootsrap
<ul class="nav nav-tabs" role="tablist">
  <li class="nav-item" role="presentation">
    <a class="nav-link active" id="home-tab" data-bs-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
  </li>
  <li class="nav-item" role="presentation">
    <a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
  </li>
</ul>
<div class="tab-content">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">Home content</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">Profile content</div>
</div>
ATabs do not switch content because 'data-bs-toggle' should be 'data-toggle'.
BNo error; tabs work correctly with content switching.
CAccessibility issue: missing 'aria-selected' on active tab link.
DJavaScript error because 'href' attribute is missing on tab links.
Attempts:
2 left
💡 Hint
Bootstrap 5 uses 'data-bs-toggle' and 'href' for tab links to switch content.

Practice

(1/5)
1. What is the main difference between nav-tabs and nav-pills in Bootstrap navigation?
easy
A. nav-tabs requires JavaScript, nav-pills does not.
B. nav-tabs shows tabs with borders, nav-pills shows rounded pill-shaped links.
C. nav-tabs is for vertical menus, nav-pills is for horizontal menus only.
D. nav-tabs disables links, nav-pills enables links.

Solution

  1. Step 1: Understand Bootstrap navigation styles

    nav-tabs creates a tab-like navigation with rectangular borders around each item.
  2. Step 2: Compare with nav-pills

    nav-pills styles navigation links as rounded pills, giving a softer look.
  3. Final Answer:

    nav-tabs shows tabs with borders, nav-pills shows rounded pill-shaped links. -> Option B
  4. Quick Check:

    Tabs = rectangular, Pills = rounded [OK]
Hint: Tabs have edges, pills are rounded shapes [OK]
Common Mistakes:
  • Thinking nav-tabs are vertical only
  • Believing nav-pills don't need JS
  • Confusing disabled/enabled states
2. Which of the following is the correct Bootstrap class to create a pill-style navigation list?
easy
A. <ul class='nav-tabs'>
B. <ul class='nav nav-tabs-pills'>
C. <ul class='nav nav-pills'>
D. <ul class='nav pills'>

Solution

  1. Step 1: Recall Bootstrap classes for pills

    The correct class for pill navigation is nav-pills combined with nav.
  2. Step 2: Check each option

    <ul class='nav nav-pills'> uses nav nav-pills, which is correct. Others have incorrect or non-existent classes.
  3. Final Answer:

    <ul class='nav nav-pills'> -> Option C
  4. Quick Check:

    Use nav nav-pills for pills [OK]
Hint: Use both 'nav' and 'nav-pills' classes together [OK]
Common Mistakes:
  • Using only 'pills' without 'nav'
  • Combining 'nav-tabs' and 'pills' incorrectly
  • Misspelling class names
3. Given this Bootstrap nav tab code snippet, what will be the visual result in the browser?
<ul class='nav nav-tabs' role='tablist'>
  <li class='nav-item'>
    <a class='nav-link active' href='#home' role='tab' aria-selected='true'>Home</a>
  </li>
  <li class='nav-item'>
    <a class='nav-link' href='#profile' role='tab' aria-selected='false'>Profile</a>
  </li>
</ul>
medium
A. Two tabs labeled 'Home' and 'Profile', with 'Home' highlighted as active.
B. Two pill-shaped buttons labeled 'Home' and 'Profile', both inactive.
C. A vertical list of links with no active highlight.
D. Tabs labeled 'Home' and 'Profile' but both disabled.

Solution

  1. Step 1: Analyze the classes and attributes

    The nav-tabs class creates tab style navigation. The nav-link active class highlights the 'Home' tab as active.
  2. Step 2: Understand the visual effect

    'Home' tab will appear selected with a border, 'Profile' will appear as a normal tab link.
  3. Final Answer:

    Two tabs labeled 'Home' and 'Profile', with 'Home' highlighted as active. -> Option A
  4. Quick Check:

    Active tab is highlighted in nav-tabs [OK]
Hint: Active tab uses 'nav-link active' class [OK]
Common Mistakes:
  • Confusing pills with tabs visually
  • Assuming both tabs are active
  • Ignoring role and aria attributes
4. Identify the error in this Bootstrap nav pills code snippet:
<ul class='nav nav-pills'>
  <li class='nav-item'>
    <a class='nav-link active' data-toggle='tab' href='#home'>Home</a>
  </li>
  <li class='nav-item'>
    <a class='nav-link' data-toggle='tab' href='#profile'>Profile</a>
  </li>
</ul>
medium
A. The attribute data-toggle should be data-bs-toggle in Bootstrap 5+.
B. The class nav-pills is invalid and should be nav-tabs.
C. The href attributes must be full URLs, not fragment IDs.
D. The nav-item class should be on the a tags, not li.

Solution

  1. Step 1: Check Bootstrap version attribute changes

    Bootstrap 5 replaced data-toggle with data-bs-toggle for JavaScript plugins.
  2. Step 2: Verify other attributes and classes

    nav-pills is valid, href can use fragment IDs, and nav-item belongs on li.
  3. Final Answer:

    The attribute data-toggle should be data-bs-toggle in Bootstrap 5+. -> Option A
  4. Quick Check:

    Use 'data-bs-toggle' in Bootstrap 5+ [OK]
Hint: Bootstrap 5 uses 'data-bs-toggle' not 'data-toggle' [OK]
Common Mistakes:
  • Using old Bootstrap 4 attributes
  • Misplacing classes on wrong elements
  • Thinking href must be full URL
5. You want to create a responsive Bootstrap nav with pills that switch content panels on click. Which combination of classes and attributes is correct to ensure accessibility and proper tab switching?
hard
A. <ul class='nav nav-pills'> <li class='nav-item'> <a class='nav-link' href='#home' role='tab' aria-selected='false'>Home</a> </li> </ul>
B. <ul class='nav nav-tabs' role='navigation'> <li> <a class='nav-link' href='#home'>Home</a> </li> </ul>
C. <div class='nav nav-pills'> <a class='nav-link' data-toggle='tab' href='#home'>Home</a> </div>
D. <ul class='nav nav-pills' role='tablist'> <li class='nav-item'> <a class='nav-link active' id='home-tab' data-bs-toggle='pill' href='#home' role='tab' aria-controls='home' aria-selected='true'>Home</a> </li> </ul>

Solution

  1. Step 1: Identify correct classes and roles for pills navigation

    Use nav nav-pills on ul with role='tablist' for accessibility.
  2. Step 2: Check anchor attributes for tab switching and accessibility

    Anchors need id, data-bs-toggle='pill', href to panel, role='tab', aria-controls, and aria-selected.
  3. Step 3: Confirm active state on the selected tab

    The active tab has nav-link active and aria-selected='true'.
  4. Final Answer:

    <ul class='nav nav-pills' role='tablist'> <li class='nav-item'> <a class='nav-link active' id='home-tab' data-bs-toggle='pill' href='#home' role='tab' aria-controls='home' aria-selected='true'>Home</a> </li> </ul> -> Option D
  5. Quick Check:

    Use 'nav-pills' with proper roles and 'data-bs-toggle' [OK]
Hint: Use 'data-bs-toggle', roles, and aria attributes for tabs [OK]
Common Mistakes:
  • Omitting role or aria attributes
  • Using old 'data-toggle' instead of 'data-bs-toggle'
  • Missing active class on selected tab
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