CSS color formats and WCAG contrast: from HEX conversion to the 4.5:1 threshold

Separate HEX, RGB, HSL and HSV, calculate text contrast under WCAG 2.2, and use gray boundary examples to see why rounding cannot change a pass decision.

Content reviewed ·

The problem and context

A new CSS Color 4 Candidate Recommendation Draft was published on November 12, 2026. HSL in a design file, RGB in a stylesheet and HSV in a color editor often share a workflow. Converting those representations preserves a color; readable text depends on the foreground and background together.

Method and calculation

Convert the colors to opaque six-digit HEX, then calculate their relative luminance and contrast ratio. WCAG AA requires at least 4.5:1 for normal text and 3:1 for large text; AAA requires 7:1 and 4.5:1 respectively. Compare the original ratio with the threshold before formatting it for display.

Worked example

Enter hsv(360, 100%, 100%) in the converter to obtain #FF0000: hue 360° returns to the same red as 0°. Compare #777777 with #FFFFFF for about 4.4781:1, which fails normal-text AA. Changing the gray to #767676 yields about 4.5422:1 and passes that threshold.

Checklist

HSL lightness and WCAG relative luminance describe different quantities; HSV value also does not measure readability. Composite transparent text over the actual background, and check each area crossed by text on a gradient or image. Large text means at least 18pt or 14pt bold; consider the actual font weight when selecting the final pair.

WCAG contrast checker

Options

Large text sample Aa 0123456789

Body text sample: read every word clearly.

Result

14.0467:1Contrast ratio

Four decimal places are displayed; AA/AAA decisions use the unrounded ratio.

AA · normal text · 4.5:1
Pass
AA · large text · 3:1
Pass
AAA · normal text · 7:1
Pass
AAA · large text · 4.5:1
Pass

Use these tools with this article

  • Color Palette

    Generate six swatches from one base: original, lighter, darker, complement and two analogous colors at hue offsets of ±30°. Every swatch shows a six-digit HEX value with its own copy button.

  • Gradient Generator

    Choose two six-digit HEX colors and a direction from 0 to 360° to preview a linear gradient. Copy supplies a complete background: linear-gradient(...) declaration for CSS.

  • Contrast Checker

    Choose six-digit HEX text and background colors, calculate relative luminance, and check AA and AAA thresholds for normal and large text.

  • Color Converter

    Convert opaque sRGB colors between HEX, RGB, HSL and HSV, keep round-trip precision, and compare black and white text contrast.

Sources