OnlineNexusAccess accessibility home Free scan

How to make product variant pickers and color swatches accessible

The variant picker is where a shopper chooses a size or a color. If a screen reader announces each swatch as just "radio button" or a keyboard can't reach the sizes, that shopper can't buy. The good news: the correct pattern is well known, and both Shopify's Dawn theme and WooCommerce's own templates show it. This guide explains the pattern and the fixes.

Step 1: Test your picker

  1. On a product page, press Tab until you reach the first option group. Can you see the focus?
  2. Use the arrow keys (for radio-style pickers) or Tab and Space (for buttons) to change the option. Does the selection change, and does the price or image update?
  3. Turn on a screen reader (VoiceOver on Mac with Cmd+F5, or NVDA on Windows) and listen. You should hear the group name ("Color"), the option name ("Navy") and whether it is selected or sold out.

Step 2: Group each option with a fieldset and legend

A set of size or color choices is a group of related controls. The W3C forms tutorial recommends grouping related radio buttons in a <fieldset> with a <legend> that names the group (Grouping Controls (W3C WAI Forms Tutorial)). Dawn does exactly this for its button-style and swatch pickers: each option is a fieldset with the option name (such as "Size") as the legend, and each value is a radio input with a label (snippets/product-variant-picker.liquid in Shopify's Dawn theme (GitHub)).

Accessible size and color picker (HTML)
<fieldset class="variant-group">
  <legend>Size</legend>
  <input type="radio" name="size" id="size-s" value="S">
  <label for="size-s">S</label>
  <input type="radio" name="size" id="size-m" value="M" checked>
  <label for="size-m">M</label>
  <input type="radio" name="size" id="size-l" value="L">
  <label for="size-l">L <span class="visually-hidden">(sold out)</span></label>
</fieldset>

<fieldset class="variant-group">
  <legend>Color: <span class="selected-value">Navy</span></legend>
  <input type="radio" name="color" id="color-navy" value="Navy" checked>
  <label for="color-navy" class="swatch" style="--swatch: #1f2a44">
    <span class="visually-hidden">Navy</span>
  </label>
  <input type="radio" name="color" id="color-sand" value="Sand">
  <label for="color-sand" class="swatch" style="--swatch: #d8c7a8">
    <span class="visually-hidden">Sand</span>
  </label>
</fieldset>

Real radio inputs give you keyboard support for free: arrow keys move between options in a group and the selected state is announced. Hide the native circle visually with CSS if you like, but keep the input in the page, and keep the focus visible on the label.

Step 3: Give every swatch a text name

A color circle on its own is just a picture. Each swatch needs a name a screen reader can read, such as the visually hidden text in the example above. Dawn renders the option value as visually hidden text inside each swatch label (snippets/product-variant-options.liquid in Shopify's Dawn theme (GitHub)). Avoid using only a title attribute for the name; in our scan of 10 stores, 2 had form fields labelled only by a title tooltip.

It also helps sighted shoppers to see the chosen color name next to the legend ("Color: Navy"), because two similar shades can be hard to tell apart.

Step 4: Show "sold out" without relying on color alone

A greyed-out or crossed-out swatch tells most sighted shoppers that a size is unavailable, but not someone who can't see the difference. WCAG 1.4.1 says color must not be the only visual means of conveying information (Understanding Success Criterion 1.4.1: Use of Color (W3C WAI)). Add text: Dawn adds visually hidden "sold out or unavailable" text to the label of an unavailable option (snippets/product-variant-options.liquid in Shopify's Dawn theme (GitHub)). A visible "Sold out" label or a pattern on the swatch helps sighted shoppers too.

Step 5: Announce price and stock changes

When a shopper picks a different variant, the price, stock message or "Add to cart" button often changes somewhere else on the page. A short status region lets screen readers announce the change without moving focus, which is what WCAG 4.1.3 Status Messages covers (Understanding Success Criterion 4.1.3: Status Messages (W3C WAI)).

Status message for variant changes
<p class="variant-status visually-hidden" role="status"></p>

<script>
  // Call this after your theme updates price and availability.
  function announceVariant(name, price, available) {
    document.querySelector('.variant-status').textContent =
      name + ', ' + price + (available ? '' : ', sold out');
  }
</script>

Step 6: Make swatches big enough to tap

Tiny swatches are hard to hit for people with tremors or on small phones. WCAG 2.2 adds 2.5.8 Target Size (Minimum): targets should be at least 24 by 24 CSS pixels, or have enough space around them, with some exceptions (Understanding Success Criterion 2.5.8: Target Size (Minimum) (W3C WAI)). Our scan found undersized targets on 2 of the 10 stores we tested. A 40px swatch with a few pixels of gap is comfortable for most people.

WooCommerce: what the default template does

WooCommerce's default variable product template uses a <select> drop-down for each attribute, with a <label for> naming it, and a "Clear" link labelled "Clear options" (single-product/add-to-cart/variable.php template (WooCommerce, GitHub)). It also includes a screen-reader-only live region for reset messages. Drop-downs are accessible by default, so if your store uses the standard template you may only need to check contrast and focus styles. Problems usually start when a swatch plugin replaces the drop-downs with colored divs. Test the plugin with the steps above; if it fails, check its settings for an accessibility option, contact the developer, or go back to drop-downs.

Check your own store in a minute or two. Our free scanner opens your homepage, a collection page, a product page and your cart in a real browser and lists the problems it can detect automatically, in plain English.

Run the free scan

Common questions

Are drop-downs or swatches better for accessibility?

Both can be accessible. Native drop-downs are the safest default. Swatches built as real radio inputs with text names work well and are easier to scan visually.

My swatch app uses divs with click handlers. Can I patch it?

Patching another developer's markup with scripts tends to break on the next update. Ask the vendor to use radio inputs or buttons with names, or switch apps. See how to check Shopify apps.

Does the image need to change too?

If the main image changes with the variant, make sure its alt text changes with it, or describes the product generally. Check with our alt text checker.

Technical fixes, not legal advice. This guide explains website accessibility from a technical point of view. We are not a law firm, and nothing here is legal advice. No scan, fix or guide can guarantee legal compliance, the outcome of any demand letter or lawsuit, or protection from future claims. If you have received a legal claim, please consult a qualified attorney about it.

Sources