November 9, 2025
How a seemingly minor HTML structure issue violated WCAG standards and what it taught me about accessibility in large codebases.
Accessibility bugs are the worst kind of bugs. They're invisible to sighted users, invisible to developers who don't use screen readers, and invisible to automated testing tools that only check for syntax, not semantics. They sit in production for months, silently breaking the experience for people who need it most.
That's exactly what was happening in the p5.js website.
Some <ul> and <ol> elements contained direct children that weren't <li>, <script>, or <template>. Instead, they were rendering <GridItem*> components directly inside the list without wrapping them in <li> elements.
Here's what the code looked like:
<ul class="content-grid-simple">
<GridItemSketch ... />
<GridItemSketch ... />
<GridItemSketch ... />
</ul>
Visually, this rendered fine. The grid layout worked, the components appeared correctly, and everything looked like a normal list. But under the hood, the HTML was invalid.
According to the HTML spec, <ul> and <ol> must only contain <li>, <script>, or <template> as direct children. Anything else is invalid HTML.
But validity isn't just about pedantic spec compliance. It's about what browsers and assistive technologies can infer from your markup.
When a screen reader encounters a <ul>, it announces "list" and tells the user how many items are in it. When it encounters <li> elements, it announces "list item" and reads the content.
But when a screen reader encounters a <ul> with non-<li> children, it gets confused. The list semantics break. The screen reader might not announce the list at all, or it might announce it incorrectly.
This violates WCAG 1.3.1: Info and Relationships, which requires that information and relationships conveyed through presentation are programmatically determined or available in text.
Different browsers handle invalid HTML differently. Chrome might render it one way, Firefox another, Safari a third. When your HTML is invalid, you're at the mercy of browser-specific behavior.
For a project like p5.js, which is used by hundreds of thousands of developers across every browser, this inconsistency is unacceptable.
I started by auditing the entire codebase for similar violations. The p5.js website is built with Astro, so I searched for all <ul> and <ol> elements and checked their children.
The violations were concentrated in two components:
src/components/RelatedItems/index.astro - Renders grids of related sketches, references, and examplessrc/layouts/SketchesLayout.astro - Renders grids of community sketchesBoth components used the same pattern: mapping over an array of items and rendering <GridItem*> components directly inside a <ul> without wrapping them in <li>.
The solution was straightforward: wrap each <GridItem*> in an <li> element. But I had to be careful about one thing: preserving the grid layout.
The <ul> had CSS classes like content-grid-simple that applied grid styling. If wrapping in <li> broke the grid, I'd be trading one problem for another.
Here's what the fixed code looks like:
<ul class="content-grid-simple">
{items.map((item) => (
<li>
<GridItemSketch ... />
</li>
))}
</ul>
The key insight: <li> elements inherit grid styling from their parent. Since the grid classes were on the <ul>, wrapping in <li> didn't change the layout at all. The visual output was identical.
I verified the fix in three ways:
Using Chrome DevTools, I confirmed that:
<ul> and <ol> elements now only have <li>, <script>, or <template> as direct children<GridItem*> components are properly nested inside <li> elementsUsing Chrome's Accessibility Inspector, I confirmed that:
I tested with VoiceOver (macOS) and NVDA (Windows) to confirm that:
After the PR was approved, the maintainer asked me to cherry-pick the fix from processing:2.0 into main. This is where things got interesting.
The commit was a merge commit, which means I had to use -m 1 to specify the mainline. But when I ran the cherry-pick, it produced an empty commit.
This meant the fix was already present in main. Someone had already applied the same fix to the main branch, but it hadn't been backported to 2.0. The cherry-pick was unnecessary.
I documented this in the PR, deleted the temporary branches, and moved on.
When HTML is invalid, browsers and assistive technologies can't be trusted to handle it consistently. What looks like a visual issue might actually be an accessibility issue, a performance issue, or a maintainability issue.
Lighthouse, axe, and other accessibility tools check for some violations, but they don't catch everything. Manual testing with screen readers is essential for catching semantic issues like this.
I was worried that wrapping in <li> would break the grid layout. It didn't. Modern CSS Grid is remarkably resilient to changes in the DOM structure, as long as the grid container and its children maintain the same relationship.
Merge commits, conflicting histories, and branch-specific changes can make cherry-picks tricky. Always verify that the fix isn't already present in the target branch before proceeding.
This fix affects:
It's a small change with outsized impact. That's the nature of accessibility work: small fixes that make a real difference in people's lives.
Links: