📖 Scenario: You are building a simple webpage that includes important text for screen readers but hides it visually. This helps people who use screen readers get extra information without cluttering the page for others.
🎯 Goal: Create a webpage using Bootstrap's screen reader utility classes to hide text visually but keep it accessible to screen readers.
📋 What You'll Learn
Use Bootstrap 5 CSS from CDN
Create a heading visible to all users
Add a paragraph with text hidden visually but readable by screen readers using visually-hidden class
Add a paragraph with text visible normally
Ensure semantic HTML structure with main and section elements
💡 Why This Matters
🌍 Real World
Screen reader utilities help make websites accessible to people with visual impairments by providing hidden but readable content.
💼 Career
Accessibility is a key skill for web developers to ensure websites can be used by everyone, including those relying on assistive technologies.
Progress0 / 4 steps
1
Create the basic HTML structure with Bootstrap
Create a basic HTML5 page with lang="en" in the html tag. Add meta charset="UTF-8" and meta name="viewport" content="width=device-width, initial-scale=1" inside the head. Link Bootstrap 5 CSS from the official CDN inside the head. Add a main element inside the body.
Bootsrap
Hint
Remember to include the Bootstrap CSS link inside the head and set the language attribute on the html tag.
2
Add a visible heading and a visually hidden paragraph
Inside the main element, add an h1 heading with the text Welcome to Our Website. Below it, add a p paragraph with the text This text is only for screen readers and apply the Bootstrap class visually-hidden to it.
Bootsrap
Hint
Use the visually-hidden class on the paragraph to hide it visually but keep it accessible.
3
Add a visible paragraph with normal text
Below the visually hidden paragraph inside the main, add another p paragraph with the text This text is visible to everyone without any special classes.
Bootsrap
Hint
Just add a normal paragraph without any special classes.
4
Wrap visible content in a section and add aria-label
Inside the main, wrap the visible h1 and visible p inside a section element. Add an aria-label="Main content section" attribute to the section for accessibility.
Bootsrap
Hint
Use a section tag with the aria-label attribute to group visible content for screen readers.
Practice
(1/5)
1. What is the main purpose of Bootstrap's .visually-hidden class?
easy
A. To disable all user interactions on an element
B. To make text bold and larger for better visibility
C. To hide content visually but keep it accessible to screen readers
D. To change the background color of an element
Solution
Step 1: Understand the role of .visually-hidden
This class hides content from the screen but keeps it readable by screen readers.
Step 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 C
Hint: Think: hidden visually but still read aloud [OK]
Common Mistakes:
Confusing visual hiding with disabling interaction
Thinking it changes text style instead of visibility
Assuming it hides content from screen readers
2. Which of the following is the correct way to apply Bootstrap's screen reader utility to a paragraph?
easy
A.
Hidden text
B.
Hidden text
C.
Hidden text
D.
Hidden text
Solution
Step 1: Identify Bootstrap's current screen reader class
Bootstrap 5 uses .visually-hidden to hide content visually but keep it accessible.
Step 2: Check other options
.hidden hides content completely including from screen readers; .sr-only was used in older versions; hidden attribute hides from all users including screen readers.
Final Answer:
<p class="visually-hidden">Hidden text</p> -> Option D
Quick Check:
Bootstrap 5 uses .visually-hidden [OK]
Hint: Use .visually-hidden for Bootstrap 5 screen reader text [OK]
Common Mistakes:
Using outdated .sr-only class
Using HTML hidden attribute which hides from screen readers
Using non-Bootstrap classes like .hidden
3. What will a screen reader announce for the following HTML snippet?
The .visually-hidden text 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 A
Quick Check:
Hidden text is read aloud with visible text [OK]
Hint: Hidden text adds to screen reader output [OK]
Common Mistakes:
Thinking hidden text is not read aloud
Ignoring visually hidden span inside button
Assuming only visible text is announced
4. Identify the error in this code snippet intended to hide text visually but keep it accessible:
<span class="sr-only">Hidden info</span>
medium
A. The span tag cannot have classes
B. The class sr-only is deprecated in Bootstrap 5
C. The text will be visible to all users
D. The class should be screen-reader-only
Solution
Step 1: Check Bootstrap version and class usage
Bootstrap 5 replaced .sr-only with .visually-hidden.
Step 2: Understand impact of using deprecated class
Using .sr-only may not apply correct styles, so text might not be hidden visually.
Final Answer:
The class sr-only is deprecated in Bootstrap 5 -> Option B
Quick Check:
Use .visually-hidden, not .sr-only [OK]
Hint: Use .visually-hidden, not .sr-only in Bootstrap 5 [OK]
Common Mistakes:
Using outdated .sr-only class
Assuming span can't have classes
Confusing class names for screen reader utilities
5. You want to add extra descriptive text for screen readers only, inside a button, without affecting layout or visible design. Which is the best approach?
hard
A. Add a <span class="visually-hidden"> with the extra text inside the button
B. Add a <div hidden> with the text inside the button
C. Add a <span style="display:none"> with the text inside the button
D. Add a <span> with the text and set font-size to 0
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 uses hidden attribute which hides from screen readers. Add a <span style="display:none"> with the text inside the button uses CSS display:none which 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 A
Quick Check:
Use .visually-hidden for accessible hidden text [OK]
Hint: Use .visually-hidden to hide but keep accessible [OK]
Common Mistakes:
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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.