Skip to main content

CSS Color Keywords

A few predefined color keywords have a special meaning in CSS, and properties like color, background-color, and border-color accept them.

There are three of these keywords:

  • transparent
  • currentcolor
  • inherit

The transparent Keyword

Elements often get a see-through background color from the transparent keyword, which turns any color fully see-through.

Note: Writing transparent gives the same result as rgba(0,0,0,0). What RGBA color values add to RGB color values is an alpha channel, and that channel sets how opaque a color is. Our CSS RGB chapter and our CSS Colors chapter go further.

Example

Here the background image shows through the <div> element, since its background color is fully transparent.

Prompt
Create a page with a body that has a background image (use "paper.gif") and a div element with a transparent background color, showing that the background image shows through.
Output: complete HTML page

The currentcolor Keyword

Think of currentcolor as a variable: it holds whatever value the color property of an element has right now.

Reach for it when one specific color should stay consistent throughout a page, or within a single element.

Border with currentcolor

The text color of this <div> element is blue, so its border color turns blue as well.

Prompt
Create a page with a div that has its text color set to blue and a 10px solid border using the currentcolor keyword, so the border matches the text color.
Output: complete HTML page

Background with currentcolor

Whatever color the body element currently has also fills the <div> here, as its background.

Prompt
Create a page where the body has its color set to purple, and a div uses currentcolor as its background color, inheriting the purple from the body element.
Output: complete HTML page

Shadow with currentcolor

This <div> takes both its border color and its shadow color from the color currently set on the body element.

Prompt
Create a page where the body color is green, and a div uses currentcolor for both its box-shadow (0px 0px 15px) and a 5px solid border.
Output: complete HTML page

The inherit Keyword

A property set to inherit takes its value from the parent element.

Any CSS property can use this keyword, and so can any HTML element.

Example

Here the parent element passes its border settings down to the <span> element.

Prompt
Create a page with a div that has a 2px solid red border, and a span inside it that inherits the border using the inherit keyword.
Output: complete HTML page