Sub topic 12
Make the hero usable for everyone
This chapter covers accessibility for the hero section: structure, text, color, focus, motion, and images. It assumes you know basic HTML and CSS, can read the hero markup from earlier chapters, and know what a call to action (CTA) is. Accessibility here means that people using keyboards, screen readers, zoom, high-contrast settings, or reduced-motion settings can read the offer and take the next step.
Why the hero needs its own accessibility pass
The hero is the first thing a visitor meets. If a screen reader user cannot tell what the page offers, or a keyboard user cannot reach the CTA, the offer has failed for that visitor. Hero problems are also common. Heroes often use large background images, light text on photos, custom-styled buttons, and animation, and each of these causes typical failures.
Most fixes cost little when made during the build. They are mostly correct HTML plus a few CSS rules.
Start with semantic structure
Screen readers expose headings, landmarks, links, and buttons as navigation points. A user can jump from heading to heading, or from landmark to landmark, so your markup is also their table of contents.
The hero from this tutorial uses these pieces:
- A
sectionwitharia-labelledbypointing at the headline. This gives the region an accessible name, so it is announced as a labelled region. - One
h1that states the offer. A page should have one main heading, and the hero headline is the right one. - A real link (
a) for the CTA, because it navigates to/signup. - A paragraph for the subheadline and the note, not extra headings.
<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>Do not pick heading levels for their size. If the subheadline looks like a heading, keep it a p and style it with CSS. A skipped or decorative heading adds noise to the heading list.
Link or button?
Use a link when the CTA goes to another page, as "Start free trial" does. Use a button when it performs an action on the current page, such as opening a dialog or submitting a form. Screen readers announce the role, and users expect Enter to activate both, but only a button also responds to Space. Do not build a CTA from a div with a click handler. It is not focusable, has no role, and ignores the keyboard.
Write useful alternative text
The alt attribute gives a text equivalent for an image. Decide what the image does on the page.
| Image role | Example | Alt text |
|---|---|---|
| Informative: shows the product or outcome | Screenshot of the invoice editor | A short description of what matters: "Ledgerly invoice editor showing a draft invoice with a Send button" |
| Decorative: adds mood only | Soft gradient or abstract shapes | Empty alt: `alt=""` |
| Contains text the visitor needs | A banner image with a slogan | The same text as in the image, or better, put the text in HTML |
Two rules apply. First, describe what the image communicates, not that it is an image. Screen readers already announce "image", so "Image of a screenshot" wastes words. Second, an empty alt="" is not the same as a missing alt. With a missing attribute, many screen readers read out the file name. With an empty one, they skip the image.
If the visual is a CSS background (background-image), it is invisible to assistive technology. That is fine for decoration. If the image carries meaning, use an img element instead.
Make the text readable
Contrast
Contrast is the difference in brightness between text and its background. The Web Content Accessibility Guidelines (WCAG) 2.2, level AA, require:
- At least 4.5:1 for normal text.
- At least 3:1 for large text, meaning roughly 24 px regular or 18.66 px bold and up.
- At least 3:1 for the visual boundary of interface components, such as a button's edge when it is the only thing that identifies it.
The CTA in the earlier CSS is white (#fff) on #0b5fff. That pair has a contrast ratio of about 5.6:1, so it passes for normal text. Check your own colors with a contrast checker rather than by eye, because a color that looks fine on your screen can fail.
Text over a photo is the usual hero trap. The contrast changes across the image, so one bright patch can make a word unreadable. Fixes, in order of preference:
- Keep text on a solid or near-solid panel, as in the two-column layout from this tutorial.
- If text must sit on an image, add a dark overlay and test the lightest part of the image behind the text.
- Avoid placing text over areas with busy detail.
Size and zoom
Use relative units (rem, ch, clamp()) so text follows the user's browser font setting. The hero CSS already does this. Never block zooming with user-scalable=no or a low maximum-scale in the viewport meta tag. WCAG asks that text can be resized to 200% without loss of content, and that content reflows at a 320 px wide viewport (equivalent to 400% zoom) without horizontal scrolling. The single-column mobile layout handles that reflow.
A useful test: set your browser zoom to 400% on a desktop and check that the headline, subheadline, and CTA are all still visible and usable.
Do not rely on color alone
If the CTA is the only blue element and the only cue is color, a color-blind user may miss it. The hero CTA has size, weight, padding, and position as well. Keep that redundancy. If you add an error or status message to a hero form, pair color with text or an icon.
Keyboard and focus
A keyboard user moves with Tab and activates with Enter or Space. Test this by putting your mouse aside and tabbing through the hero.
What you should see:
- Focus lands on the CTA in a logical order, after the text that introduces it.
- A visible focus indicator shows where focus is.
- Nothing traps focus.
The most common failure is outline: none with no replacement. Never remove the outline without providing another visible indicator. Use :focus-visible, which shows the ring for keyboard focus and generally not for mouse clicks.
.hero__cta:focus-visible {
outline: 3px solid #0b5fff;
outline-offset: 3px;
}This ring is blue against a light page. If the hero background is dark or blue, choose a ring color that has at least 3:1 contrast against the area next to it. A two-tone ring (a dark outline with a white offset gap) works on both light and dark backgrounds.
Keep source order matching visual order. If you use CSS Grid or order to move the image before the text on mobile, the Tab order and reading order still follow the HTML. A mismatch confuses keyboard and screen reader users. In the hero, the text comes first in the HTML and in the visual order, so there is no mismatch.
Target size
Touch and pointer targets should be large enough to hit. WCAG 2.2 sets a minimum of 24 by 24 CSS pixels (AA), and many design systems aim for 44 by 44. The CTA's padding of 0.875rem 1.5rem with a 1rem font gives a height of about 48 px, which is comfortable.
Respect motion and autoplay
Heroes often add a looping background video, a carousel, or an entrance animation. These can distract users with attention difficulties and cause nausea for users with vestibular disorders. Rules of thumb:
- Avoid auto-advancing carousels in the hero. They hide the offer, and users may not have time to read each slide. WCAG requires a way to pause, stop, or hide any movement that starts automatically and lasts more than five seconds.
- Do not autoplay video with sound.
- Honor the
prefers-reduced-motionsetting, which users set in their operating system.
.hero__image {
animation: hero-fade 600ms ease-out both;
}
@keyframes hero-fade {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
.hero__image {
animation: none;
}
}Note that a fade-in that delays the image also delays when it appears, which interacts with loading performance. Skipping the animation for reduced-motion users is both kinder and faster.
Add a skip link and respect the page around the hero
The hero usually sits just below the site header and navigation. A keyboard user must tab through every nav link before reaching the hero, on every page. A skip link is the first focusable element on the page, and it jumps to the main content.
<a class="skip-link" href="#main">Skip to main content</a>
<header>...</header>
<main id="main">
<section class="hero" aria-labelledby="hero-title">...</section>
</main>.skip-link {
position: absolute;
left: 0.5rem;
top: -4rem;
padding: 0.5rem 1rem;
background: #000;
color: #fff;
}
.skip-link:focus {
top: 0.5rem;
}The link is off-screen until it receives focus. Do not use display: none for it, because that removes it from the Tab order.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Headline built from an image | Not readable by screen readers, does not scale, and blurs when zoomed | Use real text in an `h1` |
| `outline: none` on the CTA | Keyboard users lose track of focus | Style `:focus-visible` |
| Light text over a photo | Fails contrast in places | Use a panel or overlay and test the worst area |
| `div` used as a button | Not focusable, no role | Use `a` or `button` |
| Several `h1` elements or heading levels chosen by size | Confusing outline | One `h1`, then levels by structure |
| Vague CTA such as "Click here" | Out of context in a links list, it says nothing | Label with the outcome, like "Start free trial" |
| Autoplaying carousel | Hides the offer, no pause control | Show one static offer |
The CTA label matters for accessibility too. Screen reader users often pull up a list of all links on the page, where "Learn more" appears with no context. An outcome label stays meaningful on its own.
Test the hero
Automated tools such as axe or Lighthouse catch roughly a third to half of accessibility issues, mainly missing alt text, contrast failures, and bad ARIA. They cannot judge whether alt text is useful. Combine them with manual checks:
- Tab through the page with the keyboard only. Confirm the order and the visible focus ring.
- Zoom to 200% and 400%. Confirm no clipped text or horizontal scrolling.
- Turn on a screen reader (VoiceOver, NVDA, or TalkBack) and listen to the hero. You should hear the region name, the h1, the paragraph, the link, and the image description, in that order.
- Enable "reduce motion" in your operating system and reload.
- Check contrast for every text and background pair, including hover and focus states.
Exercise
A teammate's hero has a white headline over a photograph, a CTA made from <div class="btn" onclick="signup()">Get started</div>, and a:focus { outline: none; } in the global CSS. List the three accessibility problems and give one fix for each.
Show answer
1) White text on a photo can fail the 4.5:1 contrast requirement where the image is bright. Fix: put the text on a solid panel or add a dark overlay, then check the lightest area behind the text. 2) The div CTA is not focusable, has no link or button role, and cannot be activated from the keyboard. Fix: use <a href="/signup">Get started</a> since it navigates, or a button if it performs an in-page action. 3) Removing the outline hides where keyboard focus is. Fix: delete the rule, or replace it with a visible :focus-visible style that has at least 3:1 contrast against its surroundings.
Exercise
Your hero has a decorative gradient img and a product screenshot img. What alt should each have, and why?
Show answer
The gradient gets alt="" so screen readers skip it. The screenshot gets a short description of what it shows, such as "Ledgerly invoice editor showing a draft invoice with a Send button", because it supports the offer and a non-sighted visitor would otherwise miss that information.
Exercise
You add a looping fade-and-slide animation to the hero image. Write the CSS rule that disables it for users who have asked their system to reduce motion.
Show answer
@media (prefers-reduced-motion: reduce) { .hero__image { animation: none; } }