Accessibility fundamentals
Audit a page for keyboard, contrast and screen-reader problems and fix them.
By Invicly Tech, , in Frontend with React & Next.js. About 9 minutes to read.
In short
Accessibility means people using keyboards, screen readers or low vision can use your site. Most problems are found with a keyboard test, a contrast check and an automated audit, then fixed in the markup.
Explained simply
Accessibility (often written a11y, with 11 letters between a and y) means people can use your site whatever their abilities. That includes blind users with screen readers, people who cannot use a mouse, people with low vision or color blindness, and anyone in bright sunlight with a cracked phone.
About one in six people has a disability. Many countries also have laws requiring accessible websites. And the fixes usually help everyone: captions help in noisy places, good contrast helps on dim screens, and keyboard support helps power users.
The good news is that most problems come from a short list: missing text for images, missing form labels, low contrast, things you cannot reach with the keyboard and no visible focus. Learning to spot these five catches the majority of real issues.
Automated tools like axe and Lighthouse find maybe a third of problems quickly. The rest you find by using the page yourself: unplug the mouse and press Tab, zoom to 200%, and try a screen reader for five minutes. It is the fastest way to build empathy and skill.
Press Play on a diagram to walk through it one step at a time.
- 1Keyboard test
Tab through everything; focus must be visible and logical
- 2Automated audit
Run axe or Lighthouse to catch common issues
- 3Fix markup
Add labels, alt text, contrast and semantic elements
- 4Screen reader check
Listen to key flows with VoiceOver or NVDA
- Back to step 1
- Page code to Browser: Renders button Menu, aria-expanded="false"1Renders button Menu, aria-expanded="false"
- User to Screen reader: Presses Tab2Presses Tab
- Browser to Screen reader: Focused: role button, name Menu, collapsed3Focused: role button, name Menu, collapsed
- Screen reader to User: Says "Menu, button, collapsed"4Says "Menu, button, collapsed"
- User to Browser: Presses Enter (click event)5Presses Enter (click event)
- Browser to Page code: Runs the click handler6Runs the click handler
- Page code to Browser: Sets aria-expanded="true"7Sets aria-expanded="true"
- Browser to Screen reader: State changed: expanded8State changed: expanded
- Keyboard
- Tab through everything
- Focus always visible
- No keyboard traps
- Eyes
- Contrast 4.5:1 for text
- Zoom to 200%
- Meaning not by color alone
- Screen reader
- Headings list makes sense
- Buttons and links have names
- Images have useful alt
- Automated
- axe DevTools
- Lighthouse accessibility score
In depth
The four principles: POUR
The WCAG guidelines are grouped under four ideas. Perceivable: people can sense the content, so images have text alternatives and videos have captions. Operable: people can use it, with a keyboard, without time pressure, without flashing content. Understandable: text is clear, forms explain errors, and the page behaves predictably. Robust: it works with many browsers and assistive tools, which mostly means valid, semantic HTML.
Each guideline has levels A, AA and AAA. Most laws and companies aim for level AA, which includes the contrast and keyboard rules in this topic.
- Perceivable: can I see or hear it?
- Operable: can I use it with my input device?
- Understandable: does it make sense?
- Robust: does it work with assistive tech?
- Perceivable
- Text alternatives for images
- Captions for video
- Operable
- Works with a keyboard
- No time pressure
- No flashing content
- Understandable
- Clear text
- Forms explain errors
- Predictable behavior
- Robust
- Valid, semantic HTML
- Works with assistive tools
Keyboard and focus
Keyboard users move with Tab and Shift+Tab, press Enter or Space to activate, and use arrow keys inside menus and radio groups. Native buttons, links and inputs are focusable automatically. A div is not.
Two rules matter most. First, never remove the focus outline without a replacement; use :focus-visible to show a clear ring for keyboard users without showing it on mouse clicks. Second, keep the tab order logical by keeping the HTML order logical. Avoid positive tabindex values; use tabindex="0" only to make a custom widget focusable, and tabindex="-1" for elements you focus with code, like a dialog heading.
ARIA: the first rule
ARIA attributes add roles, names and states to the accessibility tree. They are powerful, but the first rule of ARIA is: do not use ARIA if a native element does the job. ARIA changes only what is announced; it adds no keyboard behavior.
Good uses are small and specific: aria-label="Close" on an icon-only button, aria-expanded="true" on a button that opens a menu, aria-live="polite" on a region that shows status messages, and aria-describedby to link an input to its error text. Wrong ARIA is worse than none, because it tells assistive tech something untrue.
Contrast and color
WCAG AA requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (about 24px, or 19px bold) and for UI parts like input borders and focus rings. Light grey text on white often fails.
Never use color alone to carry meaning. A red border on an invalid field needs an icon or a message too, because about 1 in 12 men has some color vision deficiency. DevTools shows the contrast ratio when you hover a color in the Styles pane.
Learn it in 5 short steps
About 35m each. Track them with a timer in your plan.
- 1Navigate a page using only the keyboard~35m
- 2Check color contrast ratios~35m
- 3Add alt text and ARIA labels~35m
- 4Run an axe or Lighthouse audit~35m
- 5Fix the issues the audit finds~35m
Key points
- Every interactive element must be reachable and usable with the keyboard alone.
- Body text needs a contrast ratio of at least 4.5:1 for WCAG AA.
- Informative images need alt text; decorative images get an empty alt attribute.
- Prefer native HTML over ARIA; use ARIA only to fill real gaps.
- Automated tools catch only part of the issues, so test by hand too.
Key terms
Tap a card to flip it. 0/5 known
Examples
<img src="chart.png" alt="Sales grew 40% in March" />
<img src="divider.svg" alt="" />
<button aria-label="Close dialog">
<svg aria-hidden="true"><!-- X icon --></svg>
</button>
<style>
:focus-visible { outline: 3px solid #2563eb; }
</style>Meaningful alt text, a labelled icon button and visible focus.
Fixing an icon-only search button
A header has a magnifying-glass icon that opens search. It is a div with an SVG inside. Step 1: Tab through the page; focus skips it entirely. Step 2: change it to a button with type="button", which is focusable and responds to Enter and Space. Step 3: a screen reader now says just "button", because the icon has no text. Add aria-label="Search". Step 4: hide the decorative SVG from assistive tech with aria-hidden="true". Step 5: check it shows a clear focus ring.
<!-- Before -->
<div class="icon" onclick="openSearch()"><svg>...</svg></div>
<!-- After -->
<button type="button" class="icon" aria-label="Search" onclick="openSearch()">
<svg aria-hidden="true" focusable="false">...</svg>
</button>Accessible error messages
A sign-up form marks a bad email with a red border only. Step 1: add a visible message under the field. Step 2: connect the message to the input with aria-describedby so a screen reader reads it when the field gets focus. Step 3: set aria-invalid="true" so the field is announced as invalid. Step 4: on submit, move focus to the first invalid field so keyboard users land right on the problem.
<label for="email">Email</label>
<input id="email" type="email" aria-invalid="true" aria-describedby="email-err" />
<p id="email-err" class="error">Enter an email like name@example.com</p>Quick reference
- Text contrast: 4.5:1 normal, 3:1 large text and UI parts (WCAG AA)
- Decorative image: alt=""; meaningful image: describe its purpose
- Use :focus-visible for focus rings; never just outline: none
- First rule of ARIA: prefer a native element
- Icon-only button needs aria-label or visually hidden text
- Status messages: put them in an aria-live="polite" region
- Avoid tabindex values above 0
- Test with Tab, 200% zoom, a screen reader and axe
Common mistakes
- Removing focus outlines with outline: none and no replacement.
- Adding ARIA roles to divs instead of using native elements.
- Trusting a perfect Lighthouse score as proof the page is accessible.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Write alt text for: (a) a company logo in the header linking home, (b) a decorative wave divider, (c) a chart showing sales doubling in 2025.
- Exercise 2medium
Write CSS that shows a 3px blue focus ring for keyboard users on buttons and links, without showing it on mouse clicks.
- Exercise 3hard
Build a disclosure: a button "Show details" that toggles a hidden panel. It must announce its state to screen readers and work with the keyboard.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is a 100 Lighthouse accessibility score enough?
- No. Automated tools catch only some issues, such as missing alt text or low contrast. You still need keyboard and screen reader testing to find problems like confusing focus order.
- Which screen reader should I test with?
- Use what is built in: VoiceOver on macOS and iOS, Narrator on Windows, or TalkBack on Android. NVDA is a free and popular choice on Windows.
- Do I need to make my site meet AAA?
- Usually not. AA is the common target in laws and company policies. Some AAA criteria are impossible for certain content.