ARIA attributes help make Bootstrap components usable by everyone, including people who use screen readers or keyboard navigation.
ARIA attributes in Bootstrap components
<element aria-attribute="value">...</element>aria- and provide extra information about elements.aria-pressed to indicate it is toggled on.<button class="btn btn-primary" aria-pressed="true">Toggle</button>
role="dialog" and aria-modal="true" to tell screen readers it is a popup window.<div class="modal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">...</div>
role="tablist", role="tab", and aria-selected to show which tab is active.<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" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button> </li> </ul>
aria-expanded and aria-controls to indicate if the content is shown or hidden.<button class="btn btn-link" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">Toggle</button>
This example shows a Bootstrap modal with ARIA attributes like aria-labelledby, aria-hidden, and aria-modal to help screen readers understand the modal's purpose and state.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap ARIA Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-4"> <h1>Accessible Modal Example</h1> <!-- Button to open modal --> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" aria-haspopup="dialog" aria-controls="exampleModal"> Open Modal </button> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="modalTitle" aria-hidden="true" role="dialog" aria-modal="true"> <div class="modal-dialog"> <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>This modal uses ARIA attributes to improve accessibility.</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button> </div> </div> </div> </div> </main> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Bootstrap automatically adds many ARIA attributes to its components to help accessibility.
You can add or customize ARIA attributes if you want to improve or fix accessibility for your specific use case.
Always test your site with keyboard navigation and screen readers to ensure ARIA attributes work as expected.
ARIA attributes make Bootstrap components accessible to all users.
They provide extra information about roles, states, and properties of UI elements.
Bootstrap includes many ARIA attributes by default, but you can add more if needed.
Practice
Solution
Step 1: Understand ARIA attributes
ARIA attributes provide extra information about UI elements to assistive technologies like screen readers.Step 2: Identify their role in Bootstrap
Bootstrap uses ARIA attributes to make components accessible, not for styling or performance.Final Answer:
To improve accessibility by describing roles and states to assistive technologies -> Option DQuick Check:
ARIA = Accessibility info [OK]
- Thinking ARIA changes visual styles
- Assuming ARIA improves page speed
- Confusing ARIA with animations
<button class='btn btn-primary' aria-controls='collapseExample' aria-expanded='false'>Toggle</button>Solution
Step 1: Identify ARIA attributes for collapsible controls
Buttons controlling collapsible areas usearia-controlsto reference the collapsible element andaria-expandedto indicate open/closed state.Step 2: Match attributes in the code snippet
The button usesaria-controls='collapseExample'andaria-expanded='false', which is correct for collapsible control.Final Answer:
aria-controls and aria-expanded -> Option AQuick Check:
Collapsible button uses aria-controls + aria-expanded [OK]
- Using aria-hidden which hides elements
- Confusing aria-pressed with aria-expanded
- Using aria-checked which is for checkboxes
<div class='alert alert-warning' role='alert' aria-live='assertive'>Warning message!</div>
Solution
Step 1: Understand role='alert'
Therole='alert'tells assistive technologies this is an important message that should be announced immediately.Step 2: Understand aria-live='assertive'
This attribute makes screen readers announce the content as soon as it appears, interrupting other speech if needed.Final Answer:
Screen readers will announce the warning message immediately and with high priority -> Option AQuick Check:
role alert + aria-live assertive = immediate announcement [OK]
- Thinking alerts are ignored by screen readers
- Assuming aria-live polite delays announcement
- Believing alerts require focus to be read
<button type='button' class='btn btn-primary' data-bs-toggle='modal' data-bs-target='#myModal' aria-expanded='true'>Open Modal</button>
Solution
Step 1: Check ARIA usage on modal trigger buttons
Modal trigger buttons should not usearia-expandedbecause modals are overlays, not expandable sections.Step 2: Verify other attributes
data-bs-toggle='modal'anddata-bs-target='#myModal'are correct. aria-label is optional if button text is descriptive. data-bs-target uses ID selector correctly.Final Answer:
aria-expanded should not be set on the modal trigger button -> Option CQuick Check:
Modal triggers do not use aria-expanded [OK]
- Adding aria-expanded to modal buttons
- Confusing modal toggle with dropdown toggle
- Using class selector instead of ID for data-bs-target
Solution
Step 1: Identify ARIA roles for tabs
Tab buttons should haverole='tab'to define their role in the tablist.Step 2: Use state attributes for tabs
aria-selectedindicates which tab is active, andaria-controlslinks the tab to its tab panel.Final Answer:
role='tab', aria-selected, and aria-controls -> Option BQuick Check:
Tabs need role tab + aria-selected + aria-controls [OK]
- Using aria-checked which is for checkboxes
- Confusing aria-pressed with aria-selected
- Adding aria-live which is for live regions
Ready to prove it?
Pass the test and this pattern moves unknown
