🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Fundamentals••By Komal Nakrani

Astro Accessibility Checklist: 18 Checks With Code

An Astro accessibility checklist with code: lang, landmarks, skip links, headings, alt text, focus styles, accessible islands, view transitions and testing.

#Astro#Astro Accessibility#WCAG#Semantic HTML#Testing

Astro accessibility starts from a good place: every page is server-rendered HTML, so content, headings and links exist before any JavaScript runs. What Astro can’t do for you is choose the right elements, write alt text, keep focus visible or make interactive islands usable by keyboard. This checklist covers those gaps in 18 checks, each with the Astro code that fixes it.

Work through it once per layout and component, not once per page. In an Astro project most accessibility lives in a handful of files: the base layout, the header, the footer and your interactive islands.

Key Takeaways

  • Set lang on <html>, use real landmarks (header, nav, main, footer) and add a skip link in the base layout.
  • Astro’s <Image /> component refuses to build without alt; use alt="" for decorative images.
  • Never remove focus outlines without a visible replacement, and test every island with the keyboard only.
  • <ClientRouter /> announces page changes and disables transition animations for reduced-motion users.
  • Combine the dev toolbar’s audit app with axe or Lighthouse in CI; automated tools catch only part of the problems.

Document and layout checks

These live in your base layout, so fixing them once fixes every page.

1. Set the page language

Screen readers pick pronunciation from the lang attribute. Set it on <html>, and on any passage in another language.

---
// src/layouts/Base.astro
interface Props {
  title: string;
  lang?: string;
}
const { title, lang = 'en' } = Astro.props;
---
<html lang={lang}>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{title}</title>
  </head>
  <body>
    <slot />
  </body>
</html>

If you use Astro’s i18n routing, pass Astro.currentLocale as the lang value so each locale renders the right attribute.

2. Give every page a unique title

The <title> is the first thing a screen reader announces after navigation. Make it describe the page, then the site: “Pricing | Example Studio”, not “Example Studio” on every page.

3. Don’t block zoom

Keep the viewport tag at width=device-width, initial-scale=1. Adding maximum-scale=1 or user-scalable=no stops low-vision visitors from zooming.

4. Use landmarks

Landmarks let assistive technology jump between regions. Use the elements rather than div with roles:

---
// src/layouts/Base.astro (body)
import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
---
<body>
  <a class="skip-link" href="#main">Skip to content</a>
  <Header />
  <main id="main" tabindex="-1">
    <slot />
  </main>
  <Footer />
</body>

One <main> per page. If you have more than one <nav>, label each: <nav aria-label="Primary"> and <nav aria-label="Footer">. The semantic HTML guide goes deeper on choosing elements in Astro components.

The skip link above is the first focusable element on the page. Hide it until it receives focus, rather than hiding it with display: none, which removes it entirely:

/* src/styles/global.css */
.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
  padding: 0.5rem 1rem;
  background: #111;
  color: #fff;
  z-index: 100;
}
.skip-link:focus {
  top: 1rem;
}

The tabindex="-1" on <main> lets browsers move focus there when the link is followed.

Content checks

6. Keep one H1 and a logical heading order

Each page gets one <h1>, then <h2> and <h3> in order without skipping levels for visual size. In Markdown and MDX content, start sections at ## when the layout already renders the title as the H1. Style headings with classes, not by picking a smaller heading level.

7. Write alt text for every meaningful image

Astro enforces this for its image components. Leave out alt on <Image /> or <Picture /> and the build stops with the error “Image missing required “alt” property.” The hint tells you what to do for decorative images:

---
// src/components/Hero.astro
import { Image } from 'astro:assets';
import team from '../assets/team.jpg';
import divider from '../assets/divider.png';
---
<Image src={team} alt="Five people around a whiteboard planning a website" />
<Image src={divider} alt="" />

Plain <img> tags and Markdown images aren’t checked, so review those yourself. The missing alt fix covers the error in detail.

Screen reader users often list all links on a page. “Read more” ten times tells them nothing. Write “Read the pricing guide”, or keep a short visible label and add context that stays in the accessible name:

<a href={`/blog/${post.id}/`}>
  Read more<span class="sr-only"> about {post.data.title}</span>
</a>

The .sr-only class visually hides text while keeping it readable to assistive technology. Tailwind CSS ships it; in plain CSS, use the standard clip pattern.

9. Mark the current page in navigation

Use Astro.url.pathname to set aria-current="page" on the active link. It’s announced by screen readers, and you can style it too:

---
// src/components/Nav.astro
const links = [
  { href: '/', label: 'Home' },
  { href: '/work/', label: 'Work' },
  { href: '/contact/', label: 'Contact' },
];
const path = Astro.url.pathname;
---
<nav aria-label="Primary">
  <ul>
    {links.map(({ href, label }) => (
      <li>
        <a href={href} aria-current={path === href ? 'page' : undefined}>{label}</a>
      </li>
    ))}
  </ul>
</nav>

When the value is undefined, Astro omits the attribute entirely.

10. Caption video and transcribe audio

Every <video> with speech needs a captions <track>. The dev toolbar flags media without captions under its a11y-media-has-caption rule.

Visual checks

11. Meet color contrast

WCAG AA asks for a 4.5:1 contrast ratio for body text and 3:1 for large text and UI components. Check your design tokens once, in the file where they’re defined, rather than component by component. If your colors live in CSS variables, the styling docs show where theme tokens sit in a Komal project.

