Skip to content
Sentinela

Accessible Color Swatches for Shopify Variant Pickers

Published · 10 min read

An accessible color swatch on Shopify is a real radio button with a text name. Put the swatches for one option in a <fieldset> with a <legend>, show the selected and sold-out states in text as well as visually, give each swatch a visible focus ring and a target of at least 24 × 24 CSS pixels, and make pale swatches stand out from the page. Shopify's Dawn theme already follows most of this. Problems usually come from custom swatch code and swatch apps. This article covers the common failures, how Dawn builds its swatches, minimal Liquid and CSS, Shopify's built-in swatches, what to check in apps, and how to test.

It goes deeper on the variant picker than our Dawn accessibility guide.

What goes wrong with color swatches

Failure What the customer experiences WCAG 2.2
Color is the only way to tell options apart A shopper with color blindness can't tell "Navy" from "Black", and nothing gives the name 1.4.1 Use of Color
No text name for the swatch A screen reader says "button" or "clickable", or nothing. Image swatches have no alt text 4.1.2 Name, Role, Value, 1.1.1 Non-text Content
Selected state not exposed The swatch looks selected, but a screen reader can't tell which one is chosen 4.1.2
Sold out shown only by a strike or faded color A screen reader user picks a sold-out color and finds out only when "Add to cart" doesn't work. The faint line is also hard to see 1.3.1, 1.4.11
Swatches are divs, or focus styles were removed Keyboard users can't reach the swatches, or can't see where they are 2.1.1 Keyboard, 2.4.7 Focus Visible
Tiny swatches packed close together Mobile shoppers and people with tremors tap the wrong color 2.5.8 Target Size (Minimum)
White or pale swatch with a faint border The swatch, or the ring that shows it's selected, nearly disappears on a white page 1.4.11 Non-text Contrast

2.5.8 asks for targets of at least 24 × 24 CSS pixels, or enough spacing around smaller ones. 1.4.11 asks for 3:1 contrast for the visual parts needed to identify a control and its state: the selected ring, the focus ring and, in practice, the edge of a pale swatch.

The pattern that works: native radio buttons

A set of colors where you pick exactly one is a radio group. Native <input type="radio"> elements give you, with no ARIA:

  • One Tab stop for the group. Arrow keys move between colors and select them, and Tab moves on to the next control. This is the behavior described in the WAI-ARIA radio group pattern.
  • Role, name and state. A screen reader announces something like "Color, grouping. Forest green, radio button, checked, 2 of 5". The name comes from the <label>, and the group name comes from the <legend>.
  • Form behavior. The checked value is part of the form and fires a change event your theme's script can listen for.

The visual swatch goes inside the <label>, and the input itself is visually hidden but stays focusable. The color name can be visible text (the most robust option) or visually hidden text, as long as the selected name is also shown on screen, for example in the legend.

How Dawn does it

We checked Dawn's current source (main branch, October 2026, which matches v16.0.0 for these files). When an option has swatch data and the variant picker block's Swatch setting isn't "None", Dawn renders:

  • A fieldset and legend in snippets/product-variant-picker.liquid. The legend reads "Color: Forest green", with the selected value in a <span data-selected-value> that VariantSelects in assets/global.js updates on change. So the selected color is always visible as text.
  • A radio and a label for each value in snippets/swatch-input.liquid. The label holds the visual swatch from snippets/swatch.liquid, plus visually hidden text with the value name, passed in from snippets/product-variant-options.liquid. The label also has a title with the value name, which gives a hover tooltip but nothing for keyboard or touch users.
  • Sold out in text. Unavailable values get visually hidden text, "Variant sold out or unavailable". The input isn't disabled: it gets a visually-disabled class, so it can still be focused, selected and announced, and the Add to cart button changes to "Sold out". Visually, the swatch is dimmed to 40% opacity and crossed with a thin diagonal line.
  • Focus kept after a change. Dawn fetches the new product section and swaps it in, then moves focus back to the input you just used (renderProductInfo() in assets/product-info.js). The price, and the inventory and SKU blocks if you show them, are role="status" regions.
  • Sizes. Swatches are 36 px on mobile and 28 px from 750 px wide, with margins, so they meet 2.5.8.

