Colors¶
CSS allows you to style elements with different colors for text, backgrounds, borders, and more.
1. Color Properties¶
Text Color¶
p {
color: red;
}
Background Color¶
div {
background-color: #f0f0f0;
}
Border Color¶
input {
border: 1px solid #333;
}
2. Color Formats¶
a) Named Colors¶
Predefined color names.
h1 {
color: blue;
}
b) Hexadecimal¶
p {
color: #ff0000; /* red */
}
c) RGB¶
div {
background-color: rgb(255, 255, 255);
}
d) RGBA (with transparency)¶
div {
background-color: rgba(0, 0, 0, 0.5);
}
e) HSL¶
Hue, Saturation, Lightness.
h2 {
color: hsl(240, 100%, 50%);
}
f) HSLA (with alpha)¶
section {
background-color: hsla(120, 100%, 50%, 0.3);
}
3. Transparent Keyword¶
div {
background-color: transparent;
}