CSS
A colour picker is a <fieldset> holding a group of .tng-color-swatch radios on a .tng-color-swatches pill, plus an optional .tng-color-picker-label. The selected look follows the checked radio, so selection needs no JavaScript. Keeping the label in sync with the selection is up to you.
<fieldset class="tng-color-picker"> <legend class="sr-only">Exterior colour</legend> <div class="tng-color-swatches"> <label class="tng-color-swatch"> <input type="radio" name="exterior-colour" value="blue" checked /> <img src="/assets/swatches/blue.png" alt="Blue" /> </label> <label class="tng-color-swatch"> <input type="radio" name="exterior-colour" value="red" /> <img src="/assets/swatches/red.png" alt="Red" /> </label> <label class="tng-color-swatch"> <input type="radio" name="exterior-colour" value="white" /> <img src="/assets/swatches/white.png" alt="White" /> </label> <label class="tng-color-swatch"> <input type="radio" name="exterior-colour" value="black" disabled /> <img src="/assets/swatches/black.png" alt="Black" /> </label> </div> <span class="tng-color-picker-label">Blue</span></fieldset>Elements
Section titled “Elements”Swatch
Section titled “Swatch”.tng-color-swatch is a <label> wrapping a radio and the swatch image. The radio is visually hidden but stays focusable, so the image’s alt is the radio’s accessible name. Give every radio in the group the same name.
The image is an <img>, or any element with .tng-color-swatch-image. It’s cropped to a circle.
A swatch can also be a <button>. Mark the selected one with aria-pressed="true", or with aria-checked="true" inside a role="radiogroup", and update it yourself.
<button class="tng-color-swatch" type="button" aria-pressed="true"> <img src="/assets/swatches/blue.png" alt="Blue" /></button><button class="tng-color-swatch" type="button" aria-pressed="false"> <img src="/assets/swatches/red.png" alt="Red" /></button>.tng-color-picker-label shows the selected colour’s name. Update its text when the selection changes. Leave it out only when the colour name is visible elsewhere.
The default size is md. Use one size per group.
<label class="tng-color-swatch is-sm"> <input type="radio" name="sizes" /> <img src="/assets/swatches/red.png" alt="Small" /></label><label class="tng-color-swatch is-md"> <input type="radio" name="sizes" /> <img src="/assets/swatches/red.png" alt="Medium" /></label><label class="tng-color-swatch is-lg"> <input type="radio" name="sizes" /> <img src="/assets/swatches/red.png" alt="Large" /></label><label class="tng-color-swatch is-xl"> <input type="radio" name="sizes" /> <img src="/assets/swatches/red.png" alt="Extra large" /></label>States
Section titled “States”Disabled
Section titled “Disabled”<label class="tng-color-swatch"> <input type="radio" name="state" disabled /> <img src="/assets/swatches/black.png" alt="Disabled" /></label><label class="tng-color-swatch"> <input type="radio" name="state" checked disabled /> <img src="/assets/swatches/black.png" alt="Selected and disabled" /></label>