Two details are worth tightening. These are our calculations from assets/component-swatch.css and assets/component-swatch-input.css, with Dawn's default text color (#121212) on white:

  • The swatch border is 15% of the text color. That works out to about 1.4:1 against white, so a white or cream swatch has almost no visible edge.
  • The focus style on a selected swatch is faint. When you Tab into the group, focus lands on the checked swatch. On a checked swatch, Dawn keeps the same 1 px ring used for "selected" and adds a soft glow at 25% opacity (about 1.75:1). The focus ring on an unselected swatch is stronger, at about 3.5:1.

The sold-out line is drawn inside the dimmed swatch, so it is dimmed too (about 2.6:1 on white). Because it is a shape, not a color change, it doesn't fail 1.4.1, but it is easy to miss.

Minimal Liquid, CSS and JS

If you build swatches yourself, in a custom section or a theme that doesn't have them, this is the structure to keep. It uses Shopify's product_option_value properties, which are the same ones Dawn uses.

{%- for option in product.options_with_values -%}
  <fieldset class="swatches">
    <legend>
      {{ option.name | escape }}: <span data-selected-value>{{ option.selected_value | escape }}</span>
    </legend>
    {%- for value in option.values -%}
      {%- capture input_id -%}{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}{%- endcapture -%}
      <input type="radio" class="swatch__input visually-hidden"
        id="{{ input_id }}"
        name="{{ option.name | escape }}-{{ option.position }}"
        value="{{ value | escape }}"
        {% if value.selected %}checked{% endif %}>
      <label for="{{ input_id }}" class="swatch{% unless value.available %} swatch--sold-out{% endunless %}">
        <span class="swatch__chip" aria-hidden="true"
          {%- if value.swatch.image %} style="background-image: url('{{ value.swatch.image | image_url: width: 80 }}')"
          {%- elsif value.swatch.color %} style="background-color: rgb({{ value.swatch.color.rgb }})"{% endif %}></span>
        <span class="visually-hidden">
          {{- value | escape -}}
          {%- unless value.available %}, {{ 'products.product.sold_out' | t }}{% endunless -%}
        </span>
      </label>
    {%- endfor -%}
  </fieldset>
{%- endfor -%}

visually-hidden must be a "screen reader only" class (Dawn has one in assets/base.css), not display: none, or the radios can't be focused. Use your theme's translation key for "Sold out". The chip is aria-hidden because the name is already in text.

The markup still has to be connected to your theme's variant script, which updates the variant ID, price and URL. In Dawn, edit snippets/product-variant-options.liquid and snippets/swatch-input.liquid directly rather than pasting this, because Dawn's script relies on the form and data- attributes there. If your theme doesn't update the selected name in the legend, this does:

document.addEventListener('change', (event) => {
  const input = event.target.closest('.swatches input[type="radio"]');
  if (!input) return;
  input.closest('fieldset').querySelector('[data-selected-value]').textContent = input.value;
});

The CSS gives a clear edge, separate selected and focus rings, a sold-out line that shows on any color, and a 40 px target:

.swatches { display: flex; flex-wrap: wrap; gap: 8px; border: 0; margin: 0 0 16px; padding: 0; }
.swatches legend { width: 100%; margin-bottom: 8px; padding: 0; }

.swatch { position: relative; display: inline-flex; padding: 4px; border-radius: 50%; cursor: pointer; }
.swatch__chip {
  display: block; width: 32px; height: 32px; border-radius: 50%;
  background-size: cover;
  border: 1px solid #767676;   /* 4.5:1 on white, so pale swatches keep an edge */
  forced-color-adjust: none;   /* keep the colour visible in Windows contrast themes */
}

