Colour picker
A colour picker lets users choose a colour option from a group of swatches.
Usable — may still change
The colour picker lets users choose a colour option, such as the exterior paint of a vehicle in the configurator. Each colour swatch shows the actual colour or finish of the option it represents, giving users a true-to-life preview before they commit. Only one swatch in a group can be selected at a time.
Anatomy
Section titled “Anatomy”- Selected swatch
- Swatch
- Label
When to use it
Section titled “When to use it”Use a colour picker when:
- Colour is the decision. Visual colour recognition is the main thing users choose on, for example paint or interior trim colours.
- Users need a true-to-life preview. The swatch shows the real colour or finish before they commit.
Use a different selector when:
- The options aren’t colours. Grades, trim levels or packages need a selector that names them.
Properties
Section titled “Properties”Size
The swatch comes in Small (24 px), Medium (36 px, the default), Large (44 px) and Extra large (56 px). Don’t mix sizes within one group.
State
Rested shows a translucent border, so light colours stand out from the page. Hover and Focus draw a ring around the swatch, Selected draws it in the primary colour, and Disabled fades the swatch to half opacity.
Scheme
On a contrast background, the swatches sit on a light surface, and the label moves above them.
Label
The label shows the name of the selected colour. It’s optional, but the colour name must then be visible elsewhere.
Best practices
Section titled “Best practices”Do
Accompany the group with a visible label showing the selected colour name, in plain language (for example “Midnight Black”). Use images that truthfully represent the real colour or finish. Use Medium as the default size unless the context requires otherwise.
Don't
Don’t use swatches for options that aren’t colours. Don’t show internal product codes as the visible label. Don’t place swatches on busy or patterned backgrounds, or on a colour that resembles the swatch.
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>The colour picker targets WCAG 2.1 AA and follows the WAI-ARIA radio group pattern.
For designers
Section titled “For designers”- Always show the colour name as text. Colour alone can’t identify an option for people with colour vision deficiencies. Source: WCAG 1.4.1 Use of Color.
- Use plain-language names (for example “Midnight Black”), not internal product codes. Source: WCAG 2.4.6 Headings and Labels.
- Never remove or obscure the blue focus ring. Source: WCAG 2.4.7 Focus Visible.
- Use Small swatches only in non-touch or secondary contexts. Every swatch keeps a 44 px touch target. Source: WCAG 2.5.5 Target Size.
For developers
Section titled “For developers”Group the swatches in a <fieldset> whose <legend> names the group (for example “Exterior colour”). Each swatch is a native radio, or a <button>; never a <div>. Its accessible name is the colour name, from the image’s alt or an aria-label. A button communicates selection with aria-pressed, or with aria-checked inside a role="radiogroup". Sources: WCAG 1.3.1 Info and Relationships, WCAG 4.1.2 Name, Role, Value.
Disable a swatch with the native disabled attribute, so it can’t be focused or activated. A disabled swatch may fall below the contrast minimum. Source: WCAG 1.4.3 Contrast (Minimum).
When the selection changes an image elsewhere on the page, such as the car, update that image’s alt to the new colour, so screen-reader users learn about the change.
Keyboard interaction
Section titled “Keyboard interaction”Radios:
| Key | Action |
|---|---|
| Tab | Move focus into the group, to the selected swatch |
| Arrow keys | Move to the next or previous swatch and select it |
| Space | Select the focused swatch, if it isn’t selected |
Buttons:
| Key | Action |
|---|---|
| Tab | Move focus to the next swatch |
| Enter / Space | Select the focused swatch |