Tool guides and practical topics/Color, layout and visual design helpersCSS color formats and WCAG contrast: from HEX conversion to the 4.5:1 thresholdSeparate 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 · 2026-11-16The problem and contextA 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 calculationConvert 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 exampleEnter 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.ChecklistHSL 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 checkerOptionsForeground #1F2937Background #F9FAFBSwapLarge text sample Aa 0123456789Body text sample: read every word clearly.Result14.0467:1Contrast ratioCopyFour decimal places are displayed; AA/AAA decisions use the unrounded ratio.AA · normal text · 4.5:1PassAA · large text · 3:1PassAAA · normal text · 7:1PassAAA · large text · 4.5:1PassUse these tools with this articleColor PaletteGenerate 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 GeneratorChoose 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 CheckerChoose six-digit HEX text and background colors, calculate relative luminance, and check AA and AAA thresholds for normal and large text.Color ConverterConvert opaque sRGB colors between HEX, RGB, HSL and HSV, keep round-trip precision, and compare black and white text contrast.Sourceswww.w3.org · 1www.w3.org · 2www.w3.org · 3