Discover how a simple class can make your site friendly for everyone, even if they can't see the screen!
Why Screen reader utilities in Bootsrap? - Purpose & Use Cases
Imagine you have a website with important information hidden visually but needed by people using screen readers, like descriptions or instructions.
If you try to hide content by just using CSS like display:none or visibility:hidden, screen readers also ignore it, so the information is lost for users who rely on them.
Screen reader utilities in Bootstrap let you hide content visually but keep it accessible to screen readers, ensuring everyone gets the important info without cluttering the page.
<span style="display:none;">Hidden info here</span><span class="sr-only">Hidden info here</span>
This lets you improve accessibility easily, making your site usable for people who depend on screen readers without changing the visual design.
For example, adding extra context to buttons like 'Submit form' that only screen readers announce, helping users understand the button's purpose better.
Manually hiding content can block screen readers too.
Bootstrap's screen reader utilities hide visually but keep content accessible.
This improves website accessibility without affecting design.
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
