HTML accessibility basics: alt text, labels, keyboard and ARIA
Make pages usable for everyone: text alternatives, labels, keyboard access, skip links, contrast and a careful touch of ARIA.
In this lesson you will
- Write good alt text and link text
- Make pages keyboard friendly
- Use ARIA correctly and sparingly
- Test accessibility step by step
About 14 minutes
A website for everyone
Meet three visitors. Sana is blind and uses a screen reader that reads the page aloud. Omar broke his wrist and navigates only with the keyboard. Grandpa Yusuf has poor eyesight and turns the text size up to the maximum. Each of them wants to buy a cake. Whether they can depends on choices you make in your HTML, mostly small ones, mostly free. That practice has a name: accessibility, often shortened to a11y.
Roughly one person in six lives with some kind of disability, and almost everyone has a temporary limitation at some point: a bright screen outdoors, a noisy train, a hand full of shopping. Accessible pages are also better for search engines and easier for everyone. In many countries they are a legal requirement too.
Start with semantic HTML
You have already done half the work. Every semantic element from lesson 15 carries built-in accessibility. A real <button> can be reached with the Tab key and pressed with Space or Enter, while a <div> pretending to be a button does none of that unless you add a lot of code. The first rule is simple: use the right element for the job.
Text alternatives for images
You learned about alt in lesson 6. Here is the full picture.
- A meaningful image gets a short description of what it shows or what it does:
alt="Chocolate birthday cake with candles". - A purely decorative image gets an empty alt,
alt="", so screen readers skip it. - An image that is a link or button describes the destination or action:
alt="Go to the shop". - A complex chart needs a longer explanation in the nearby text.
Never start with “image of” or “picture of”. Screen readers already announce that it is an image. Also never leave alt out entirely, because then some readers speak the file name aloud.
Labels and instructions
From the forms lessons: every control needs a connected label, and the rules must be written down where people can read them. Group radio buttons in a fieldset with a legend. Mark required fields in text, not only with a red star or colour.
Links that make sense out of context
Screen reader users often pull up a list of all the links on a page. A list reading “click here, click here, read more, read more” is useless. Make link text meaningful on its own.
<!-- Weak -->
<p>To see our menu, <a href="menu.html">click here</a>.</p>
<!-- Better -->
<p>Browse <a href="menu.html">our full menu</a>.</p>
Keyboard access
Press the Tab key on any page. A visible outline should hop from link to button to field in a logical order. This is how Omar, and many screen reader and switch-device users, move around. Two rules protect them.
- Never remove the focus outline with
outline: noneunless you replace it with something just as clear. - Keep the order natural. The Tab order follows the order in your HTML. Avoid positive
tabindexvalues such astabindex="5". Usetabindex="0"to make a custom control reachable, andtabindex="-1"to move focus to something with code.
This clickable div cannot be reached with the keyboard. Replace it with a real button element, keeping the text.
<div class="btn" onclick="alert('Ordered!')">Order a cake</div>
Use .
<button type="button" onclick="alert('Ordered!')">Order a cake</button>
A skip link
Imagine tabbing through twenty menu links on every page before reaching the content. A skip link, placed first in the body, lets keyboard users jump straight to the main area.
<body>
<a class="skip" href="#content">Skip to main content</a>
<header>...</header>
<main id="content">...</main>
</body>
A common design hides the link until it receives keyboard focus, then shows it at the top of the page.
A little ARIA, carefully
ARIA attributes add extra information for assistive technology when plain HTML cannot express something. You have already met aria-label. A few more are worth knowing.
aria-labelnames an element that has no visible text, such as an icon-only button:<button aria-label="Close">X</button>.aria-current="page"marks the link to the page the visitor is on.aria-expanded="true|false"tells whether a menu or accordion is open.aria-hidden="true"hides a decorative element, such as an icon, from screen readers.
The first rule of ARIA: if a native HTML element can do the job, use it, and do not reach for ARIA. Wrong ARIA is worse than none.
Colour, contrast and size
- Text needs enough contrast against its background. The common target is a ratio of at least 4.5 to 1 for normal text. Free checkers let you test two colours.
- Do not use colour alone to convey meaning. Add an icon or a word such as “Error:” next to the red.
- Let people zoom. Avoid sizes that stop text from growing, and never disable pinch zoom on phones.
- Declare the page language with
<html lang="en">so screen readers pronounce the words correctly.
How to test
- Put the mouse away and use only the Tab, Shift+Tab, Enter and Space keys. Can you do everything?
- Zoom the page to 200 percent. Does anything overlap or disappear?
- Turn on a screen reader such as NVDA on Windows or VoiceOver on a Mac and listen to one page for two minutes.
- Run an automated checker such as the Lighthouse accessibility audit built into Chrome. It finds about a third of problems, so human testing still matters.
Fix the three accessibility problems: add the empty alt to the decorative swirl, a proper alt to the cake photo, and a label connected to the input.
<img src="swirl.png">
<img src="cake.jpg">
<input type="email" id="mail" name="mail">
Decorative image: alt=””. Cake: describe it. Add a label with for=”mail”.
<img src="swirl.png" alt="">
<img src="cake.jpg" alt="Chocolate cake with strawberries">
<label for="mail">Email</label>
<input type="email" id="mail" name="mail">
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
What alt text should a purely decorative image have?
- The file name
- Empty alt,
alt="" - “image”
- No alt attribute at all
An empty alt tells screen readers to skip the decoration.
Why use a real button instead of a clickable div?
- Buttons are prettier
- Buttons work with the keyboard and assistive technology by default
- Divs cannot have text
- Buttons are faster
Native elements bring keyboard and screen reader support for free.
Which link text is best?
- Click here
- Read more
- Download the 2026 price list (PDF)
- Link
Meaningful link text makes sense even when read out of context.
What does a skip link do?
- Skips the page load
- Lets keyboard users jump past the menu to the content
- Skips an ad
- Plays the next video
It saves keyboard users from tabbing through every menu link.
What is the first rule of ARIA?
- Use as much ARIA as possible
- Use a native element if one exists
- Use aria-hidden everywhere
- Avoid labels
Native HTML is better supported than ARIA, so prefer it.
Summary
- Use the right native element first.
- Describe meaningful images and skip decorative ones.
- Test with the keyboard, zoom and a screen reader.
- Contrast, language and keyboard focus matter to everyone.
Questions
Is accessibility only for people with disabilities?
No. Captions help in noisy places, keyboard access helps power users, and clear contrast helps everyone in bright sunlight.
Do I need to know every ARIA attribute?
No. Learn a handful, use native HTML first, and look up the rest when you need it.
What contrast ratio should I aim for?
At least 4.5 to 1 for normal text and 3 to 1 for large text, according to the common WCAG guidelines.
