CSS provides multiple ways to apply colors to text, backgrounds, borders, and other elements on a webpage. Colors help improve the visual appearance and readability of your design. CSS supports a wide range of color formats, giving developers flexibility based on their design needs.
CSS includes around 140 predefined color names such as:
p{
color:blue;
}
HEX values represent colors using a hexadecimal code.
h1 {
color: #ff5733; /* orange-red */
}
h1 {
color: #f53;
}
RGB stands for Red, Green, Blue. Each value ranges from 0 to 255.
p {
color: rgb(120, 80, 200);
}
Similar to RGB, but includes an alpha (opacity) value (0.0 – 1.0).
div {
background-color: rgba(0, 0, 0, 0.5); /* semi-transparent */
}
HSL stands for Hue, Saturation, and Lightness.
p {
color: hsl(200, 70%, 50%);
}
HSL with an alpha transparency value.
button {
background: hsla(150, 60%, 40%, 0.6);
}
This keyword uses the current text color for other properties.
div {
color: darkblue;
border: 2px solid currentColor;
}
Used to make an element fully transparent.
.box {
background-color: transparent;
}