Colors in CSS are used to style elements, such as text, backgrounds, borders, and more. CSS supports multiple ways to define colors, making it flexible for designing web pages.
CSS provides 147 predefined color names like red
, blue
, green
, etc.
p {
color: red;
}
Example Colors | Preview |
---|---|
red | π΄ |
blue | π΅ |
green | π’ |
yellow | π‘ |
black | β« |
white | βͺ |
A HEX code starts with #
and uses six characters (0-9, A-F) to define colors.
h1 {
color: #ff5733; /* Orange shade */
}
π‘ HEX Format: #RRGGBB
(Red, Green, Blue)
HEX Code | Color Preview |
---|---|
#000000 |
β« (Black) |
#FFFFFF |
βͺ (White) |
#FF0000 |
π΄ (Red) |
#00FF00 |
π’ (Green) |
#0000FF |
π΅ (Blue) |
RGB values range from 0-255
for each color.
body {
background-color: rgb(255, 165, 0); /* Orange */
}
π‘ RGB Format: rgb(Red, Green, Blue)
RGB Value | Color Preview |
---|---|
rgb(255, 0, 0) |
π΄ (Red) |
rgb(0, 255, 0) |
π’ (Green) |
rgb(0, 0, 255) |
π΅ (Blue) |
rgb(255, 255, 0) |
π‘ (Yellow) |
The A (Alpha) value controls transparency (0
= fully transparent, 1
= fully visible).