learn2kode.in

CSS Colors

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.

1. Color Names

CSS includes around 140 predefined color names such as:

Example

2. HEX Colors

HEX values represent colors using a hexadecimal code.

Example

h1 {
  color: #ff5733; /* orange-red */
}

Short version (3 digits):

3. RGB Colors

RGB stands for Red, Green, Blue. Each value ranges from 0 to 255.

p {
  color: rgb(120, 80, 200);
}

4. RGBA Colors

Similar to RGB, but includes an alpha (opacity) value (0.0 – 1.0).

div {
  background-color: rgba(0, 0, 0, 0.5); /* semi-transparent */
}

5. HSL Colors

HSL stands for Hue, Saturation, and Lightness.

p {
  color: hsl(200, 70%, 50%);
}

6. HSLA Colors

HSL with an alpha transparency value.

button {
  background: hsla(150, 60%, 40%, 0.6);
}

7. CurrentColor Keyword

This keyword uses the current text color for other properties.

div {
  color: darkblue;
  border: 2px solid currentColor;
}

8. Transparent Keyword

Used to make an element fully transparent.

.box {
  background-color: transparent;
}