CSS color refers to the specification and application of color in web design using Cascading Style Sheets (CSS). CSS allows you to set the color of text, backgrounds, borders, and other elements on a webpage. There are several ways to define colors in CSS:
Named Colors
CSS includes a set of named colors that can be used directly. For example:
color: red;
Hexadecimal Colors
Colors can be defined using hexadecimal (hex) values, which start with a #
followed by six hexadecimal digits. The first two digits represent the red component, the next two represent green, and the last two represent blue. For example:
color: #ff0000; /* red */
RGB and RGBA Colors
Colors can be specified using the rgb()
or rgba()
functions. The rgb()
function takes three parameters (red, green, and blue), each ranging from 0 to 255. The rgba()
function includes an additional parameter for alpha (opacity) which ranges from 0 (completely transparent) to 1 (completely opaque). For example:
color: rgb(255, 0, 0); /* red */
HSL and HSLA Colors
Colors can also be defined using the hsl()
or hsla()
functions. The hsl()
function takes three parameters: hue (0-360), saturation (0%-100%), and lightness (0%-100%). The hsla()
function adds an alpha parameter for opacity. For example:
color: hsl(0, 100%, 50%); /* red */