Text color
Must contrast strongly with the background.
Color creates hierarchy, emotion and meaning. In CSS, good color work is about contrast, consistency and clear roles.
:root {
--color-text: #f7f9ff;
--color-accent: #8cffc1;
}
Typography & Visual Style
CSS colors can be written as keywords, hex, rgb, hsl and newer color functions. The syntax matters less than the system behind the choices.
A professional interface uses color roles: text, muted text, background, surface, border, accent, success, warning and danger.
Color must also meet contrast needs. A beautiful palette is not good if users cannot read it.
Must contrast strongly with the background.
Draws attention to important actions or highlights.
Communicates success, warning, error or active state.
Named variables keep color usage consistent.
Visual model
Typography and visual style are where CSS starts to feel like design. These models turn subjective choices into reusable decisions you can explain, test and improve.
Primary readable foreground.
Secondary content.
Action and highlight.
Error or destructive state.
Examples
:root {
--color-text: #f7f9ff;
--color-muted: #cfd8e6;
--color-accent: #8cffc1;
--color-danger: #ff5d73;
}
.title { color: #fff; }
.link { color: lime; }
.warning { color: orange; }
.card { background: #111; }
Rules that matter
A beautiful one-off style is not enough. The goal is a visual system that keeps working when the site grows, content changes and new pages are added.
Readable foreground and background pairs matter most.
Use --color-accent, not --green-thing.
If everything is highlighted, nothing is highlighted.
Errors need text, icons or structure too.
Success, warning and danger should not change meaning per page.
A color that works on one surface may fail on another.
Production thinking
Color tells users where to look and what something means. Random colors create visual noise and mistrust.
Contrast and non-color cues are essential. Some users cannot distinguish hue reliably.
Store colors as tokens and document their roles. That makes redesigns and theme work much easier.
Readable contrast improves usability and reduces frustration for visitors from search.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If your answer is vague, change the lab values and judge the visual result again.
Senior audit upgrade
A color system is not finished until text contrast, state meaning and non-color indicators are checked.
Check foreground and background pairs, especially muted text and button text.
Error and success states need text, icon, label or shape in addition to color.
Prefer --color-danger over --red when the token carries meaning.