CSS Color Values
Learn different ways to define colors in CSS using color names, HEX, RGB, and RGBA values.
What are CSS Color Values?
CSS allows us to define colors in different formats.
These values can be used with properties such as
color and
background-color.
The most common color formats are: Color Names, HEX, RGB, and RGBA.
How CSS Color Values Work
HTML Element
h1, p, div
CSS Color Value
red
#ff0000
rgb(255, 0, 0)
rgba(255, 0, 0, 0.5)
Browser
Displays the selected color
1. Color Name
CSS provides predefined color names such as
red, blue,
green, and orange.
h1 {
color: red;
}
Output
WELCOME TO CIIT TRAINING INSTITUTE 🌍🤓..!
2. HEX Color
HEX represents a color using hexadecimal values.
A HEX color normally starts with #.
For example,
#ff0000 represents red.
h1 {
color: #ff0000;
}
Output
HEX Color Example
3. RGB Color
RGB stands for Red, Green, Blue.
Each value normally ranges from
0 to 255.
h1 {
color: rgb(0, 128, 0);
}
Output
RGB Color Example
4. RGBA Color
RGBA is similar to RGB, but it also supports transparency using the Alpha value.
The Alpha value ranges from
0 to 1.
-
0= completely transparent -
0.5= 50% transparent -
1= completely visible
div {
background-color: rgba(255, 0, 0, 0.5);
padding: 20px;
}
Output
Common CSS Color Formats
Color Name
red
Uses a predefined CSS color name.
HEX
#ff0000
Represents the same red color using hexadecimal notation.
RGB
rgb(255, 0, 0)
Defines red, green and blue values.
RGBA
rgba(255, 0, 0, 0.5)
Adds transparency using Alpha.
Color Name, HEX, and RGB can represent the same color in different formats. RGBA additionally allows you to control transparency.
Summary
CSS color values can be defined using color names, HEX values, RGB values, and RGBA values. Each method provides a different way to specify colors in CSS.