Sub topic 12
Make the hero usable for everyone
This chapter assumes you know basic HTML and CSS, and that you have already built the hero from the earlier chapters: one h1, a subheadline, a call-to-action link, and an image. Here you check that people using keyboards, screen readers, zoom, or low vision can use it as well as anyone else.
What accessibility means for a hero
Accessibility is the practice of building a page so people with different abilities and devices can use it. A hero is the first thing every visitor meets, so a failure here blocks the whole page. Most problems come from four areas: structure, text alternatives, color contrast, and keyboard use.
Use semantic structure
Semantic HTML means choosing elements for their meaning, not their looks. Screen readers use that meaning to let people jump around the page.
- Use one
h1for the offer. Do not pick a heading level for its size. Style it with CSS instead. - Use
afor the call to action when it goes to another page. Usebuttononly when it performs an action on the current page. - Label the section with
aria-labelledbypointing at theh1, so assistive technology announces the region by name.
The hero from the earlier chapters already does this:
<section class="hero" aria-labelledby="hero-title">
<div class="hero__text">
<h1 id="hero-title">Send invoices in under a minute</h1>
<p class="hero__sub">Ledgerly helps freelancers create, send and track invoices, so you get paid sooner.</p>
<a class="hero__cta" href="/signup">Start free trial</a>
<p class="hero__note">No credit card required</p>
</div>
<img class="hero__image" src="/img/invoice-editor.webp" width="640" height="400" fetchpriority="high" alt="Ledgerly invoice editor showing a draft invoice with a Send button">
</section>Write useful alt text
Alt text is a short written description of an image, read aloud by screen readers. Describe what the image shows and why it matters to the offer. Skip phrases like "image of". The alt text above names the product screen and the Send button, which supports the headline.
If an image is purely decoration, use an empty alt="" so screen readers skip it. Never leave the attribute out, because some readers then announce the file name.
Check color contrast
Contrast is the difference in brightness between text and its background. The Web Content Accessibility Guidelines (WCAG) level AA asks for a ratio of at least 4.5:1 for normal text and 3:1 for large text (about 24px, or 19px bold).
The button in the sample uses white text on #0b5fff. That pair clears 4.5:1. Check every pair you choose with a contrast checker, especially if the hero text sits over a photo. Text over a photo is the most common failure, because the background changes across the image. Put a solid or semi-opaque layer behind the text, or keep the text off the photo.
Keep keyboard focus visible
Many people move through a page with the Tab key. They need to see which element has focus. Browsers draw a default outline, and a common error is removing it with outline: none and adding nothing back.
.hero__cta:focus-visible {
outline: 3px solid #0b5fff;
outline-offset: 3px;
}:focus-visible shows the outline for keyboard users and usually hides it for mouse clicks. Because the button is itself blue, the outline uses an offset so it stays visible against the button.
Also check that the call to action is early in the tab order. With the HTML above, it is the first focusable item in the hero, matching its visual order.
Respect size and zoom
- Use
remunits for text so it grows with the user's browser font setting. - Do not disable zoom with
user-scalable=noin the viewport tag. - Make the button at least 44 by 44 pixels so it is easy to tap. The sample padding gives a comfortable target.
- At 200% zoom, text should still wrap without being cut off or hidden.
A quick manual test
Run these in order. Press Tab and confirm the focus outline is visible on the call to action. Turn on a screen reader and confirm it reads the h1, subheadline, link, and image description in a sensible order. Run a contrast checker on text and button colors. Zoom the browser to 200% and look for clipped text.
Common errors
| Error | Result | Fix |
|---|---|---|
| Removing the focus outline | Keyboard users lose their place | Style `:focus-visible` |
| Text over a busy photo | Low contrast in places | Add a solid layer behind text |
| Heading level chosen for size | Confusing page outline | One `h1`, style with CSS |
| Missing `alt` | File name is read aloud | Write a description or use `alt=""` |
Exercise
A teammate removes the outline from the hero button with outline: none because it looks messy after clicks. What should you recommend instead, and why?
Show answer
Keep a visible focus style and apply it with :focus-visible, for example a 3px outline with an offset. This hides the ring for most mouse clicks but still shows it to keyboard users, who need it to see where they are on the page.
Exercise
The hero headline is white text over a photo, and part of the photo is light. Which accessibility problem does this create, and name one fix.
Show answer
It creates a color contrast problem, because the text may fall below the 4.5:1 ratio over the light area. Fix it by placing a solid or semi-opaque dark layer behind the text, or by moving the text off the photo.