iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

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

FormatExampleWhen to use
Named colorgreen~140 keywords. Quick and readable.
Hex#04AA6DMost common in design tools.
Short hex#0A6Three-digit shorthand for matched pairs.
RGBrgb(4, 170, 109)When values come from code or a picker.
RGBArgba(4, 170, 109, 0.5)When you need transparency.
HSLhsl(155, 95%, 34%)Tweak hue, saturation, lightness directly.

Sample palette

#04AA6D #2965F1 #E44D26 #ffd333 #777BB4 #282a35
Fig 1. Hex codes for the colors used across this site.
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>

Test yourself

Q1. Which is a valid HTML color value?
Q2. Named colors include about…
Q3. Add transparency with…

Discussion

Loading…