/* Selected: one dark ring */
.swatch__input:checked + .swatch { outline: 2px solid #121212; outline-offset: 0; }

/* Keyboard focus: a second ring further out, so focus and selection look different */
.swatch__input:focus-visible + .swatch { box-shadow: 0 0 0 4px #fff, 0 0 0 6px #121212; }

/* Sold out: a diagonal line with a light edge, visible on dark and light swatches */
.swatch--sold-out::after {
  content: ""; position: absolute; top: 4px; bottom: 4px; left: calc(50% - 1px); width: 2px;
  background: #121212; box-shadow: 0 0 0 1px #fff; transform: rotate(45deg);
}

Replace the hard-coded colors with your theme's color variables and check them on each color scheme. To tighten Dawn itself, raise the border in .swatch (rgba(var(--color-foreground), 0.5) gives about 3.5:1 with the defaults) and give .swatch-input__input:checked:focus-visible + .swatch-input__label a stronger, separate ring.

Shopify's built-in swatches

Shopify stores swatch data in category metafields. When a product has a category from Shopify's product taxonomy, you can connect a variant option such as Color to the category's color metafield. Each entry has a name and a color or image, and editing an entry (for example renaming "Black" to "Graphite") updates every product that uses it (Shopify Help Center). Shopify's help says you need the latest version of Dawn or another theme that supports swatches. In Liquid, the data is available as value.swatch.color and value.swatch.image on each product option value.

In Dawn, the variant picker block has a Style setting (Dropdown or Pills) and a Swatch setting (Circle, Square or None). With Pills, you get the radio swatches described above. With Dropdown, you get a native <select> with a small swatch preview next to it, and unavailable values read "Forest green - Unavailable". Both are accessible starting points. Dawn's collection filters can also show swatches, as checkboxes with the value name next to them. In the code we read, that text sits outside the checkbox's <label>, so check with a screen reader that each filter swatch announces its color name.

Three things to remember:

  • The entry name is the accessible name. "Forest green" helps everyone. "Color 1", "FG-02" or a hex code doesn't.
  • Image swatches need real names too, such as "Blue stripe".
  • Shopify supplies the data, and the theme decides the markup. A theme or app can render the same metafield as accessible radios or as unlabeled divs, so test what your theme outputs.

What to check in a swatch app

Swatch apps replace the theme's picker with their own markup. Before installing one, or when auditing one, check:

  1. Markup. In DevTools, are the swatches <input type="radio"> elements, or <button>s with aria-pressed? Or are they div, span or li elements with click handlers? aria-label on a plain div with no role is not reliably announced.
  2. Keyboard. Can you Tab to the group, choose a color with the arrow keys (or Tab and Enter/Space for buttons), and see focus at every step?
  3. Name and state. Does a screen reader announce the color name, and which one is selected?
  4. Sold out. Is "sold out" available as text, not just as a strike-through or fading?
  5. Sync. Does choosing a swatch update the price, the URL, the Add to cart button and the image, as the theme's own picker does?
  6. Focus after re-render. If the app redraws the picker, does focus return to the swatch you chose, or jump to the top of the page?
  7. Size and contrast. Are targets at least 24 px, or spaced well enough, and are the selected and focus rings at least 3:1?
  8. Collection pages. Swatches on product cards need names too.

If an app fails these, ask the vendor for a fix or go back to the theme's own swatches.

How to test

  1. Keyboard. Tab into the picker. Focus should land on the selected swatch. Arrow keys should change the color, and the price and image should update while focus stays put.
  2. Screen reader. With NVDA and Firefox or Chrome, and VoiceOver with Safari on iOS, listen for the group name, each color name, "checked", and "sold out". Check whether the new price is announced, as you would for cart updates in a drawer.
  3. Accessibility tree. In Chrome or Firefox DevTools, each swatch should show role "radio", a name, and a checked state.
  4. Contrast and size. Measure the selected ring, focus ring and pale swatch edges against the background (3:1), and swatch size and spacing (24 px).
  5. Zoom and reflow. At 200% zoom and 320 px wide, swatches should wrap rather than overflow.
  6. Automated checks. An automated check is not an audit. Tools such as axe-core find missing names and invalid ARIA. They can't tell whether the selected state is clear or whether color is the only cue. See what a free scan finds, and what it can't.

Work on a duplicate theme and preview it before publishing. If your store also runs on WooCommerce, our WooCommerce variation swatches guide covers the same pattern there.

Where Sentinela fits

Sentinela's automated checks use axe-core rules mapped to WCAG 2.2 A/AA, plus our own keyboard and accessibility-tree checks, at 1366 px and 320 px wide. An audit adds a reviewer who tests the keyboard journey to the start of checkout, NVDA and VoiceOver, target size and contrast, and records a verdict for every WCAG 2.2 A and AA criterion. With remediation, we fix the findings on a preview theme, and nothing is published until you approve it. Third-party apps and content added later are out of scope. We fix the code, not the view on top of it (why overlays don't fix your theme).

Sources