Bird
Raised Fist0
Bootsrapmarkup~10 mins

Why modals focus user attention in Bootsrap - Test Your Understanding

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

Complete the code to add the Bootstrap modal class to the div.

Bootsrap
<div class="modal [1]" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Afade
Bshow
Chidden
Dactive
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'show' class initially instead of 'fade'.
Confusing 'active' with modal visibility classes.
2fill in blank
medium

Complete the code to add the attribute that traps keyboard focus inside the modal.

Bootsrap
<div class="modal fade" tabindex="-1" role="dialog" [1]>
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <!-- modal content here -->
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Aaria-expanded="true"
Baria-hidden="true"
Caria-modal="true"
Daria-live="polite"
Attempts:
3 left
💡 Hint
Common Mistakes
Using aria-hidden which hides content from screen readers.
Confusing aria-expanded with modal focus behavior.
3fill in blank
hard

Fix the error in the button that closes the modal by completing the data attribute.

Bootsrap
<button type="button" class="btn-close" [1] aria-label="Close"></button>
Drag options to blanks, or click blank then click option'
Adata-bs-toggle="modal"
Bdata-dismiss="modal"
Cdata-toggle="modal"
Ddata-bs-dismiss="modal"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data-dismiss' which was used in Bootstrap 4.
Using 'data-toggle' which is for toggling modals, not dismissing.
4fill in blank
hard

Fill both blanks to create a button that opens the modal with id 'myModal'.

Bootsrap
<button type="button" class="btn btn-primary" [1]="#myModal" [2]="modal">
  Launch modal
</button>
Drag options to blanks, or click blank then click option'
Adata-bs-target
Bdata-target
Cdata-bs-toggle
Ddata-toggle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data-target' and 'data-toggle' which are Bootstrap 4 syntax.
Forgetting the '#' in the target value (not shown here because it's in quotes).
5fill in blank
hard

Fill all three blanks to create a modal div with id 'myModal', role 'dialog', and aria-labelledby 'modalTitle'.

Bootsrap
<div class="modal fade" id="[1]" tabindex="-1" role="[2]" aria-labelledby="[3]">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalTitle">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
AmyModal
Bdialog
CmodalTitle
Dalert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'alert' as role instead of 'dialog'.
Mismatching aria-labelledby id with the modal title's id.

Practice

(1/5)
1. Why do Bootstrap modals help focus user attention?
easy
A. They automatically refresh the page content
B. They block interaction with the rest of the page until closed
C. They change the page background color permanently
D. They disable the browser's back button

Solution

  1. Step 1: Understand modal behavior

    Bootstrap modals create a popup that covers the page and disables interaction outside it.
  2. Step 2: Identify how focus is controlled

    By blocking other page elements, modals force the user to focus on the modal content only.
  3. Final Answer:

    They block interaction with the rest of the page until closed -> Option B
  4. Quick Check:

    Modals block page interaction = They block interaction with the rest of the page until closed [OK]
Hint: Modals block page outside clicks to keep focus inside [OK]
Common Mistakes:
  • Thinking modals change page colors permanently
  • Believing modals refresh the whole page
  • Assuming modals disable browser buttons
2. Which Bootstrap modal attribute ensures keyboard focus stays inside the modal?
easy
A. data-bs-backdrop='static'
B. data-bs-focus='true'
C. data-bs-keyboard='false'
D. data-bs-scroll='true'

Solution

  1. Step 1: Review Bootstrap modal attributes

    Bootstrap uses data-bs-backdrop='static' to prevent closing the modal when clicking outside, which helps keep focus inside.
  2. Step 2: Match attribute to focus behavior

    data-bs-backdrop='static' ensures keyboard focus stays inside the modal while open by blocking outside clicks.
  3. Final Answer:

    data-bs-backdrop='static' -> Option A
  4. Quick Check:

    Focus trapping attribute = data-bs-backdrop='static' [OK]
Hint: Focus trapping uses data-bs-backdrop='static' in Bootstrap modals [OK]
Common Mistakes:
  • Confusing backdrop with focus control
  • Using keyboard='false' disables ESC key but not focus
  • Scroll attribute controls scrolling, not focus
3. What happens when a Bootstrap modal is opened regarding user focus?
medium
A. Focus moves to the browser address bar
B. Focus remains on the page background elements
C. Focus moves to the modal and keyboard navigation is trapped inside
D. Focus is lost and user cannot use keyboard

Solution

  1. Step 1: Understand modal opening behavior

    When a modal opens, Bootstrap automatically moves focus to the modal container.
  2. Step 2: Check keyboard navigation effect

    Keyboard navigation is trapped inside the modal to prevent interacting with background content.
  3. Final Answer:

    Focus moves to the modal and keyboard navigation is trapped inside -> Option C
  4. Quick Check:

    Modal traps focus inside = Focus moves to the modal and keyboard navigation is trapped inside [OK]
Hint: Modal open moves focus inside and traps keyboard navigation [OK]
Common Mistakes:
  • Thinking focus stays on background elements
  • Assuming focus moves to browser controls
  • Believing keyboard stops working
4. You notice users can tab outside a Bootstrap modal when it is open. What is the likely cause?
medium
A. Modal content is empty
B. Modal has data-bs-backdrop='false' set
C. Modal is missing the fade class
D. Modal has data-bs-focus='false' attribute on the modal

Solution

  1. Step 1: Identify focus trapping mechanism

    Bootstrap traps focus inside modals using the data-bs-focus='true' attribute (default).
  2. Step 2: Analyze cause of focus escape

    If users can tab outside, focus trapping is disabled (e.g., data-bs-focus='false').
  3. Final Answer:

    Modal has data-bs-focus='false' attribute on the modal -> Option D
  4. Quick Check:

    Focus trapping disabled = Modal has data-bs-focus='false' attribute on the modal [OK]
Hint: Check if data-bs-focus='true' is set to trap focus [OK]
Common Mistakes:
  • Confusing backdrop with focus trapping
  • Thinking fade class affects focus
  • Assuming empty content causes focus issues
5. You want to ensure a Bootstrap modal keeps user focus for an important form but also allows scrolling inside the modal if content is long. Which setup is best?
hard
A. Use no data attributes and rely on default modal behavior
B. Use data-bs-backdrop='false' and data-bs-keyboard='false'
C. Use data-bs-focus='false' and data-bs-scroll='false'
D. Use data-bs-focus='true' and data-bs-scroll='true' on the modal

Solution

  1. Step 1: Identify focus requirement

    Bootstrap modals keep user focus inside by default (data-bs-focus='true').
  2. Step 2: Enable scrolling inside modal

    Modal body scrolls by default if content overflows.
  3. Step 3: Combine for desired behavior

    Default settings ensure both focus trapping and scrollable content.
  4. Final Answer:

    Use no data attributes and rely on default modal behavior -> Option A
  5. Quick Check:

    Focus trapped + scroll enabled = Use no data attributes and rely on default modal behavior [OK]
Hint: Default Bootstrap modals trap focus and allow scrolling inside [OK]
Common Mistakes:
  • Confusing backdrop/keyboard with focus control
  • Setting focus='false' loses focus control
  • Using non-existent attributes like data-bs-scroll
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