HTML Colors

You can set colors by name, by HEX code, or with RGB values.

All three formats describe the same colors, so pick whichever is easiest to read. Names are quick for common colors, while HEX and RGB give you millions of shades.

Three Ways to Name a Color

FormatExampleNotes
NametomatoAbout 140 names are built in
HEX#ff6347Red, green, blue in base 16
RGBrgb(255, 99, 71)Red, green, blue from 0 to 255

Text Color

Coloring text

<!DOCTYPE html>
<html>
<body>

<h1 style="color:tomato;">A colorful heading</h1>

</body>
</html>

Background Color

HEX background

<!DOCTYPE html>
<html>
<body>

<div style="background-color:#9ce56d; padding:10px;">Green background</div>

</body>
</html>
Note: HEX codes are the most common format you will see in real projects and design tools.

Exercise: HTML Colors

Which of these correctly specifies a color using RGB values?