Skip to main content
Copy for LLM

Swatch

<x-wirekit::swatch> shows a value that is a color, a pattern or a short name: the color of a product variant, a fabric, a finish, a size. It draws a circle or a square filled with the color or the picture, or a pill with the name, and it carries the value's name, because a color says nothing to a reader who cannot see it.

To let the reader choose among swatches, use the swatch group: it puts each swatch in a native radio button or checkbox, which posts with a form and binds with wire:model.

Usage

Give the swatch a color and a label. The label is the swatch's name for assistive technology:

A color and its name

Add show-label to show the name as text beside the swatch:

The name beside the swatch
Navy Chalk Coral

A light color keeps its edge on a light page: every swatch has a border in the color the form fields use for theirs, which stands at 3:1 against the page.

A Pattern Instead of a Color

image fills the swatch with a picture, for a value no single color describes: a fabric, a wood grain, a leather. The picture covers the swatch, and the swatch's name names it:

Finishes as pictures
Linen Walnut

image takes an http or https address, or a path on your site. An address with any other scheme draws no picture.

A Color Behind the Picture

Give a color with the image, and the color lies behind the picture: it shows through the picture's transparent parts, fills the swatch while the picture loads, and stands alone where the picture does not load. A color close to the picture's own keeps a row of patterns calm while they arrive:

A color behind each picture
Linen Walnut

A Name Instead of a Color

shape="pill" draws the value's name as the swatch's text, for a value its name says best, such as a size. A pill is as tall as a swatch of its size and at least as wide, and it is read as its text:

Sizes as pills
S M XXL XS, unavailable

An unavailable pill strikes its name through and reads "unavailable" with it. A color or an image given with a pill is drawn as a dot before the name:

A color before its name
Navy Chalk Linen

A pill draws its name, so it needs a label. Without one, WireKit reports it in development and draws a circle.

The Colors It Accepts

color takes a hex color of three, four, six or eight digits (#fff, #1e3a8a, #1e3a8a80), rgb(), hsl() or oklch(). The color is written into the swatch's style attribute, so a value in any other form is rejected: WireKit reports it in development, and the swatch draws no fill instead of writing the value into your page. A color that comes from your database is checked the same way as one written in a template.

An Unavailable Value

unavailable draws a line across the swatch and adds "unavailable" to its name, so the state is in the picture and in the words:

A value that is not available
Navy Red, unavailable

Sizes and Shapes

size is sm (24px), md (32px, the default) or lg (40px), the height of a pill as well. shape is circle, the default, square, whose corners take the theme's small radius, or pill:

Three sizes, two shapes

The defaults come from config('wirekit.components.swatch').

Props

Prop Type Default Description
color string|null null The value's color: a hex color, rgb(), hsl() or oklch(). Any other value is rejected and draws no fill. Given with an image, it lies behind the picture
image string|null null A picture of the value, as an http or https address or a path. It covers the swatch, over a color given with it
label string|null null The value's name. It names the swatch for assistive technology, stands beside it with showLabel, or is the text of a pill. Without one the swatch is decorative and hidden from assistive technology
showLabel bool false Show the name as text beside the swatch. A pill shows it inside already
unavailable bool false Draw a line across the swatch, or through a pill's name, and read "unavailable" with its name
size string md sm (24px), md (32px) or lg (40px), the height of a pill
shape string circle circle, square or pill, which draws the name as text
scope string|null null Scoped personalization key

Accessibility

  • The name is always there. With label the swatch is an image named by it; with showLabel the name is text beside it, and the swatch itself is hidden from assistive technology so the name is read once. A swatch without a label is decorative: give it one unless the value's name already stands next to it.
  • No state rests on color alone. An unavailable value has a line across it, or through a pill's name, and "unavailable" in its name.
  • A pill is read as its text. The name it shows is the name a reader hears, and it is as tall as a swatch of its size, 24px at sm, and at least as wide, so it is never a smaller target than a circle.
  • A light color keeps its edge. The border is the form fields' resting border, at 3:1 against the page, so white on white stays visible.
  • The color survives a forced-colors theme. It is the content of the swatch, as a photo's colors are, so the fill opts out of the theme's color replacement, while the edge around it takes the theme's colors.

Keyboard Interaction

A swatch is not interactive and takes no focus. To choose among swatches with the keyboard, use the swatch group.

Design Tokens

Token Use
--size-wk-xs / --size-wk-sm / --size-wk-md The swatch at sm, md and lg
--radius-wk-sm The corners of a square swatch
--border-wk-width + --color-wk-border-strong The edge that keeps a light color visible on a light page
--color-wk-text + --color-wk-surface The line across an unavailable value, and the halo that keeps it readable on a dark color
--gap-wk-sm + --text-wk-sm The name beside the swatch
--padding-wk-x-xs / --padding-wk-x-sm / --padding-wk-x-md The sides of a pill at sm, md and lg
--text-wk-xs / --text-wk-sm / --text-wk-md The name in a pill at sm, md and lg
--color-wk-surface + --color-wk-text + --gap-wk-xs A pill's ground, its name, and the space after its dot

Customization

Set the default size and shape of every swatch in config/wirekit.php:

'components' => [
    'swatch' => ['size' => 'lg', 'shape' => 'square'],
],

Updated in WireKit v2.70.0 (2026-10-31)

Was this page helpful?

Thank you for your feedback!

Voting requires cookies or local storage. What we store