SHARE THIS

background-color

The  background-color  property sets the background color of an element and it can only be used as a single  <color>  value.

In CSS, the following color values are the most often used:

  • Keyword Values:
    • These are basic colors that have easy-to-remember names like  red ,  green ,  blue , etc.
    • These colors can have a keyword associated with them, such as  blueviolet ,  cornflowerblue ,  darkgreen , etc. There are about 150 colors with a keyword associated.
  • HEX Values:
    • A hexadecimal color value represents colors using the most common syntax, a six-value syntax beginning with the # symbol like  #ff0000 ,  #00ff00 ,  #0000ff , etc.
    • It is a shorthand for the color model of the primary color components RGB (Red, Green, Blue), where each pair of digits indicates the intensity of red, green, and blue, respectively.
    • A HEX value can be created using the three-value  #f01  which is equivalent to  #ff0011 , four-value  #f01c  which is equivalent to  #ff0011cc , six-value  #ff0011 , and eight-value syntax ( #ff0011cc ), using both uppercase and lowercase letters.
  • RGB Values
    • The  RGB  value is a color model that represents three different channels.
    • The letters  RGB  represent  red ,  green , and  blue , representing mixtures of colors.
    • With the  rgb()  function, a color can be created using three values or numbers, generally between  0.0  and  1.0 , or between  0  and  255 .
    • Each value or number represents the primary colors that define the final color. For example, a black color would be rgb(0, 0, 0) , a white color would be  rgb(255, 255, 255), and a combination of colors would be rgb(231, 204, 68 this creates a type of yellow color that defines the final color.

Syntax

background-color: color;