CSS Color Property

The color property in CSS is used to set the color of text content within an HTML element.

Example

/* Setting the text color of paragraphs to blue */
p {
  color: blue;
}

/* Setting the text color using RGB values */
h1 {
  color: rgb(255, 0, 0); /* Red color */
}


Color types

  • Color Names : Keywords such as red, blue, green, etc.

  • Hex Codes : Six-digit hexadecimal color codes (#RRGGBB).

  • RGB/RGBA Values : Red, Green, Blue, and optional Alpha channel values (rgb() or rgba()).

  • HSL/HSLA Values : Hue, Saturation, Lightness, and optional Alpha channel values (hsl() or hsla()).