color

Term side of the Card.
Topic: Text Handling
Unit title: color
Categories: Property
Explanation side of the Card

Explanation: The property that sets the color of text in an element. It applies to the content of the element, including text, borders and other inline elements and can be defined using color keywords, hexadecimal values, RGB, HSL or other color functions.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wrongcss
.btn {
  color: #0a66c2;
  border: 1px solid #0a66c2;
}
.btn svg {
  fill: #0a66c2;
}
Rightcss
.btn {
  color: #0a66c2;
  border: 1px solid currentcolor;
}
.btn svg {
  fill: currentcolor;
}

currentcolor reuses the text color, so one change to color updates the border and icon too.

Common mistakes

  • Light gray text on white looks clean but fails contrast checks.
  • Link color doesn't change because the browser's default a styles override inherited color.

Key points

  • Text and background colors are set together and meet contrast requirements for body text.
  • Icons, borders and SVG fills that match the text use currentcolor instead of repeating the value.
  • Colors come from custom properties or tokens, not hardcoded hex values in every rule.

Interview questions

Is the color property inherited?

Yes. Children use the parent's color unless they set their own, but links and form controls have their own browser defaults.

How do I change the color of an SVG icon with CSS?

For inline SVG, set fill: currentcolor on the icon and change color on the parent.

Does color change the background?

No. color sets the text and currentcolor; use background-color for the background.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy