OKLCH color space for web projects. Convert hex/rgb/hsl to oklch, generate palettes, check contrast, handle gamut boundaries, and theme with Tailwind v4. Triggers on oklch, color conversion, palette generation, contrast ratio, gamut, display p3, design tokens, hue drift, chroma, dark mode colors.
Real-world examples
Live HTML demos for this skill — rendered directly in the page. 4 examples.
- 01
HSL hue drift vs OKLCH
Blue ramp in HSL vs constant-hue OKLCH. Convert steps to oklch H — HSL crosses the 10° drift threshold; OKLCH stays locked.
- 02
9-step palette & multi-hue
Generate a 50–950 scale with even L steps and C as % of max per step. Multi-hue swatches share L and C% for equal vividness; dark mode reverses the mapping.
- 03
Fix contrast with L only
Failing text on a light background — adjust lightness to open the gap. APCA Lc and WCAG ratio update live; chroma and hue stay fixed.
- 04
Gamut clamp & P3 theme
High-chroma colors clip in sRGB — clamp C at constant L/H, then enhance with @media (color-gamut: p3). Tailwind-style @theme tokens in oklch.
Skill markdown
# Colors A color system is a small set of ramps, named by role and verified against the backgrounds they actually render on. Most color bugs are system bugs. A value picked in isolation, a token borrowed because it looked right, a pair nobody measured. Never report a contrast value you did not measure, and never estimate a color you could compute. Colors are one of the few interface concerns with an exact answer, so produce the exact answer. Contrast requirements belong to `better-accessibility`. Surfaces, shadows and icon color belong to `better-ui`. ## Match the project's color system Reuse the project's tokens and notation. A second representation added to fix one value makes the palette harder to reason about. A consistent hex system beats hex with `oklch()` scattered through it. For a new system, `oklch()` is the best default, because its numbers behave the way the ramp rules below describe. Everywhere else, a color library produces the same ramp in the project's own notation ([color-formats.md](color-formats.md)). ## A system is ramps, not colors One neutral ramp, one accent ramp and only the status ramps the product actually renders. A `warning` ramp nothing imports is maintenance for zero pixels. A second accent hue earns its place only when two things must be distinguishable at a glance. ## Every step has a job A ramp is not a gradient to pick from by eye. Each step exists because a role needs it: page background, component hover, border, solid fill, body text. Do not generate a step no role consumes. Both the Tailwind `50`–`950` and Radix `1`–`12` conventions map to those roles ([palette-structure.md](palette-structure.md)). ## Name primitives by hue, semantics by role Primitives name a value (`--blue-500`) and are never applied in a component. Semantic tokens name a job (`--color-text-secondary`), point at a primitive and are the only tier components reference. That seam is what makes theming possible. Without it, dark mode means auditing every usage to work out which meant "the accent" and which just wanted blue ([token-naming.md](token-naming.md)). ## Use a token only in its role Never borrow a token because its value is right today. A separator used as a text color works until borders get lighter, and then the text goes with them. If a role has no token, add the token. ## Hold the hue across the ramp Four properties define a well-formed ramp: - Steps step evenly in *perceived* lightness, not in whatever the format calls lightness. - Hue stays constant end to end. - Vividness peaks mid-ramp and falls off at both ends. - Steps sit denser at the light end than at the dark end. Both ends stop short of pure black and white, which cannot carry hue at all. Use a color library rather than eyeballing it ([palette-generation.md](palette-generation.md)). ## One color, one meaning Use a color for one purpose across the whole interface, treating anything within `15°` of hue as the same color. If the accent means interactive, that hue on static text tells users to click something that is not clickable, and an interactive element rendered neutral misleads just as badly. Color is never the only carrier of meaning, which `better-accessibility` owns. ## Fill exactly one action per view When filled color encodes primary emphasis, one primary action gets it and peers stay neutral. Put the color on the background, not the label. A filled button reads as primary across the room; accent-colored text on a neutral button reads as a link. Several colored backgrounds are fine when they encode distinct states or categories rather than competing as peers. ## Measure the rendered pair, then report Measure a foreground against the background it actually renders on, not the page background. When a pair fails, report the pair, its measured value and the threshold it misses, then leave the colors alone. They are a design decision. Change them only when asked, and remeasure after ([contrast.md](contrast.md)). ## Pick a gradient's interpolation space The space is a look, not a correctness setting. - **`in oklab`** is the best default: even brightness, no hue surprises. - **`in oklch`** travels around the hue wheel rather than through the middle, staying vivid and sweeping every hue between the stops. Reach for it when a two-hue gradient goes gray in the middle. - **The sRGB default** darkens and mutes the midpoint. It is what most interfaces already have, because it is what you get without asking. See [color-usage.md](color-usage.md). ## Before you finish | Mistake | Fix | | --- | --- | | A raw value where the project has a token | Reuse or add the role token, in the project's notation | | An isolated `oklch()` value dropped into a hex codebase | Keep the established notation unless a migration is in scope | | A primitive like `--blue-500` used directly in a component | Point a semantic token at it | | Token named for its appearance (`--color-blue-button`) or first use (`--color-sidebar-gray`) | N …
More from jakubkrehel
- Better TypographyWeb typography from choosing fonts to spacing, wrapping and accessibility. Use when picking or pairing typefaces, configuring variable fonts or OpenType features, setting up a type scale, styling text in components, truncating text, styling underlines, selection, placeholders or carets, or reviewing frontend code for typography. Triggers on typography, fonts, font formats, woff2, variable fonts, font-weight, opentype, font-feature-settings, letter-spacing, line-height, type scale, tabular numbers, text-wrap, truncation, line clamp, underlines, text-decoration, text selection, iOS input zoom, font smoothing, text contrast, measure, line length, text-box, smart punctuation, drop cap.
- Better UIDesign engineering principles for making interfaces feel polished. Use when building UI components, reviewing frontend code, implementing animations, hover states, shadows, borders, micro-interactions, enter/exit animations, or any visual detail work. Triggers on UI polish, design details, "make it feel better", "feels off", stagger animations, border radius, optical alignment, image outlines, box shadows.
- Make Interfaces Feel BetterDesign engineering principles for making interfaces feel polished, with focus on micro-interactions, typography, and visual details.
- OKLCH SkillPractical OKLCH color workflow skill for building consistent, accessible, and tunable color systems in modern UIs.