Skip to main content

HTML Colors

HTML colors can be set with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values.


Color Names

A color can be set using a color name. HTML supports 140 standard color names.

Example

Several colors shown by name.

Prompt
A page showing several CSS color names as colored blocks: Tomato, Orange, DodgerBlue, MediumSeaGreen, Gray, SlateBlue, Violet, and LightGray, each block filled with its own color.
Output: complete HTML page

Background Color

You can set the background color of HTML elements with the background-color property.

Example

A heading and paragraph with colored backgrounds.

Prompt
A page setting background color with color names: an h1 with a DodgerBlue background reading "Hello World" and a paragraph with a Tomato background of lorem ipsum text.
Output: complete HTML page

Text Color

You can set the color of text with the color property.

Example

A heading and paragraphs in different text colors.

Prompt
A page setting text color with color names: a Tomato h1 "Hello World" and two paragraphs of lorem ipsum colored DodgerBlue and MediumSeaGreen.
Output: complete HTML page

Border Color

You can set the color of borders with the border property.

Example

Headings with borders in different colors.

Prompt
A page setting border color with color names: three h1 headings each reading "Hello World" with a 2px solid border in Tomato, DodgerBlue, and Violet.
Output: complete HTML page

Color Values

Colors can also be set with RGB, HEX, HSL, RGBA, and HSLA values. RGB, HEX, and HSL all describe the same color in different ways. RGBA and HSLA add an Alpha channel, which sets transparency (for example, 50% see-through).

Example

The same color set with RGB, HEX, HSL, and the transparent RGBA and HSLA forms.

Prompt
A page showing the same color set as a background using different value formats: RGB rgb(255, 99, 71), HEX #ff6347, HSL hsl(9, 100%, 64%), plus RGBA and HSLA versions at 50% transparency.
Output: complete HTML page

Learn more about Color Values

You will learn more about RGB, HEX, and HSL in the next chapters.