tutorialstonight logo
A Platform To Learn To Code

CSS COLOR



Color values in CSS is used to specify colors to HTML elements.Generally this property is used to specify color of text.

Example:

Red
Green
Blue
Gold
Sienna

Example

Run the code

Defining CSS color

CSS provides us various methods by which we can define color values.

The three main methods to define colors in CSS are:

  1. RGB value
  2. HEX value
  3. HSL value



1).RGB value

One of the ways to define color in CSS is RGB value.color value can be specified using rgb() property.

rgb(red,green,blue)

rgb() property is defined by setting three numerical values separated by commas in this property.Each define value for red,green and blue.

Example:

Example

Run the code

2).HEX value

Another way to define color in CSS is HEX value.color in HEX() is defined using hexadecimal value.

Color is defined as #rrggbb() where rr represent color red,gg represent color green and bb represent color blue.

Example:

Example

Run the code

3).HSL value

It is also a way to define color in CSS.color value can be specified using hsl() property.

hsl() property is defined by setting three values separated by commas in this property.

hsl(hue,saturation,lightness)

In hsl() property hue defines color.Its degree on color wheel 0 is red,120 is green and 240 is blue.saturation is shade of gray in percentage value 0% means gray shade 100% means full color.lightness is also percentage value where 0% is black,50% is nothing and 100% is white.

Example:

Example

Run the code