Lesson 8 of 52HTML
Accessibility Basics
Build pages that work with a keyboard, a screen reader and low vision, and learn how to test them in minutes.
Accessibility (often shortened to a11y, because there are 11 letters between the a and the y) means building pages that people can use whatever their abilities or circumstances. Someone who is blind uses a screen reader that reads the page aloud. Someone with a tremor uses only the keyboard. Someone with low vision zooms to 200 percent. And someone with perfect eyesight is squinting at a phone in bright sunlight with one hand full of shopping. The good news: most of the work is choosing the right HTML elements, which you have already been learning. This lesson ties it together and shows you how to test.
Who benefits
Accessibility is not a niche feature for a few users. The World Health Organization estimates that about 1 in 6 people worldwide live with a significant disability, and many more have temporary or situational limits:
| Permanent | Temporary | Situational |
|---|---|---|
| Blind, uses a screen reader | Eye surgery recovery | Phone screen in bright sun |
| One arm | Broken wrist | Holding a baby |
| Deaf | Ear infection | Noisy train, no headphones |
Captions, big click targets, clear contrast and keyboard support help all three columns. Many countries also have laws requiring accessible sites (the European Accessibility Act, the ADA in the United States), and the shared technical standard is WCAG, the Web Content Accessibility Guidelines. The current version is WCAG 2.2.
WCAG versions and levels in one minute
You will hear WCAG quoted in tickets, contracts and audit reports, so it helps to know how the numbers work.
- Versions. WCAG 2.0 (2008), 2.1 (2018) and 2.2 (October 2023, also published as the international standard ISO/IEC 40500:2025). Each version keeps almost everything from the one before and adds criteria, so a page that meets 2.2 also meets 2.1. The one exception: 2.2 removed the old 4.1.1 Parsing criterion.
- Levels. Every testable rule, called a success criterion, is level A (the bare minimum), AA, or AAA (the strictest). Meeting AA means meeting every A and AA criterion. AAA is not expected for whole sites.
- What to aim for. Most laws and contracts name WCAG 2.1 AA, including the European Accessibility Act's technical standard. Build to 2.2 AA, which covers 2.1 AA and adds a few criteria that real users need, such as minimum target sizes and focus that is not hidden behind sticky headers.
Criteria are referred to by number, such as 1.4.3 Contrast (Minimum) or 2.1.1 Keyboard. When a bug report says "fails 1.1.1", it means a missing or wrong text alternative. WCAG 3.0 exists only as an early draft with a different scoring model; do not treat it as a current requirement.
How assistive technology reads your page
A screen reader does not look at your pixels. The browser builds an accessibility tree from your HTML: a simplified version of the page where each item has a role (button, link, heading, textbox), a name (the text that identifies it) and a state (checked, expanded, disabled). The screen reader reads that tree aloud and lets the user jump between headings, links, form fields and landmarks.
You write button with the text Save.
This is why semantic HTML matters so much. The right element gives you the right role, name and keyboard behaviour for free.
Keyboard navigation and focus
Many people never touch a mouse. They press Tab to move to the next interactive element, Shift+Tab to go back, Enter to follow links and press buttons, Space for buttons and checkboxes, and arrow keys inside radio groups and menus. The element that will receive the key press has focus, and browsers draw a focus ring around it.
Three rules cover most of it:
- Use real
a,button,inputandselectelements. They are focusable and keyboard operable already. - Never remove the focus ring without replacing it.
outline: noneon everything is one of the most common accessibility bugs on the web. - Keep the tab order logical, which means keeping the source order logical. Avoid positive
tabindexvalues liketabindex="5".
Preview
Tab through the preview: the div is skipped completely, while the real button and the link each get a focus ring. Now add tabindex="0" to the div and tab again. It becomes focusable, but pressing Enter on it still does nothing, and a screen reader would not call it a button. Patching a div takes a role, a tabindex and keyboard handlers; using button takes nothing. Finally, change the outline colour in :focus-visible to something you like.
:focus-visible shows the ring when someone is using the keyboard but usually not after a mouse click, which is why designers no longer need to hide focus styles.
*:focus { outline: none; } because the rings look ugly. What is the best response?Text alternatives, labels and headings
You met these in earlier lessons. Here is why each one matters for access:
- Alt text. Every
imgneeds analt. Describe what the image means in context ("Bar chart: sales doubled in March"), not "image of chart". Purely decorative images get an emptyalt=""so screen readers skip them. - Labels. Every form field needs a label linked with
forandid. Without it, a screen reader announces "edit text, blank" and the user has to guess. - Link and button text. Screen reader users often pull up a list of all links. Ten links that say "Click here" are useless out of context. Write "Read the pricing guide" instead.
- Headings in order. Screen reader users jump from heading to heading to skim a page, like you skim with your eyes. Use one
h1, thenh2for sections,h3inside those, without skipping levels to get a smaller font. Size is a CSS job.
Landmarks
The semantic elements from the semantic HTML lesson double as landmarks: regions a screen reader user can jump to directly. header becomes banner, nav becomes navigation, main becomes main, footer becomes contentinfo, and aside becomes complementary. One main per page, and a nav for each major navigation block. A "Skip to main content" link at the very top of the page, pointing at #main, saves keyboard users from tabbing through the whole menu on every page.
Match each problem to the fix.
Colour and contrast
Text must stand out from its background. WCAG 2.2 at level AA asks for a contrast ratio of at least 4.5 to 1 for normal text and 3 to 1 for large text (about 24px, or about 18.7px if bold) and for interface parts like input borders and icons. Light grey placeholder-style text on white is the usual offender.
Also, never use colour alone to carry meaning. A red border on a broken field means nothing to someone with red-green colour blindness. Add an icon or a text message too.
Preview
Change #b0b0b0 to #767676 and the first card passes AA for normal text (that grey is close to the lightest passing value on white). The error line uses colour and the word "Error", so it still works in greyscale. To check any pair, open devtools, select the text, and click the colour swatch in the Styles panel: Chrome and Firefox show the contrast ratio right there.
ARIA: the last resort
ARIA (Accessible Rich Internet Applications) is a set of attributes like role, aria-label and aria-expanded that change what goes into the accessibility tree. It is powerful and easy to misuse. The first rule of ARIA from the W3C is: if a native HTML element already does what you need, use it instead of adding ARIA.
ARIA changes only what assistive technology is told. It adds no behaviour. role="button" on a div does not make it focusable or respond to Enter. Surveys of large numbers of home pages (such as WebAIM's yearly Million report) keep finding that pages using ARIA tend to have more detected errors, not fewer. Reach for it for things HTML cannot express, such as aria-expanded on a button that opens a menu, or aria-label on an icon-only button:
<button aria-label="Close dialog">
<svg aria-hidden="true" ...></svg>
</button>Testing in ten minutes
You do not need special skills to catch most problems:
- Unplug the mouse. Tab through the page. Can you reach and use everything? Can you always see where focus is?
- Zoom to 200 percent. Does anything overlap or get cut off?
- Run an automated check. Lighthouse is built into Chrome devtools (the Lighthouse tab, choose Accessibility). Firefox has an Accessibility panel. Tools like axe DevTools go further. Automated tools catch only part of the problems, so treat a perfect score as a start, not a finish.
- Listen with a screen reader. VoiceOver is built into macOS and iOS (Cmd+F5 on a Mac), Narrator into Windows, NVDA is free for Windows, and TalkBack ships with Android. Navigate by headings and by form fields and listen for anything that is unclear.
Put a quick accessibility check in a sensible order, from cheapest to most thorough.
- Tap the steps below in the right order.
Hiding things the right way
"Hidden" means three different things, and picking the wrong one is a common bug:
| You want it hidden from | Use | Example |
|---|---|---|
| Everyone | The hidden attribute or display: none | A closed panel, a tab that is not selected |
| Sighted users only | A visually hidden class (often called sr-only) | "Read more about pricing", where the extra words are for screen readers |
| Assistive technology only | aria-hidden="true" | A decorative icon next to a text label |
The visually hidden pattern keeps text in the accessibility tree while taking up no space on screen:
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
border: 0;
}Do not use display: none or visibility: hidden for it: both remove the text from the accessibility tree as well. And never put aria-hidden="true" on anything focusable, or on a wrapper around links and buttons: keyboard users can still tab to them, and a screen reader then lands on something with no name. To take a whole region out of use for everyone, such as the page behind an open modal, use the inert attribute. ARIA Widget Patterns and Keyboard Support and Focus Management cover both in depth.
Match each situation to the right way to hide.
Where next
This lesson is the foundation. The Accessibility in depth unit builds on it:
- WCAG 2.2: What the Standard Actually Asks walks through how the criteria are organised, the new 2.2 criteria with before-and-after fixes, the criteria audits fail most, and what the law actually requires.
- ARIA Widget Patterns: Tabs, Menus, Comboboxes and Live Regions covers how a control gets its name and how to build the widgets HTML does not give you.
- Keyboard Support and Focus Management goes deeper on tab order, moving focus after actions, modals and focus styles that pass everywhere.
- Testing with Screen Readers and Automated Tools turns the four quick checks above into a repeatable test script, with VoiceOver and NVDA quick starts and accessibility checks in CI.
Native dialogs and popovers handle much of the focus work for you, which Dialogs, Popovers and Anchored UI Without a Library shows. Accessible forms, including labels, errors and autocomplete, are covered in Forms.
- accessibility (a11y)
- Making pages usable by people with different abilities, devices and situations.
- screen reader
- Software that reads the page aloud and lets users navigate by headings, links and fields.
- accessibility tree
- The browser's simplified page model with a role, name and state for each item.
- focus
- The element that will receive keyboard input, normally shown with a focus ring.
- landmark
- A page region, like main or nav, that assistive tech users can jump to directly.
- contrast ratio
- How much text stands out from its background. WCAG AA asks for 4.5 to 1 for normal text.
- ARIA
- Attributes that adjust the accessibility tree. Use only when no native HTML element does the job.
- WCAG 2.2
- The current version of the Web Content Accessibility Guidelines (2023). Meeting 2.2 AA also meets 2.1 AA.
- success criterion
- One testable WCAG rule, numbered like 1.4.3, at level A, AA or AAA.
- visually hidden (sr-only)
- CSS that removes text from the screen but keeps it in the accessibility tree for screen readers.
- inert
- An HTML attribute that makes a region unfocusable, unclickable and hidden from assistive technology.