Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

color — foreground color

The color property sets the foreground color, usually for text. It is inherited and determines the color used by currentcolor.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

color: <color>;

color sets an element’s foreground color, usually its text fill. It accepts <color>, such as a name, hexadecimal notation, or rgb().

The property is inherited. Its initial value is the system color CanvasText, not necessarily black. color does not set the background; use background-color for that.

In other properties, currentcolor refers to the same element’s color. In color: currentcolor, it resolves to the inherited color. In the example, span inherits green text, while the border uses currentcolor.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>color</title>
<style>
  p {
    color: #006633;
    background-color: white;
    border: 2px solid currentcolor;
    padding: 8px;
  }
</style>
<p>Parent <span>child</span></p>
</html>

Result

Parent child — green text and a green border on a white background.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources