Contrast and color scheme
Definition and purpose
Readable color choices require sufficient contrast and non-color cues. color-scheme declares which schemes an element can accommodate so the browser can adjust native UI.
Readable status
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { color: #000; background-color: #fff; } #b { color: #fff; background-color: #000; } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>Opaque black and white give 21:1 contrast.
Syntax and mental model
For ordinary text WCAG AA generally requires 4.5:1 contrast (3:1 for qualifying large text). Compute contrast from relative luminances using (Llighter + .05)/(Ldarker + .05). Set authored foreground and background together; color-scheme: light dark does not recolor arbitrary author declarations. Underline a link or label a status instead of relying only on hue.
Native scheme and link cue
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> :root { color-scheme: light dark; } #a { color: navy; background-color: white; text-decoration: underline; } </style> </head> <body> <a id="a" href="#b">Details</a> <input id="b" aria-label="Search"> </body></html>The scheme is declared for native controls; the link has an explicit light background and underline.
Common mistakes
Do not infer contrast from HSL lightness or a computed color alone. Translucency, gradients and surroundings matter. Browser emulation is not a full accessibility audit.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Current color and system colors. Next lesson: Modern color spaces.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Contrast and color scheme — knowledge check
Five questions on contrast and color scheme.
What is black on white contrast?
What is the usual AA threshold for ordinary text?
What does color-scheme inform?
Which adds a non-color link cue?
What must be evaluated for transparent text backgrounds?