How We Built an Accessible Website That Scored 100/100 on Lighthouse
|8 minutes min read
When aer studios launched its new brand this year, the website we'd created had to do more than just look good. We spend a lot of time talking to clients about accessibility and sustainability, so our own site needed to prove we meant it.
Thomas Moreton, Senior Full Stack Software Engineer, joined us in late June. His first project was working on the aer studios website. Working alongside Wayne, he helped build a site that launched with a 100/100 Lighthouse accessibility score and an A sustainability grade.
In this post, Thomas explains how the team switched motion off for people who need it to be, why semantic HTML mattered more than he expected, and how accessibility checks became part of building every component. Over to Thomas to tell all…
New beginnings and an unexpected first client
When I joined, I wasn't sure which client I'd be tasked to work with first. So, imagine my surprise when my first project turned out not to be client work, but working on the business itself. I got to help build the new aer studios website, a key part of our relaunch.
Building the site wasn't another run-of-the-mill tale of static site generation (SSG). We're a studio that's passionate about accessibility and sustainability, and we wanted to create an accessible website to show how much we care and to lead by example.
Two important goals, accomplished together
From the very first planning sessions, it was clear to me that two goals sat at the centre of the brief: sustainability and accessibility. With little experience in this area, I assumed they were two separate lists. It quickly became apparent that they're mostly the same one.
When I was first introduced to the concept of sustainability in software development, I naturally thought about data centres and where our infrastructure is hosted. It turns out developing a website sustainably isn't about following a checklist; it's a new mindset. In short, our goal was: how can we meet the requirements of the design whilst shipping minimal data to the client? The less data we send, the smaller our carbon footprint.
The same mentality led us down the path of accessibility too. The lighter a page, the faster it loads on older hardware or slow internet connections, which is the reality for a lot of potential visitors. Native HTML elements also weigh less than custom-built ones, and they come with keyboard support and screen reader semantics for free.
Right from the start of development, these goals shaped both technical and design decisions. Questions like 'How do we create interactive components like a parallax?' and 'How can we optimise our image delivery?' became both more important and more challenging.
We chose Astro as our framework because it builds pages as plain HTML, only adds JavaScript when a component needs it, and has image optimisation built in. Astro set us up with a solid foundation, but that was only the first step. Wayne has already written in detail about our CSS-first approach to components in A Journey Towards a More Sustainable Front End, so I won't repeat it here.
Accessible animation, but only for people who want it
The new aer studios website has its fair share of animation, particularly the parallaxes on the homepage and About us page. As a result, scroll-driven motion became a centrepiece of the site. The story of how these parallaxes were built has already been told, but I'd like to talk about who they're for. To most people, a smooth scrolling parallax looks great, but for anyone with a vestibular disorder it can cause dizziness or nausea.
We wanted our new website to be for everyone, so before we wrote any animation, we made sure it would only switch on when two things are true: the browser supports CSS scroll-driven animations, and the user hasn't asked their device to reduce motion.
@supports (animation-timeline: view()) {
@media (prefers-reduced-motion: no-preference) {
.stackedHero {
view-timeline-name: --basic-page-hero-scroll;
view-timeline-axis: block;
} .frame {
animation: scrollFadeIn linear both;
animation-timeline: --basic-page-hero-scroll;
animation-range: contain var(--bph-enter-from) contain var(--bph-enter-to);
}
}
}
Wrapping the animation in prefers-reduced-motion: no-preference, rather than adding it everywhere and trying to undo it afterwards with reduce, means the motion is never added for anyone who has asked for less. If a user has set their device to reduce motion, they'll simply see the frames stacked as normal content.
That approach carried over into code reviews. We held each other to account to make sure that every animation followed the same pattern, so nothing slipped through the cracks.
Browsers that don't support scroll-driven animations yet, get a small fallback script that reads the same custom properties as the CSS, so there's a single source of truth across our users' browsers. The same rule applies across the site: card hovers, button transitions, the testimonials, the media grid and, of course, the parallaxes all calm down when motion is reduced.
Telling the full story with semantic HTML
Earlier, I mentioned that native HTML elements come with keyboard support and screen reader semantics for free. On this project, I learned how much it matters to shake old habits of using lots of <div>s and seek out the right element for the job.
A <div> tells the browser nothing about what it contains, which leaves a screen reader without context. A <nav>, <button> or <h2> tells the browser exactly what it is, and that context is passed on to anyone using assistive technology. Using the correct semantic elements lets those users experience the page as it's intended.
Here's how we set up our breadcrumb component using semantic HTML. Visually, it's a short row of links. In the markup, it's a labelled navigation landmark containing an ordered list, with the current page clearly marked for screen readers:
<nav aria-label="Breadcrumb">
<ol>
<li><a href="/our-work">Our work</a></li>
<li><span aria-current="page">Dogs Trust</span></li>
</ol>
</nav>
As a result, a screen reader user hears that they're in the breadcrumb, how many steps it has and which page they're currently on: vital context, without a single line of JavaScript.
It's easy to default to a stack of <div> elements when working at speed, so we held each other to account in code reviews whenever the wrong semantic elements, or none at all, were used. If a pull request used <div> or <span> elements, the question we asked each other was: "Does an element already exist that describes what we need?" More often than not, it did. Having project-wide buy-in meant good semantics became a habit rather than a clean-up job at the end of the project.
Using semantic HTML correctly won't change how the site looks. It changes what it means, and that's what our users with assistive technology experience.
Accessibility testing as we build
Just like our proactive approach to sustainable development, we didn't want to wait until after launch to grade our accessibility. Instead, we built it into how every new component is added to the site.
Our components are developed in our Storybook component library with its accessibility add-on running, so issues like low contrast are flagged at the earliest point, while we're still building. On top of that, our component tests use axe accessibility tools to scan each component's rendered output and check there are no violations, allowing us to catch problems like missing labels:
it("has no accessibility violations", async () => {
await renderAstroComponent(QuotesBlock, { ...exampleQuotesBlockProps });
const results = await axe(document.body, componentAxeOptions);
expect(results).toHaveNoViolations();
});
Whenever a component is modified, any change that breaks accessibility is caught straight away, both in local test runs and in our pipeline.
Whilst an accessibility test suite can check that an image has alt text, it can't tell whether that alt text is useful. So alt text became part of our content process too. Image descriptions are managed in the CMS, which makes writing good ones part of how we publish, in the hands of the people who know each image best.
The grade
After months of planning, building and testing, we launched with an accessibility score of 100/100, measured with Google's Lighthouse accessibility audit. Alongside a sustainability grade of A across the site, it's a result we're super proud of. Automated checks can't tell you everything, but it's a strong sign that the care we put in along the way paid off.
Seeing what a team prioritises tells you a lot about its values. At aer studios, I found a team that thinks about keyboard users, people with reduced motion turned on, and screen reader users in the same way it thinks about someone on a fast laptop with the latest browser.
What's next?
Our pull requests already get automated reports on SEO, carbon and performance, but those reports don't cover accessibility yet.
Whilst our component tests catch a lot, they only test building blocks in isolation, with sample content, which paints a fragmented picture. Some accessibility issues can only be caught on a real page: for example, headings that skip a level once blocks are stacked together, text that loses contrast over a particular photo, or an image whose description came through from the CMS empty.
The good news is that the pipeline behind those pull request reports already builds the site, serves it, and runs Lighthouse on every page. At launch, we ran Lighthouse's accessibility audit by hand. That audit uses the same axe engine as our component tests, so adding it to the pipeline is a one-line change:
onlyCategories: ["seo", "performance", "accessibility"],
That small change would let us report an accessibility score for every page, in the same way we already do for carbon, and flag any pull request where a page drops below the 100 we launched with.
This approach won't replace testing with real people and real assistive technology, but it will help us get the basics right and hold each other to account before changes are shipped to production.
This is the mindset we're trying to take into our work at the studio: before asking how something should look, we should ask who might not be able to use it.
