CSS color Property

CSS color property specifies the color of the text.

The color value can be specified in any valid CSS color format such as ‘color name’, ‘HEX’, ‘RGB’, ‘HSL’, etc.

The example below sets different text colors for the <h1>, <h2> and <p> tags.

Example:

h1{
  color: red;
}
h2{
  color: #0000ff;
}
p{
  color: rgb(240, 12, 217);
}

CSS Syntax

The color property has the below syntax:

color: color|initial|inherit;

Property Values

The color property accepts the following values:

colorSpecifies the color of the text in any valid CSS color format such as ‘color name’, ‘HEX’, ‘RGB’, ‘HSL’, etc.
initialSets the color property to its default value.
inheritInherits the color value from its parent element.

General Info

Default ValueDepends on browser
InheritedYes
JavaScript Usageelement.style.color = “red”

Author

  • Manoj Kumar

    Hi, My name is Manoj Kumar. I am a full-stack developer with a passion for creating robust and efficient web applications. I have hands-on experience with a diverse set of technologies, including but not limited to HTML, CSS, JavaScript, TypeScript, Angular, Node.js, Express, React, and MongoDB.

    View all posts

Leave a Comment