Color picker: a ball you drag over the color squashes against the edges, hue and alpha pills, rolling channels, and a live WCAG contrast row with the readable text color.
DragDrag
Workspace › Appearance
Brand color
Used for buttons, links, badges and charts across the workspace.
Aa5.650123456789.601234567899.9: 1Light textAAContrast 5.6 to 1 with light text, passes AA
Preview
Weekly signups+12%
Thursday was the best day. View report
Invite memberWhite text · 5.6 : 1 · AA
color-picker · , lively
color-picker-demo.tsx
When to use
Use when people pick any color, with an optional contrast row that shows the WCAG ratio and the readable text color. Presets: field (opens in a popover), inline and swatches.
When not to use
For a fixed short list of colors with no custom value use Radio Group. For a native browser dialog use a plain input of type color.
Use it for brand, label, tag, series and status colors in theme editors, workspace settings and
label managers. shadcn has no color picker and the native <input type="color"> opens a different
dialog in every browser. It has three presets: field (a swatch tile and a hex field; the tile
morphs into the panel in a popover), inline (the panel in a card, for appearance settings that
keep it on screen) and swatches (a row of swatch balls with a "+" for a custom color, for
calendars and tags). For a fixed short list of colors with no custom value, a
Radio Group is simpler.
The picker follows the MotionKit motion grammar in three beats. Pressing the area charges the
ball: it stretches toward the press point. It is then thrown there on the small spring (the
action) and, when the trip ends on an edge, it squashes against that edge only (the
settle). Dragging, the ball follows eased while the color inside it, the swatch tile and the
hex update every frame and the R/G/B digits roll. The hue and opacity thumbs are the same ball on
12 px pills, squashing at the ends. Picking a swatch, the ball travels across the area to that
color while the hue ball slides to its hue, and the selection ring rolls to the swatch. At calm
the ball glides along the edges without squashing.
With contrast, a row under the fields answers the question behind most brand colors: can text
sit on it? It shows "Aa" in the most readable text color on the picked color, the WCAG ratio
(its digits roll as you drag, floored so 4.49 never reads as a pass) and the level badge (AAA,
AA, AA large or Fail), which pops when the level changes.
Values are hex strings: #rrggbb, or #rrggbbaa with alpha. value and defaultValue also
read the RGB and HSL strings. onValueChange fires on every change, drag frames included;
onValueCommit fires once a change is finished (pointer up, key, swatch, typed value). format
picks the channel fields under the hex (rgb, hsl or hex for none). With name, the picker
submits the hex in a hidden input.
contrast adds the live contrast row. true tests white and a near-black and shows whichever
reads better; pass your own text colors to test against those only, for example the white text
your labels always use:
The helpers behind it are exported for your own previews: contrastRatio(a, b) (1 to 21,
floored to one decimal), contrastLevel(ratio) and contrastWith(color, candidates?), which
returns the readable text color for a brand color:
The parts are exported for your own layout inside ColorPicker: ColorArea, HueSlider,
AlphaSlider, ColorFields, ColorContrast, ColorSwatches (pass them as children). Set the
character for the whole app with MotionKitProvider, or per picker with temperament.
preset="field" in a label editor: pressing the field sinks it and the swatch tile grows into
the panel. The tracker's labels always use white text, so the panel's contrast row
tests the color against white only, and the form turns the field aria-invalid with a hint when
the label text would fail AA (try the amber or green swatch). The label preview updates as you
drag.
preset="swatches" in a calendar's settings rows: the ring rolls between the swatch balls and
squashes against the one it lands on; "+" opens the area for a custom color. The second row is
disabled. The week view below repaints its event in the picked color.
The area is a role="slider" (aria-roledescription="2D slider") named after label plus ", saturation
and brightness", with aria-valuetext "Saturation 80%, brightness 60%". Hue and opacity are
role="slider" with "Hue 228°" and "Opacity 90%".
The swatches are a role="radiogroup" of role="radio" buttons named by their label (or hex),
with roving focus. The "+" button has aria-haspopup="dialog".
In field, the hex input is a role="combobox" with aria-haspopup="dialog" and
aria-expanded; the panel is a role="dialog" named "Choose" plus the label.
The hex is validated on blur and Enter: an invalid entry keeps the last color, sets
aria-invalid and turns the rim destructive. A polite live region announces "Color 3B5BDB
selected" when a change is finished.
Every ball has a 2 px background rim and a 1 px foreground line, so it stays visible on any
color. Focus shows a 3 px ring halo outside the ball, the fields and the swatches. Hit areas
are at least 24 px (the 12 px pills sit in a 24 px band).
The contrast row is read as one sentence ("Contrast 5.6 to 1 with light text, passes AA"); its
visual parts are aria-hidden. It is not a live region, so a drag does not flood the screen
reader; with contrast, the commit announcement adds the ratio and level ("Color 3B5BDB
selected, contrast 5.6 to 1, AA"). The level is written out, never shown by color alone.
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") there is no
charge, squash, sink, morph or roll. The panel crossfades in place, the balls and the selection
ring glide to their place in a short fade, the digits crossfade, and the inline picker shows the
ball on its color from the first frame. The contrast digits crossfade and the level badge fades
instead of popping. The rest look (rimmed ball, pills, swatch ring) is
complete on its own.
Only transform and opacity animate (ball position, charge and squash, ring roll, morph,
digit roll); the area's gradient repaints only when the hue changes. Pointer capture keeps a drag
on the area; touch-action: none is on the area and the pills only, so the page still scrolls.
Nothing loops. The inline picker's first trip (from the area's centre to the color) runs once,
when the card comes into view.
Size: about 16 kB gzip with its MotionKit helpers (ball, morph, roll, beats): the Pro 15 kB
budget plus 1 kB for the contrast row and helpers. Third-party dependencies come on top: @radix-ui/react-popover about 23 kB gzip
(shared with shadcn's Popover) and motion about 47 kB (shared by every MotionKit component).
SSR-safe: the eyedropper button appears on the client only, where EyeDropper exists.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 16.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, @radix-ui/react-popover, motion.
Dependencies
@radix-ui/react-popover · peer
motion · peer
Triggers
drag, click, press, typing, keyboard focus, entering the viewport
Reduced motion
No charge, squash, morph or roll: the panel crossfades in place, the balls and the ring glide in a short fade, digits and the contrast level crossfade.
Keyboard
ArrowLeft / ArrowRight
On the area: saturation -1 / +1% (Shift: 10%)
ArrowUp / ArrowDown
On the area: brightness +1 / -1% (Shift: 10%)
PageUp / PageDown
On the area: brightness +10 / -10%
Home / End
On the area: saturation 0 / 100%; on hue and opacity: first / last value
Arrow keys
On hue and opacity: one step (Shift: ten); on the swatches: the previous or next swatch
ArrowDown
From the field: opens the panel
Enter
In the hex or channel fields: applies the typed value
Escape
Closes the panel and returns focus to the field
Tab
Moves between the area, hue, opacity, hex, channels, eyedropper and swatches
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)