CSS Color Keywords

Using named colors and special keywords in CSS

🏷️ Named Colors in CSS

CSS provides 147 named colors that you can use by name instead of codes. Plus special keywords like transparent, currentColor, and inherit.


/* Using color keywords */
.header { 
    background-color: steelblue; 
    color: white;
}
.button { 
    background-color: tomato; 
    border: 2px solid darkred;
}
                                    

Output:

Header with steelblue background

Popular Color Keywords

🔴

Red Shades

Various red color names

red, crimson, tomato, coral
🔵

Blue Shades

Different blue variations

blue, navy, steelblue, skyblue
🟢

Green Shades

Nature-inspired greens

green, forestgreen, lime, olive

Neutral Colors

Grays and earth tones

black, gray, silver, white

🔹 Common Named Colors

CSS provides a wide range of common named colors, such as red, blue, green, purple, orange, and teal, which offer quick, human-readable alternatives to hexadecimal or RGB values. These keywords are especially useful for prototyping, learning, or when an exact color match isn't critical. While less precise than numerical values, they cover a broad spectrum of basic needs. For example, background-color: lightgray; is instantly understandable. Using named colors can speed up initial development and make stylesheets more readable for beginners, though for brand consistency in production, numerical color values are typically preferred to ensure exact matching across all browsers and devices.

/* Popular named colors */
.red-text { color: red; }
.blue-bg { background-color: blue; }
.green-border { border: 3px solid green; }

/* More specific names */
.tomato-bg { background-color: tomato; }
.steelblue-text { color: steelblue; }
.coral-border { border: 2px solid coral; }
.forestgreen-bg { background-color: forestgreen; }

Output:

Red text
Blue background
Green border
Tomato background
Steelblue text

🔹 Special Color Keywords

CSS provides special dynamic color keywords like currentColor, transparent, and system colors (e.g., Canvas, ButtonText) for advanced, context-aware styling. The currentColor keyword uses the element's current color value, creating harmonious designs. Transparent creates a fully transparent color. System colors respect the user's OS theme, enhancing accessibility and dark/light mode support. These keywords enable more maintainable and adaptive designs by creating relationships between properties or deferring to user preferences. They are powerful tools for creating themable components, reducing code duplication, and building interfaces that are inherently more accessible and user-friendly.

/* Special keywords */
.transparent-bg { 
    background-color: transparent; 
    border: 2px solid black;
}

.current-color { 
    color: blue;
    border: 2px solid currentColor; /* Uses the text color */
}

.inherited { 
    color: inherit; /* Inherits parent's color */
}

Output:

Transparent background
Current color border matches text
Parent with green text
Child inherits green color

🔹 Color Palette Examples

Creating beautiful, accessible color schemes using named colors involves selecting harmonious combinations for backgrounds, text, and accents that maintain sufficient contrast. For example, a palette might use darkblue for headings, slategray for body text on a whitesmoke background, with coral as an accent for links and buttons. Tools and an understanding of color theory help ensure accessibility (WCAG guidelines). While named colors offer convenience, for production-grade palettes, designers often finalize with precise HSL or RGB values to guarantee consistency. Well-defined palettes strengthen brand identity, guide user attention, and create a cohesive visual experience across an entire website or application.

/* Ocean theme */
.ocean-card {
    background-color: lightcyan;
    border: 2px solid steelblue;
    color: darkslategray;
}

/* Sunset theme */
.sunset-card {
    background-color: peachpuff;
    border: 2px solid coral;
    color: darkred;
}

/* Forest theme */
.forest-card {
    background-color: lightgreen;
    border: 2px solid forestgreen;
    color: darkgreen;
}

Output:

Ocean Theme Card
Sunset Theme Card
Forest Theme Card

🔹 Complete Color Reference

CSS offers an extensive, standardized list of color keywords that provide a wide spectrum of pre-defined hues, serving as a quick reference and practical toolbox for developers and designers. These keywords are grouped into intuitive families like reds, blues, greens, and purples, each containing variations from light to dark (e.g., lightcoral to darkred). While not exhaustive for professional brand work, they are incredibly useful for prototyping, education, and internal tools. This reference demonstrates the richness of CSS's built-in color system, allowing for rapid visual development without needing to look up hex codes, which can streamline the initial design and mockup phase of a project.

Red Family:

red, darkred, crimson, firebrick, indianred, lightcoral, salmon, tomato, coral, orangered

Blue Family:

blue, darkblue, navy, mediumblue, steelblue, lightblue, skyblue, deepskyblue, dodgerblue, cornflowerblue

Green Family:

green, darkgreen, forestgreen, seagreen, mediumseagreen, lightgreen, lime, limegreen, springgreen, yellowgreen

Purple Family:

purple, darkviolet, blueviolet, mediumorchid, plum, thistle, lavender, indigo, darkmagenta, magenta

🧠 Test Your Knowledge

Which keyword makes an element's background completely see-through?