CSS Colors

CSS supports various color formats to specify colors for elements.

Keyword Colors:

CSS provides a set of predefined color keywords.

Example:

color: white;
background-color: blue;

Hexadecimal Colors:

Example:

color: #ffffff; /* White */
background-color: #0000ff; /* Blue */

Hexadecimal notation represents colors using six hexadecimal digits, where pairs of digits represent the intensity of red, green, and blue (RGB) components.

Example:

color: rgb(255, 255, 255); /* White */
background-color: rgb(0, 0, 255); /* Blue */

RGB Colors:

Example:

color: rgba(0, 0, 0, 0.5); /* Black with 50% transparency */
background-color: rgba(0, 0, 255, 0.2); /* Blue with 20% transparency */

RGB (Red, Green, Blue) notation specifies colors using the intensity of each of the three primary colors.

Example:

color: tomato;
background-color: azure;

RGBA Colors:

Example:

color: hsl(0, 100%, 50%); /* Red */
background-color: hsl(240, 100%, 50%); /* Blue */

RGBA is similar to RGB, but includes an alpha channel for transparency.

Named Colors:

CSS provides a set of named colors that can be used directly.

HSL Colors:

HSL (Hue, Saturation, Lightness) notation defines colors based on their hue, saturation, and lightness.