Accessibility in HTML
Accessibility in HTML: Build for Everyone
Accessibility is more than just good practice — it’s a commitment to making the web usable for everyone, including people with disabilities. Whether your users rely on a screen reader, keyboard, or high-contrast settings, HTML has the tools to support them.
1. alt Text for Images
The alt attribute provides a textual alternative for images. Screen readers use this to describe the image aloud.
<img src="apple.jpg" alt="Red apple on a wooden table">
[ Screen reader: "Red apple on a wooden table" ]
Best Practices:
- Use descriptive, meaningful alt text.
- Use
alt=""for decorative images. - Avoid phrases like “image of…” — screen readers already announce that.
2. Semantic HTML Tags
HTML5 introduced semantic tags that help assistive technologies understand the page structure without extra attributes.
<header>Welcome to Cherry Times</header>
<nav><a href="#news">News</a></nav>
<main>
<article>
<h2>Cherry Picking Season</h2>
<p>Learn how to pick the ripest cherries.</p>
</article>
</main>
<footer>Contact us: banana@fruitmail.com</footer>
[ Screen reader identifies clear landmarks: header, nav, main, footer ]
3. ARIA Roles (Accessible Rich Internet Applications)
Use ARIA only when semantic HTML doesn’t offer a clear alternative. Roles provide screen readers with the purpose of elements.
<div role="button" tabindex="0" onclick="sayHello()">
Say Hello 🍌
</div>
Explanation:
role="button"tells the screen reader this is a button.tabindex="0"makes the div focusable via keyboard.
But remember: prefer <button> over ARIA when possible — native elements are best!
5. Screen Reader Considerations
Screen readers process HTML in a linear flow — so it’s crucial to:
- Use proper heading hierarchy (
<h1>to<h6>) - Provide labels for inputs
- Include skip links for quick navigation
- Use
<label for="id">or wrap<input>in<label>
Example: Accessible Input
<label for="fruit">Favorite Fruit:</label>
<input type="text" id="fruit" name="fruit" placeholder="e.g. apple">
[ Screen reader reads: "Favorite Fruit: edit text" ]
Summary
Accessibility in HTML isn’t an afterthought — it’s an integral part of great design. Today you learned how to:
- Describe images with
alttext - Use semantic elements for clarity and structure
- Apply ARIA roles when needed
- Enable full keyboard navigation
- Design with screen readers in mind
Check your understanding 1
Check your understanding 2
Check your understanding 3
Choose the option that lists all and only the correct statements.
- Using semantic HTML elements like
<button>and<nav> - Setting tabindex to control focus order
- Disabling all keyboard events
- Providing visible focus indicators
Check your understanding 4
Check your understanding 5
Check your understanding 6
Choose the option that lists all and only the correct statements.
- Use semantic tags to give meaning to content
- Include descriptive alt text for images
- Avoid keyboard focus styles to keep UI clean
- Use ARIA roles and properties where necessary
What’s Next?
Coming up: We’ll go hands-on with building an accessible, semantic HTML layout that works seamlessly for keyboard users, screen readers, and everyone in between.
Reaching the recap and completing the quizzes are separate milestones.