Shopify Liquid fix

Before and after

Broken — before
{%- comment -%} snippets/card-product.liquid (Broken: missing alt attribute) {%- endcomment -%}
<img
  src="{{ card_product.featured_media | image_url: width: 600 }}"
  width="600"
  height="600"
  loading="lazy"
  class="card__media-img"
>
Fixed — after
{%- comment -%} snippets/card-product.liquid (Fixed: explicit alt with safe Liquid fallback) {%- endcomment -%}
{%- assign image_alt = card_product.featured_media.alt | default: card_product.title | escape -%}
{{
  card_product.featured_media
  | image_url: width: 600
  | image_tag:
    alt: image_alt,
    loading: 'lazy',
    widths: '300, 450, 600',
    sizes: '(min-width: 990px) 25vw, 50vw',
    class: 'card__media-img'
}}
Live preview

Fixed vs. broken example

Passes image-alt
Accessibility tree: role="img", accessible name="Cobalt blue stoneware ceramic pour-over mug with matte handle"

Always provide meaningful alt text for informative photos and explicitly set alt="" (empty string) for purely decorative flourishes so screen readers skip them cleanly.

Automated test

Playwright + axe-core check

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

test("Shopify collection grid product images expose non-empty alt text", async ({ page }) => {
  await page.goto("/collections/all");
  const results = await new AxeBuilder({ page })
    .withRules(["image-alt"])
    .analyze();
  expect(results.violations).toEqual([]);
});

Template deduplication tip

Missing alt attributes inside snippets/card-product.liquid or sections/main-collection-product-grid.liquid repeat across every SKU card on every /collections/* and /products/* page. A11yDrift clusters thousands of missing-alt alerts into that single Liquid card snippet.

Screen readers

What NVDA and VoiceOver announce

When an informative image lacks an alt attribute, screen readers either skip it silently or read out raw CDN filenames and hashes, blocking blind shoppers and readers from understanding products, charts, and editorial photos.

NVDA (Windows)

Broken

"graphic, cdn_shop_files_IMG_8842_v1731942.webp" (or skipped silently depending on verbosity)


Fixed

"Cobalt blue stoneware ceramic pour-over mug with matte handle, graphic"

VoiceOver (macOS / iOS)

Broken

"IMG_8842_v1731942.webp, image"


Fixed

"Cobalt blue stoneware ceramic pour-over mug with matte handle, image"

Common questions

When should a Shopify Liquid image use alt="" instead of descriptive text?
Use alt="" (empty string) only for purely decorative backgrounds, divider graphics, or icons adjacent to identical visible text. Product photos, promotional banners with text, and brand logos inside links must have descriptive alt text.
Does Shopify's image_tag filter automatically output an alt attribute?
image_tag reads the media's stored alt field by default, but if a merchant left it blank or you pass an unescaped string, it can render empty when descriptive text is required. Passing alt: image_alt with a product.title fallback ensures informative cards never go unnamed.
Should product card alt text repeat the exact link title right next to it?
If the image and product title are separate links, give the image concise visual detail (e.g., color/angle). Better yet, wrap the card's image and heading cleanly or set decorative thumbnail alt="" when inside the same link as the visible product title.