How to use Color in CSS?

CSS Color Property is used for defining the color of the text, background and border.

Color Value can be specified in below formats We will see these formats in more detail.These formats are explained in more detail within the following sections:

CSS Color – Hex Codes

The hex number is prefixed with a hash character (#). It is a six digit notation of a color value( #RRGGBB)
For eg. Hex code for Magenta is #FF00FF

CSS Colors – Short Hex Codes

This is a compressed version of the six-digit notation(#RGB)
For eg. Short Hex code for Magenta now becomes #F0F

CSS color – RGB Values

rgb() property is used to define RGB value. It is denoted by 3 values respectively for Red, Green and Blue. And the value is an integer between 0 to 255. 0 being the lowest and 255 is highest value. It can also be in percentage format
For eg. Magenta is written as rgb(255,0,255) and also can be denoted as rgb(100%,0%,100%)

RGB & hexadecimal values can be taken using any graphical tool like adobe photoshop, advanced paint brush or any color picker like ColorZilla.

While designing colors can be applied to elements by using properties like color, background-color and border-color.

A paragraph with red background with white text and black border could look like this:

  color: #FFFFFF;
  background-color: #FF0000;

Please note all browsers does not support rgb() property, hence it is recommended not to use it.