Skip to content
Search
Search the documentation
Colour swatches
GitHub
1 min read

Colour swatches

Show a palette's colours, and what each token resolves to in the current colour mode.

ColorSwatch shows one colour, its name, and the value it resolves to. Give it any CSS colour, CSS variables included, so a library can document its own design tokens. Switch the colour mode and the values below change with it: these are this site’s own theme tokens.

--background var(--background)
--foreground var(--foreground)
--primary var(--primary)
--primary-foreground var(--primary-foreground)
--secondary var(--secondary)
--muted var(--muted)
--accent var(--accent)
--destructive var(--destructive)
--border var(--border)
--ring var(--ring)

Usage

ColorSwatches lays swatches out in a grid, as many columns as fit.

			<script>
	import { ColorSwatch, ColorSwatches } from 'svelte-docsmith';
</script>

<ColorSwatches>
	<ColorSwatch value="var(--brand)" />
	<ColorSwatch value="var(--brand-muted)" name="Brand, muted" />
	<ColorSwatch value="#3b82f6" />
	<ColorSwatch value="oklch(0.7 0.15 150 / 50%)" name="Translucent green" />
</ColorSwatches>
		
Chart 1 var(--chart-1)
Chart 2 var(--chart-2)
#3b82f6
Translucent green oklch(0.7 0.15 150 / 50%)

The name defaults to the variable for var(--x), and to the value for any other colour. Below the name is the value the browser resolves, in the notation your stylesheet uses. A token derived from others, such as a color-mix(), shows the colour it comes out as. The value updates when the reader switches colour mode, whether your site marks that with a class or attribute on the html element or follows the system setting. It is left out when it would only repeat the name. A translucent colour shows over a checkerboard.

The server can’t know what a variable resolves to, so the page first shows the value as written, and the browser fills in the resolved value as it loads.

API reference

ColorSwatch

ColorSwatch
value required string
Any CSS colour: #3b82f6, oklch(0.6 0.2 260) or var(--brand).
name string default the variable's name for `var(--x)`, otherwise the value
The label under the swatch.

ColorSwatches

ColorSwatches
children required Snippet
The ColorSwatch components to lay out.

Was this page helpful?