Shopify Liquid fix

Before and after

Broken — before
{%- comment -%} sections/collapsible-content.liquid (Broken: empty Liquid boolean & wrong ID) {%- endcomment -%}
<button
  type="button"
  aria-expanded="{{ block.settings.open_by_default }}"
  aria-controls="AccordionContent-{{ block.id }}"
>
  {{ block.settings.heading | escape }}
</button>
<div id="Accordion-{{ block.id }}">
  {{ block.settings.row_content }}
</div>
Fixed — after
{%- comment -%} sections/collapsible-content.liquid (Fixed: guaranteed true/false & matching IDREF) {%- endcomment -%}
{%- assign is_open = block.settings.open_by_default | default: false -%}
<button
  type="button"
  aria-expanded="{% if is_open %}true{% else %}false{% endif %}"
  aria-controls="AccordionContent-{{ section.id }}-{{ block.id }}"
>
  {{ block.settings.heading | escape }}
</button>
<div
  id="AccordionContent-{{ section.id }}-{{ block.id }}"
  {% unless is_open %}hidden{% endunless %}
>
  {{ block.settings.row_content }}
</div>
Live preview

Fixed vs. broken example

Passes aria-valid-attr-value
Accessibility tree: role="button", expanded=true, controls=#demo-shipping-panel (valid WAI-ARIA 1.2 state & live DOM IDREF)

Never interpolate unvalidated booleans, undefined IDs, or custom strings like 'open'/'closed' into ARIA attributes; only render aria-controls when the controlled ID exists in the DOM.

Automated test

Playwright + axe-core check

tests/a11y-aria-valid-attr-value.spec.ts
import { test, expect } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";

test("Shopify collapsible sections & drawers pass aria-valid-attr-value", async ({ page }) => {
  await page.goto("/products/cobalt-ceramic-mug");
  const results = await new AxeBuilder({ page })
    .withRules(["aria-valid-attr-value"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

A mismatched aria-controls='CartDrawer' vs id='cart-drawer' in sections/header.liquid or sections/collapsible-content.liquid creates a site-wide cluster across every storefront route. Fix the Liquid ID expression once to clear all URLs.

Screen readers

What NVDA and VoiceOver announce

Invalid ARIA tokens (like aria-expanded='open'), broken IDREFs (aria-controls pointing to a nonexistent or unmounted ID), or mistyped booleans cause browsers and screen readers to silently drop interactive state announcements.

NVDA (Windows)

Broken

"Shipping & Returns FAQ, button" (collapsed/expanded state omitted due to invalid token)


Fixed

"Shipping & Returns FAQ, button, expanded"

VoiceOver (macOS / iOS)

Broken

"Shipping & Returns FAQ, button" (state not exposed)


Fixed

"Shipping & Returns FAQ, expanded, button"

Common questions

Why does {{ block.settings.open_by_default }} sometimes output an empty aria-expanded=''?
If a theme schema setting hasn't been saved yet or was removed from settings_data.json, Liquid renders nil as an empty string. Always emit explicit 'true' or 'false' using an {% if %} branch.
Can Liquid whitespace inside aria-labelledby break axe-core?
Stray newlines are trimmed, but if a referenced heading block is conditionally skipped with {% if block.settings.heading != blank %}, the ID disappears and breaks aria-labelledby. Guard aria-labelledby with the exact same Liquid condition.
What causes aria-hidden='1' or aria-disabled='disabled' in older Shopify themes?
Legacy jQuery theme scripts often wrote HTML-style values instead of WAI-ARIA boolean strings ('true'/'false'). Replace them with strict 'true' or 'false' values.

Fix aria-valid-attr-value in other stacks

More Shopify Liquid guides