12. Keep focus visible

Removing outlines with outline: none is the most common accessibility regression in custom designs. Replace it instead:

/* src/styles/global.css */
:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

:focus-visible shows the ring for keyboard users without showing it on every mouse click.

13. Respect reduced motion

Wrap your own animations in a media query so they run only for visitors who haven’t asked for less motion:

@media (prefers-reduced-motion: no-preference) {
  .card {
    transition: transform 200ms ease;
  }
  .card:hover {
    transform: translateY(-4px);
  }
}

14. Don’t rely on color alone

Error states, required fields and chart series need a second signal: text, an icon with a label, or a pattern. Red borders alone fail for color-blind visitors.

Interactive island checks

Islands are where Astro accessibility usually breaks, because that’s where custom widgets live.

15. Use native elements before ARIA

A <button> is focusable, activates with Enter and Space, and announces itself as a button. A <div onclick> does none of that. Reach for <button>, <a>, <details>, <dialog> and form elements first. Add ARIA only when no element fits, and test it. The modal dialog component builds on native <dialog> for this reason.

16. Make toggles state their state

A menu button should say whether the menu is open:

---
// src/components/MenuToggle.astro
---
<button type="button" aria-expanded="false" aria-controls="site-menu" data-menu-toggle>
  Menu
</button>
<ul id="site-menu" hidden>
  <li><a href="/work/">Work</a></li>
  <li><a href="/contact/">Contact</a></li>
</ul>

<script>
  const button = document.querySelector<HTMLButtonElement>('[data-menu-toggle]');
  const menu = document.getElementById('site-menu');
  button?.addEventListener('click', () => {
    const open = button.getAttribute('aria-expanded') === 'true';
    button.setAttribute('aria-expanded', String(!open));
    if (menu) menu.hidden = open;
  });
</script>

For a full menu, also close it on Escape and return focus to the button. The mobile nav component shows the complete pattern.

17. Label every form field

Every input needs a <label> tied to it with for and id, or wrapping it. Placeholders disappear when the visitor types, so they aren’t labels. Show errors as text next to the field and connect them with aria-describedby.

18. Check view transitions

If you use <ClientRouter />, Astro handles two things for you. It announces the new page title through a live region after each navigation, and it disables all transition animations, including the fallback animation, when the visitor’s device has reduced motion enabled. What you still own is focus: after a client-side navigation, make sure keyboard users don’t land somewhere unexpected, and test persistent elements marked with transition:persist. The view transitions guide covers the router in detail.

Testing your Astro site for accessibility

Automated tools find missing attributes and contrast problems quickly. They can’t tell you whether alt text is accurate or a widget is usable, so combine three layers:

Layer Tool What it catches
While coding Astro dev toolbar audit app Missing alt, invalid ARIA, positive tabindex, missing captions
Before merge axe-core with Playwright, Pa11y or Lighthouse in CI Contrast, landmarks, labels, duplicate IDs across built pages
Before launch Keyboard only, then a screen reader (VoiceOver, NVDA) Focus order, traps, confusing announcements

The audit app in the Astro dev toolbar runs in astro dev and highlights problems on the page you’re viewing. For CI, run checks against astro preview so you test the built HTML that ships. A minimal Playwright test with axe looks like this:

// tests/a11y.spec.ts
import { test, expect } from '@playwright/test';
import AxeBuilder from '@axe-core/playwright';

const pages = ['/', '/work/', '/contact/'];

for (const path of pages) {
  test(`no detectable a11y violations on ${path}`, async ({ page }) => {
    await page.goto(path);
    const results = await new AxeBuilder({ page }).analyze();
    expect(results.violations).toEqual([]);
  });
}

Point Playwright’s webServer at npm run preview and the test runs against production output. The testing tools roundup covers setup. For the full criteria, the W3C WCAG 2.2 quick reference is the source to check against.

If you start from one of the Astro themes here, run this checklist after you add your own colors, images and copy. A theme’s structure gives you landmarks and headings, but contrast and alt text depend on the content you put in.

FAQ

Is Astro good for accessibility?

Yes, as a starting point. Astro renders complete HTML on the server and ships no JavaScript by default, so content works with assistive technology before any script loads. Accessibility still depends on the elements, labels, contrast and alt text you write, so you need to check those yourself.

Does Astro check accessibility automatically?

Partly. The <Image /> and <Picture /> components fail the build without an alt property, and the dev toolbar’s audit app flags common ARIA and markup problems while you run astro dev. Neither replaces testing with axe, Lighthouse, a keyboard and a screen reader.

Put an <a href="#main">Skip to content</a> as the first element inside <body> in your base layout, give <main> the matching id and tabindex="-1", and hide the link off-screen until it receives focus with a :focus style.

Are Astro view transitions accessible?

The built-in <ClientRouter /> announces the new page title to screen readers after each navigation and turns off transition animations when the visitor has reduced motion enabled. Test focus behaviour and any persisted elements yourself.

How do I make React islands accessible in Astro?

The same way you would in any React app: use native interactive elements, keep ARIA state attributes such as aria-expanded in sync, manage focus when content opens or closes, and test with the keyboard. The island is server-rendered first, so make sure the static HTML is usable before hydration too.