CSS hsl() / oklch() String Builder

Build valid CSS hsl() or oklch() color function strings

Ad placeholder (leaderboard)

Hand-writing CSS color functions is error-prone: it is easy to forget a percent sign, mix up comma and space syntax, or push a channel out of its legal range. This builder produces a guaranteed-valid hsl() or oklch() string from plain numeric inputs and shows a live swatch so you can see the result before pasting.

How it works

Each channel is clamped to the range the CSS specification allows, then the string is assembled in modern space-separated syntax:

hsl()   →  hsl(<hue> <sat>% <light>% [/ <alpha>])
oklch() →  oklch(<L 0–1> <C 0–0.4> <hue> [/ <alpha>%])

For hsl() the saturation and lightness carry percent signs and hue is in degrees. For oklch() the lightness is a 0–1 number, chroma is an unbounded positive number (practically capped near 0.4 inside sRGB), and hue is in degrees. The alpha part is only emitted when opacity is below 100 percent.

Example and tips

Setting hue 210, saturation 80, lightness 55 yields hsl(210 80% 55%), a clean sky blue. Switching to oklch() with L 0.7, C 0.15, hue 250 gives a perceptually even blue that keeps its apparent brightness if you later rotate the hue. When targeting older browsers, place an hsl() or hex declaration before the oklch() one as a fallback — unsupported engines will simply ignore the line they cannot parse.

Ad placeholder (rectangle)