Color Picker
shadcn-htmx/color-pickerFreeComponent
A native <input type="color"> styled as a shadcn swatch, with an optional live hex readout. The browser supplies the entire picker UI and guarantees a valid CSS color value — we only restyle the swatch and never parse colors ourselves.
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/color-picker.jsonSource
1/** @jsxImportSource hono/jsx */2import { cn, type ClassValue } from "@/registry/lib/cn"34// Color Picker — shadcn-htmx, htmx v4 + Tailwind v4.5//6// Built on native <input type="color">. The browser owns the entire picker7// UI (a platform color dialog or a validating text field) and guarantees the8// value is a valid CSS color — we never reimplement any of that. shadcn/ui has9// no color-picker; we mirror the Input anatomy10// (repos/shadcn-ui/apps/v4/registry/new-york-v4/ui/input.tsx) and lean on the11// platform exactly like registry/ui/slider.tsx does for <input type=range>.12//13// What the platform gives us, per MDN:14// - the whole color-selection UI + value validation; an invalid value is15// coerced and :invalid is applied (we never parse colors ourselves)16// - `value` is a CSS <color>; default is #000000 when omitted/invalid17// - `alpha` (boolean) lets the user edit the alpha channel18// - `colorspace` ("limited-srgb" | "display-p3") hints the picker + gamut19// - `input` fires continuously as the color changes, `change` on dismiss20// - supported common attributes: autocomplete, list (a <datalist> of swatches)21// - it has NO implicit ARIA role, so a visible <label for> or ariaLabel is22// required for an accessible name23// See repos/mdn/files/en-us/web/html/reference/elements/input/color/index.md24// (Value:54, alpha/colorspace:63-69, events:96, common attrs:219,25// validation:121, Implicit ARIA Role: none:244)26//27// We hide the browser's default swatch chrome via Tailwind v4's pseudo-element28// selectors ([&::-webkit-color-swatch] / [&::-moz-color-swatch]) so the control29// reads as one rounded shadcn swatch — the same -webkit-/-moz- pairing the30// Slider uses for its thumb. Both engines need separate rules.31//32// JS budget: none for the swatch itself (it is a real <input>). The optional33// `showValue` hex readout is synced by a 6-line handler in public/site.js keyed34// on data-slot="color-picker"; with showValue={false} it is zero-JS.3536export type ColorSpace = "limited-srgb" | "display-p3"3738const swatchBase =39 // The native <input type=color> styled as a single rounded swatch button.40 "size-9 shrink-0 cursor-pointer rounded-md border border-input bg-transparent p-1 shadow-xs outline-none transition-[color,box-shadow] " +41 "dark:bg-input/30 " +42 "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 " +43// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Autosize Textareaautosize-textarea | shadcn-htmx | Components | Free | no deps |
