Contrast Picker

Contrast Picker is a copy-paste React component that stops unreadable text colour shipped before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/contrast-picker
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsUnreadable text colour shipped

Was this component page useful?

How do I install Contrast Picker?

pnpm dlx shadcn@latest add @bollard/contrast-picker

The files land in your project. They're yours to edit.

How do I use Contrast Picker in React?

contrast-picker-usage.tsx
import { ContrastPicker } from "@/components/ui/contrast-picker"

return <ContrastPicker defaultValue={{ foreground: "#777777", background: "#ffffff" }} />

What input mistakes does Contrast Picker catch?

  • Ratios just under a threshold that rounding would hide (4.499 shown as 4.49, a fail)
  • Failures for normal text versus large text, at AA and AAA
  • A nearest passing colour that keeps the hue

What props does Contrast Picker accept?

ContrastPicker props
PropTypeDefault
value

Controlled pair.

ColorPair—
defaultValue

Initial pair when uncontrolled.

ColorPair{ foreground: "#777777", background: "#ffffff" }
onValueChange

Called with the pair on every change, including one-tap fixes.

(value: ColorPair) => void—
level

WCAG level the warning and fixes aim for.

"AA" | "AAA""AA"
textSize

Whether the pair is used for body text or large text (24px, or 18.66px bold).

"normal" | "large""normal"
foregroundLabel

Label of the text colour.

string"Text"
backgroundLabel

Label of the background colour.

string"Background"
bodyLabel

Short name of normal-size text in the badges.

string"body"
largeLabel

Short name of large text in the badges.

string"large"
previewText

Sample text in the preview.

string"Your order has shipped"
failMessage

Builds the warning shown when the pair falls short.

(level: string, size: string, needed: number) => string(lvl, size, needed) => `Fails ${lvl} for ${size === "norm…
fixPrefix

Start of the fix buttons' accessible names ("Use #767676 for text").

string"Use"

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

How is Contrast Picker accessible?

  • Labelled colour fields with aria-invalid on unreadable values; swatches have aria-labels
  • The ratio has an aria-label ("Contrast ratio 4.47 to 1")
  • Pass/fail is written in words ("fails, needs 4.5:1") plus icons
  • Warnings are aria-live="polite"

Only what the source does. Test with your own screen reader and content before shipping.

What are the limitations and server boundaries?

  • Uses the WCAG 2 formula; it is not an APCA (WCAG 3 draft) checker
  • Checks solid colours only, not text over images, gradients or transparency
  • Readability also depends on font weight and size, which it does not measure

What validation rules apply to Contrast Picker?

Rules last verified:

Informational. Checked thresholds: AA 4.5:1 normal / 3:1 large; AAA 7:1 normal / 4.5:1 large. Copied components don't update themselves, so re-check after rule changes (see updating a component).

What expensive mistakes does Contrast Picker stop?

Unreadable text colour shipped

Also known as

contrast · wcag · color picker · accessibility · a11y · aa aaa · theme · brand color

Field type

What dependencies does Contrast Picker require?

Contrast Picker facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameContrast Picker
Registry identifier@bollard/contrast-picker
Install commandnpx shadcn@latest add @bollard/contrast-picker
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Contrast Picker

What form validation mistake does Contrast Picker catch?

Contrast Picker prevents unreadable text colour shipped. Shows the WCAG contrast ratio of a text and background pair, never rounded up, and offers the nearest passing colour, so unreadable text doesn't ship. Catches: Ratios just under a threshold that rounding would hide (4.499 shown as 4.49, a fail), Failures for normal text versus large text, at AA and AAA, A nearest passing colour that keeps the hue. Limitation: validate contrast-picker schemas on backend.

How do I install contrast-picker with shadcn?

Run `npx shadcn@latest add @bollard/contrast-picker`. Sources added: registry/default/contrast-picker/contrast-picker.tsx, registry/default/contrast-picker/contrast.ts. Package requirements: lucide-react.

What props customize Contrast Picker?

Contrast Picker accepts `value`, `defaultValue`, `onValueChange`, `level`, `textSize`. Configures contrast, wcag, color picker behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of contrast-picker?

Uses the WCAG 2 formula; it is not an APCA (WCAG 3 draft) checker. Checks solid colours only, not text over images, gradients or transparency. Readability also depends on font weight and size, which it does not measure Server requirement: backend verification for contrast-picker.

How does Contrast Picker meet accessibility guidelines?

Labelled colour fields with aria-invalid on unreadable values; swatches have aria-labels. The ratio has an aria-label ("Contrast ratio 4.47 to 1"). Pass/fail is written in words ("fails, needs 4.5:1") plus icons. Warnings are aria-live="polite". Minimizes errors: color contrast fails wcag, contrast ratio checker.

Which components pair with Contrast Picker?