HTML Colors
HTML colors are written using CSS color values. The browser accepts several formats — pick the one that's most readable for the color you need.
Color value formats
| Format | Example | When to use |
|---|---|---|
| Named color | green | ~140 keywords. Quick and readable. |
| Hex | #04AA6D | Most common in design tools. |
| Short hex | #0A6 | Three-digit shorthand for matched pairs. |
| RGB | rgb(4, 170, 109) | When values come from code or a picker. |
| RGBA | rgba(4, 170, 109, 0.5) | When you need transparency. |
| HSL | hsl(155, 95%, 34%) | Tweak hue, saturation, lightness directly. |
Sample palette
Tip: For accessibility, check contrast between text and background. WCAG AA needs at least 4.5:1 for normal text.
Example
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors</title>
</head>
<body>
<h1>HTML Colors</h1>
<p>This is a demo page for the "HTML Colors" lesson.</p>
</body>
</html>
Try it Yourself »
Exercise
Use the hex code for pure white as the text color.
<p style="color:
;">White text</p>
Three or six F characters preceded by #.
Discussion
Loading…