Skip to content

Color Swatch

Display and select a named color value. CSS only

Color Swatch
Copy this markup
<div class="ui-color-swatch" style="--ui-color-swatch: oklch(62% 0.18 32)">
<span data-ui-part="chip" aria-hidden="true"></span>
<span data-ui-part="label">Brand red</span>
<span data-ui-part="value">oklch(62% 0.18 32)</span>
</div>

Install

Styles and registration
import '@timelessui/components/css/tokens.css'
import '@timelessui/components/css/color-swatch.css'

Anatomy

Parts are authored in your own markup and identified by the selector below, so your CSS can target the same anatomy without loading Timeless styles. Required parts must be present for the component to work. Private data-ui-internal-* hooks are written by the runtime and must never be authored.

PartRequiredSelectorPurpose
chipNo[data-ui-part~='chip']The color area. Set the color through --ui-swatch-color.
labelNo[data-ui-part~='label']Human-readable color name.
valueNo[data-ui-part~='value']The raw CSS color value.
warningNo[data-ui-part~='warning']Out-of-gamut or contrast warning.

Styling

Root identity: ui-color-swatch. Required stylesheets: tokens.css, color-swatch.css.

This component adds no custom properties of its own. Restyle it through the design tokens or your own CSS.

Design tokens this component reads (18)

These are global Atmosphere tokens. Change them once at the theme level rather than per component.

--ui-accent · --ui-bg-surface · --ui-bg-surface-raised · --ui-checkerboard · --ui-disabled-opacity · --ui-duration-fast · --ui-ease-standard · --ui-fg · --ui-fg-muted · --ui-focus · --ui-font-mono · --ui-line · --ui-line-strong · --ui-radius-md · --ui-radius-sm · --ui-space-2 · --ui-space-3 · --ui-warning

Accessibility

Keep the native elements, roles, and relationships shown in the example. Timeless adds only the state and keyboard coordination the platform does not already provide, and it never supplies your accessible names — those depend on your content.

Before JavaScript runs

This primitive is CSS only. There is nothing to register and nothing to wait for.

Color Palette

Lay several swatches out as a selectable grid across CSS color formats.

Color Palette
Copy this markup
<div style="display: grid; gap: 0.5rem; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr))">
<button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand red, oklch(62% 0.18 32)" style="--ui-color-swatch: oklch(62% 0.18 32)">
<span data-ui-part="chip" aria-hidden="true"></span>
<span data-ui-part="label">Brand red</span>
<span data-ui-part="value">oklch(62% 0.18 32)</span>
</button>
<button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand amber, hwb(38 6% 8%)" style="--ui-color-swatch: hwb(38 6% 8%)">
<span data-ui-part="chip" aria-hidden="true"></span>
<span data-ui-part="label">Brand amber</span>
<span data-ui-part="value">hwb(38 6% 8%)</span>
</button>
<button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand lime, color(display-p3 0.63 0.86 0.2)" style="--ui-color-swatch: color(display-p3 0.63 0.86 0.2)">
<span data-ui-part="chip" aria-hidden="true"></span>
<span data-ui-part="label">Brand lime</span>
<span data-ui-part="value">color(display-p3 0.63 0.86 0.2)</span>
</button>
<button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand teal, lch(70% 45 190)" style="--ui-color-swatch: lch(70% 45 190)">
<span data-ui-part="chip" aria-hidden="true"></span>
<span data-ui-part="label">Brand teal</span>
<span data-ui-part="value">lch(70% 45 190)</span>
</button>
<button class="ui-color-swatch" type="button" aria-pressed="true" aria-label="Select Brand blue, #3366cc" style="--ui-color-swatch: #3366cc">
<span data-ui-part="chip" aria-hidden="true"></span>
<span data-ui-part="label">Brand blue</span>
<span data-ui-part="value">#3366cc</span>
</button>
<button class="ui-color-swatch" type="button" aria-pressed="false" aria-label="Select Brand violet, oklch(52% 0.24 300)" style="--ui-color-swatch: oklch(52% 0.24 300)">
<span data-ui-part="chip" aria-hidden="true"></span>
<span data-ui-part="label">Brand violet</span>
<span data-ui-part="value">oklch(52% 0.24 300)</span>
</button>
</div>

More examples

Open Color Swatch in StoryLite for variants, controls, and manual testing.