Skip to main content

CSS Colors

In CSS, you can set a color using a predefined color name, or with an RGB, HEX, HSL, RGBA, or HSLA value.


CSS Color Names

A color can be set using one of the predefined color names.

CSS and HTML support 140 standard color names.

Example

Each box uses a different named color as its background.

Prompt
An HTML page that shows several predefined CSS color names as colored boxes. Make a series of headings, each with a different background color using a named color: Tomato, Orange, DodgerBlue, MediumSeaGreen, Gray, SlateBlue, Violet, and LightGray. Label each box with its color name.
Output: complete HTML page

CSS Background Color

You can set the background color of HTML elements.

Example

The heading and paragraph use named colors for their backgrounds.

Prompt
An HTML page that sets background colors using named colors. Give an <h1> a DodgerBlue background and a <p> a Tomato background, using inline styles with named colors.
Output: complete HTML page

CSS Text Color

You can set the color of the text.

Example

The heading and paragraphs each use a named text color.

Prompt
An HTML page that sets text colors using named colors. Make an <h1> Tomato, one <p> DodgerBlue, and another <p> MediumSeaGreen, using inline styles with named colors.
Output: complete HTML page

CSS Border Color

You can set the color of borders.

Example

Each heading has a solid border in a different named color.

Prompt
An HTML page that sets border colors using named colors. Give three <h1> elements a 2px solid border in Tomato, DodgerBlue, and Violet, using inline styles.
Output: complete HTML page

CSS Color Values

Colors can also be set using RGB, HEX, HSL, RGBA, and HSLA values.

For example, these all give the same color as the name Tomato: rgb(255, 99, 71), #ff6347, and hsl(9, 100%, 64%). The RGBA and HSLA versions add transparency.

Example

The same color is written in several value formats, with the last two at 50% transparency.

Prompt
An HTML page that sets the same color using different CSS color value formats. Make five <h1> elements with background colors written as: rgb(255, 99, 71), #ff6347, hsl(9, 100%, 64%) (all the same "Tomato"), then rgba(255, 99, 71, 0.5) and hsla(9, 100%, 64%, 0.5) (the same color at 50% transparency). Use inline styles.
Output: complete HTML page

Learn more about Color Values

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