CSS Color Keywords
1 April 2025 | Category: CSS
CSS provides a wide range of color keywords that can be used to style elements on your webpage. These keywords represent predefined colors that can be directly used in your CSS without needing to specify the RGB or HEX values. They are part of the CSS standard and can be used for text color, background color, border color, and other styling purposes.
🔹 1. What Are CSS Color Keywords?
CSS color keywords are predefined names that represent colors. These keywords can be used in CSS properties like color
, background-color
, border-color
, and more, instead of using hex codes, RGB values, or other color formats.
Example:
p {
color: red;
background-color: lightblue;
}
List of Common Color Keywords:
CSS provides a total of 140 predefined color keywords. Here’s a breakdown of some of the most commonly used ones.
🔹 2. Basic Color Keywords
These are the most basic color names available in CSS:
Keyword | Color Represented |
---|---|
black | Black (#000000) |
white | White (#FFFFFF) |
red | Red (#FF0000) |
green | Green (#008000) |
blue | Blue (#0000FF) |
yellow | Yellow (#FFFF00) |
gray | Gray (#808080) |
silver | Silver (#C0C0C0) |
maroon | Maroon (#800000) |
navy | Navy (#000080) |
🔹 3. Shades of Colors
CSS also provides color names for various shades of colors.
Keyword | Color Represented |
---|---|
lightgray | Light Gray (#D3D3D3) |
darkgray | Dark Gray (#A9A9A9) |
lightblue | Light Blue (#ADD8E6) |
darkblue | Dark Blue (#00008B) |
lightgreen | Light Green (#90EE90) |
darkgreen | Dark Green (#006400) |
lightred | Light Red (#FF6666) |
darkred | Dark Red (#8B0000) |
🔹 4. Extended Color Keywords
In addition to basic and shades of colors, CSS has several extended color names representing different hues and tones.
Keyword | Color Represented |
---|---|
aqua | Aqua (#00FFFF) |
fuchsia | Fuchsia (#FF00FF) |
lime | Lime (#00FF00) |
olive | Olive (#808000) |
purple | Purple (#800080) |
teal | Teal (#008080) |
pink | Pink (#FFC0CB) |
brown | Brown (#A52A2A) |
orange | Orange (#FFA500) |
cyan | Cyan (#00FFFF) |
🔹 5. CSS Color Keywords in Use
These color keywords can be used in many different places in your CSS code. Some examples of using CSS color keywords are:
Example 1: Changing Text Color
p {
color: green; /* Sets the text color to green */
}
Example 2: Background Color
div {
background-color: lightblue; /* Sets the background color to light blue */
}
Example 3: Border Color
button {
border: 2px solid red; /* Sets the border color to red */
}
Example 4: Hover Effects
a:hover {
color: fuchsia; /* Changes the link color to fuchsia on hover */
}
🔹 6. CSS Color Keywords vs Other Color Formats
While color keywords are convenient, they might not offer the same level of flexibility or precision as other color formats like RGB
, RGBA
, HEX
, or HSL
. Here’s a quick comparison:
Method | Example | Description |
---|---|---|
color keyword | color: red; | Easy to use, but limited to predefined colors. |
HEX | color: #FF0000; | Precise color definition using a 6-digit code. |
RGB | color: rgb(255, 0, 0); | Defines color using Red, Green, Blue channels. |
RGBA | color: rgba(255, 0, 0, 0.5); | Adds transparency (alpha) to the RGB format. |
HSL | color: hsl(0, 100%, 50%); | Defines color using Hue, Saturation, and Lightness. |
Why Use Color Keywords?
- Ease of Use: Color keywords are simple and easy to understand.
- Readability: For basic projects, using color keywords can make your code more readable and maintainable.
- Quick Styling: It’s faster to use
color: red;
rather thancolor: #FF0000;
.
🔹 7. Limitations of CSS Color Keywords
While CSS color keywords are convenient, they are somewhat limited in the range of colors they offer. They don’t provide as much flexibility as rgb()
, rgba()
, hsl()
, or hex
values, especially if you need more precise color control.
If you want to create a custom color that is not part of the predefined keywords, you’ll need to use other methods like rgb()
, rgba()
, hsl()
, or hex
.
🔹 8. Conclusion
CSS color keywords are an easy and convenient way to apply colors to elements without needing to memorize or use specific color codes. They are simple, intuitive, and provide a quick way to apply basic colors for text, backgrounds, borders, and more. However, for more precise control over colors and for defining more complex designs, you may need to use other color formats like rgb()
, rgba()
, hsl()
, or hex
.
Using color keywords effectively can improve the readability and maintainability of your CSS, especially when working with standard colors. Just be mindful of the limitations and know when to switch to more flexible color representations based on your design requirements.