Screen reader utilities help make websites easier to use for people who rely on screen readers. They hide or show content only to screen readers, improving accessibility.
Screen reader utilities in Bootsrap
Use the class .visually-hidden on any HTML element to hide it visually but keep it accessible to screen readers. Example: <span class="visually-hidden">Hidden text for screen readers</span>
.sr-only class in Bootstrap 5 and later..visually-hidden are not visible but still read by screen readers.<span class="visually-hidden">This text is only for screen readers</span>
<button>Submit <span class="visually-hidden">form</span></button>
<div class="visually-hidden">Extra instructions for screen reader users</div>
This page shows a button with extra text hidden visually but read by screen readers. The hidden text helps users who rely on screen readers understand the button's purpose better.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Screen Reader Utilities 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-5"> <h1>Welcome to Our Website</h1> <p> Click the button to submit your data. <span class="visually-hidden">This action will save your information securely.</span> </p> <button type="button" class="btn btn-primary"> Submit <span class="visually-hidden"> form</span> </button> </main> </body> </html>
Use .visually-hidden instead of display:none or visibility:hidden because those hide content from screen readers too.
Always test your site with a screen reader to ensure hidden content is announced as expected.
Screen reader utilities help make content accessible by hiding it visually but keeping it readable by screen readers.
Use the .visually-hidden class in Bootstrap to add hidden but accessible text.
This improves the experience for users who rely on assistive technologies.
Practice
.visually-hidden class?Solution
Step 1: Understand the role of
This class hides content from the screen but keeps it readable by screen readers..visually-hiddenStep 2: Compare with other options
Options A, B, and C describe visual or interaction changes, not accessibility hiding.Final Answer:
To hide content visually but keep it accessible to screen readers -> Option CQuick Check:
Screen reader utility = hide visually, read by screen readers [OK]
- Confusing visual hiding with disabling interaction
- Thinking it changes text style instead of visibility
- Assuming it hides content from screen readers
Solution
Step 1: Identify Bootstrap's current screen reader class
Bootstrap 5 uses.visually-hiddento hide content visually but keep it accessible.Step 2: Check other options
.hiddenhides content completely including from screen readers;.sr-onlywas used in older versions;hiddenattribute hides from all users including screen readers.Final Answer:
<p class="visually-hidden">Hidden text</p> -> Option DQuick Check:
Bootstrap 5 uses .visually-hidden [OK]
- Using outdated .sr-only class
- Using HTML hidden attribute which hides from screen readers
- Using non-Bootstrap classes like .hidden
<button>Submit<span class="visually-hidden"> form</span></button>
Solution
Step 1: Understand the role of
The.visually-hidden.visually-hiddentext is invisible but still read by screen readers.Step 2: Combine visible and hidden text for screen reader output
The button text is "Submit" plus hidden " form", so screen readers read "Submit form".Final Answer:
Submit form -> Option AQuick Check:
Hidden text is read aloud with visible text [OK]
- Thinking hidden text is not read aloud
- Ignoring visually hidden span inside button
- Assuming only visible text is announced
<span class="sr-only">Hidden info</span>
Solution
Step 1: Check Bootstrap version and class usage
Bootstrap 5 replaced.sr-onlywith.visually-hidden.Step 2: Understand impact of using deprecated class
Using.sr-onlymay not apply correct styles, so text might not be hidden visually.Final Answer:
The classsr-onlyis deprecated in Bootstrap 5 -> Option BQuick Check:
Use .visually-hidden, not .sr-only [OK]
- Using outdated .sr-only class
- Assuming span can't have classes
- Confusing class names for screen reader utilities
Solution
Step 1: Understand screen reader utility requirements
The text must be hidden visually but still accessible to screen readers without affecting layout.Step 2: Evaluate each option's effect
Add a<span class="visually-hidden">with the extra text inside the button uses.visually-hidden, which hides visually but keeps text accessible. Add a<div hidden>with the text inside the button useshiddenattribute which hides from screen readers. Add a<span style="display:none">with the text inside the button uses CSSdisplay:nonewhich also hides from screen readers. Add a<span>with the text and set font-size to 0 hides text visually but may cause layout issues or be unreliable.Final Answer:
Add a <span class="visually-hidden"> with the extra text inside the button -> Option AQuick Check:
Use .visually-hidden for accessible hidden text [OK]
- Using hidden attribute which hides from screen readers
- Using display:none which removes from accessibility tree
- Hiding text by font-size 0 causing layout issues
Ready to prove it?
Pass the test and this pattern moves unknown
