Vistaprint
styleKeyscolorSwatches

Color Swatches

Color Swatches are used to show and/or select color options for products.

Color swatches can be used as their own component, or can be used with Selection Set to allow users to make selections.

Playground

Default size

Share
Share
jsx
<div class="color-swatches">
<div
class="color-swatch"
title="color red"
aria-label="color red"
style="background-color: red;"
></div>
<div
class="color-swatch"
title="color indigo"
aria-label="color indigo"
style="background-color: indigo;"
></div>
<div
class="color-swatch"
title="color green"
aria-label="color green"
style="background-color: green;"
></div>
<div
class="color-swatch"
title="color gold"
aria-label="color gold"
style="background-color: gold;"
></div>
<div
class="color-swatch"
title="color blue"
aria-label="color blue"
style="background-color: blue;"
></div>
<div
class="color-swatch"
title="color limegreen"
aria-label="color limegreen"
style="background-color: limegreen;"
></div>
<div
class="color-swatch"
title="color darkmagenta"
aria-label="color darkmagenta"
style="background-color: darkmagenta;"
></div>
<div
class="color-swatch"
title="fancy image"
aria-label="fancy image"
style='background-color: transparent; background-image: url("https://picsum.photos/id/165/100/100");'
></div>
</div>

Super size

Share
Share
jsx
<div class="color-swatches color-swatches-super">etc</div>

Indicating "more"

If there is not enough space to show all the available swatches, you can add the "More" sub-element, filling it with a + sign and the number of additional swatches.

+3
Share
Share
jsx
<div class="color-swatches">
<div
class="color-swatch"
title="color red"
aria-label="color red"
style="background-color: red;"
></div>
<span class="color-swatches-more">+3</span>
</div>

Two-tone color swatches

Share
Share
jsx
<div class="color-swatches">
<div
class="color-swatch"
title="color red/blue"
aria-label="color red/blue"
style="background-color: red; color: blue;"
></div>
</div>

Background image

You can use an image for the swatch background, if the swatch does not represent one or two colors. The background image should be square.

Share
Share
jsx
<div class="color-swatches">
<div
class="color-swatch"
title="fancy image"
aria-label="fancy image"
style='background-color: transparent; background-image: url("https://picsum.photos/id/165/100/100");'
></div>
</div>

Using a Selection Set with radio buttons

Share
Share
jsx

Using a Selection Set with super-size checkboxes

Share
Share
jsx

Guidelines

Developer Gudielines

  • By default, color swatches have a transparent background circle. In React, you can use the React props to set the swatch's primary color (and secondary color as necessary). In the vanilla API, you will need to set each swatch's background-color CSS property, either with an inline style attribute, or via an external stylesheet. If you want to create a two-tone swatch in the vanilla API, set the CSS background-color attribute to the shade on the bottom/right, and the CSS color attribute to the color on the top/left.

  • For color swatches that are acting as radio buttons or checkboxes, setting the disabled property on the associated input tag will give the swatch the disabled look. For color swatches that are not radio buttons or checkboxes, you can add the color-swatch-disabled CSS class to the swatch itself.

Accessibility Guidelines

  • To support users with visual accessibility issues, each swatch must have both a title attribute (for color-blind users) and an aria-label attribute (for assistive technologies), whose values are a localized description of the color choice, e.g. title="light blue" aria-label="light blue"

  • If used as a Selection Set, see also the Accessibility Guidelines for that component.