ColourPilot
Complete CSS Colors Manual

Complete CSS Colors Guide

Learn everything about CSS colors, including HEX, RGB, HSL, RGBA, named colors, gradients, transparency, variables and accessibility with practical examples.

1. What are CSS Colors?

CSS provides several ways to define colors, including HEX, RGB, RGBA, HSL, HSLA and predefined color names. Choosing the right format makes your styles easier to maintain while helping create consistent, accessible and visually appealing websites.


2. CSS Color Formats

Stylesheets support multiple functions to represent color coordinates:

HEX Formats

color: #3498DB; /* 6-digit hex */

color: #FFF; /* 3-digit shorthand */

RGB / RGBA Functions

color: rgb(52, 152, 219);

color: rgba(52, 152, 219, 0.5); /* 50% opacity */

HSL / HSLA Functions

color: hsl(204, 70%, 53%);

color: hsla(204, 70%, 53%, 0.5);


3. Predefined Named Colors

CSS includes 148 predefined color keywords like red, gold, tomato, rebeccapurple, and cornflowerblue.

Full Named Colors Grid
aliceblue#f0f8ff
antiquewhite#faebd7
aqua#00ffff
aquamarine#7fffd4
azure#f0ffff
beige#f5f5dc
bisque#ffe4c4
black#000000
blanchedalmond#ffebcd
blue#0000ff
blueviolet#8a2be2
brown#a52a2a
burlywood#deb887
cadetblue#5f9ea0
chartreuse#7fff00
chocolate#d2691e
coral#ff7f50
cornflowerblue#6495ed
cornsilk#fff8dc
crimson#dc143c
cyan#00ffff
darkblue#00008b
darkcyan#008b8b
darkgoldenrod#b8860b
darkgray#a9a9a9
darkgreen#006400
darkgrey#a9a9a9
darkkhaki#bdb76b
darkmagenta#8b008b
darkolivegreen#556b2f
darkorange#ff8c00
darkorchid#9932cc
darkred#8b0000
darksalmon#e9967a
darkseagreen#8fbc8f
darkslateblue#483d8b
darkslategray#2f4f4f
darkslugrey#2f4f4f
darkturquoise#00ced1
darkviolet#9400d3
deeppink#ff1493
deepskyblue#00bfff
dimgray#696969
dimgrey#696969
dodgerblue#1e90ff
firebrick#b22222
floralwhite#fffaf0
forestgreen#228b22
fuchsia#ff00ff
gainsboro#dcdcdc
ghostwhite#f8f8ff
gold#ffd700
goldenrod#daa520
gray#808080
green#008000
greenyellow#adff2f
grey#808080
honeydew#f0fff0
hotpink#ff69b4
indianred#cd5c5c
indigo#4b0082
ivory#fffff0
khaki#f0e68c
lavender#e6e6fa
lavenderblush#fff0f5
lawngreen#7cfc00
lemonchiffon#fffacd
lightblue#add8e6
lightcoral#f08080
lightcyan#e0ffff
lightgoldenrodyellow#fafad2
lightgray#d3d3d3
lightgreen#90ee90
lightgrey#d3d3d3
lightpink#ffb6c1
lightsalmon#ffa07a
lightseagreen#20b2aa
lightskyblue#87cefa
lightslategray#778899
lightslategrey#778899
lightsteelblue#b0c4de
lightyellow#ffffe0
lime#00ff00
limegreen#32cd32
linen#faf0e6
magenta#ff00ff
maroon#800000
mediumaquamarine#66cdaa
mediumblue#0000cd
mediumorchid#ba55d3
mediumpurple#9370db
mediumseagreen#3cb371
mediumslateblue#7b68ee
mediumspringgreen#00fa9a
mediumturquoise#48d1cc
mediumvioletred#c71585
midnightblue#191970
mintcream#f5fffa
mistyrose#ffe4e1
moccasin#ffe4b5
navajowhite#ffdead
navy#000080
oldlace#fdf5e6
olive#808000
olivedrab#6b8e23
orange#ffa500
orangered#ff4500
orchid#da70d6
palegoldenrod#eee8aa
palegreen#98fb98
paleturquoise#afeeee
palevioletred#db7093
papayawhip#ffefd5
peachpuff#ffdab9
peru#cd853f
pink#ffc0cb
plum#dda0dd
powderblue#b0e0e6
purple#800080
rebeccapurple#663399
red#ff0000
rosybrown#bc8f8f
royalblue#4169e1
saddlebrown#8b4513
salmon#fa8072
sandybrown#f4a460
seagreen#2e8b57
seashell#fff5ee
sienna#a0522d
silver#c0c0c0
skyblue#87ceeb
slateblue#6a5acd
slategray#708090
slategrey#708090
snow#fffafa
springgreen#00ff7f
steelblue#4682b4
tan#d2b48c
teal#008080
thistle#d8bfd8
tomato#ff6347
turquoise#40e0d0
violet#ee82ee
wheat#f5deb3
white#ffffff
whitesmoke#f5f5f5
yellow#ffff00
yellowgreen#9acd32

4. Custom CSS Variables

Declaring color variables inside the :root selector helps you manage themes and avoid hardcoding color codes.

:root {
  --primary-color: #3498DB;
  --secondary-color: #2ECC71;
}

.button {
  background-color: var(--primary-color);
  border-color: var(--secondary-color);
}

5. Every CSS Color Property

You can style various parts of your elements using specific CSS color properties:

colorSets text color.
background-colorSets background solid color.
border-colorSets border stroke color.
outline-colorSets outline highlight color.
text-decoration-colorSets underline/strike-through colors.
caret-colorSets input text cursor color.
accent-colorSets checkboxes/radios branding accents.
column-rule-colorSets columns divider line colors.
fillSets SVG vectors interior fill color.
strokeSets SVG vectors border stroke color.

6. Opacity & Transparency

Transparency can be declared in several ways in CSS:

  • Opacity Property: Applying opacity: 0.5; makes the entire element (including text and children) translucent.
  • Alpha Channels: Using rgba(), hsla(), or 8-digit HEX leaves child elements fully opaque.
  • transparent Keyword: Sets background transparency without affecting text.
  • currentColor Keyword: Automatically inherits the text color of the current element.

7. CSS Color Level 4 & 5

Modern browsers support wide color gamuts that go beyond the standard sRGB space.

CSS Color Level 4: Wide-Gamut Spaces

Functions like lab(), lch(), hwb(), oklab(), and oklch() allow monitors to project brighter, more saturated reds, greens, and blues.

CSS Color Level 5: Dynamic Color Functions

Introduces color mixing functions like color-mix() and Relative Color Syntax (RCS) to modify color values directly in your stylesheets:

/* CSS Level 5 examples */
background-color: color-mix(in srgb, var(--primary) 80%, white);
background-color: rgb(from var(--primary) r g b / 50%); /* RCS */

8. Variables in Frameworks

Color variables can be declared in popular design frameworks like Tailwind CSS, Bootstrap, and Material Design:

Tailwind Configuration
theme: { extend: { colors: { brand: '#3498db' } } }
Bootstrap variables
$primary: #3498db;
Material UI Palette
palette: { primary: { main: '#3498db' } }

9. Dark Mode Implementation

You can implement dark mode easily by redefining your CSS variables inside media queries or target classes:

:root {
  --background: #FFFFFF;
  --text: #1E293B;
  --border: #E2E8F0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0F172A;
    --text: #F8FAFC;
    --border: #334155;
  }
}

10. WCAG Accessibility Rules

To ensure readable contrast between text and background colors, you must comply with WCAG accessibility standards:

  • WCAG AA Standard: Requires a minimum contrast ratio of 4.5:1 for body copy and 3.0:1 for large text.
  • WCAG AAA Standard: Requires a minimum contrast ratio of 7.0:1 for body copy and 4.5:1 for large text.

11. Comparison Tables

HEX vs RGB

FeatureHEX FormatRGB Format
Syntax#3498DBrgb(52, 152, 219)
Opacity support8-digit Hexrgba() Function

RGB vs HSL

FeatureRGB FormatHSL Format
CoordinatesRed, Green, Blue amountsHue, Saturation, Lightness parameters
Vibrancy adjustmentsHardEasy

RGBA vs Opacity

FeatureRGBA ColorOpacity Property
Element ScopeApplies transparency only to the styled element.Applies transparency to the element and all its children.
InheritanceChildren remain opaque.Children inherit transparency levels.

12. CSS Design Examples

Button Styles
.btn { background-color: #3498DB; color: white; border: 1px solid #2980B9; }
Alert Component
.alert { background: #FADBD8; border-left: 5px solid #E74C3C; color: #78281F; }

13. Frequently Asked Questions

What are CSS colors?

CSS colors are value specifications applied inside stylesheets to paint element text highlights, background sheets, margins, rules, and overlay shadows.

Which color format is best?

HEX is best for standard color constants, RGB is useful for opacity math (RGBA), and HSL is excellent for modifying saturation and lightness programmatically.

Does CSS support HEX?

Yes, CSS natively supports 3-digit shorthand, 6-digit standard, and 8-digit hexadecimal transparency notation.

Does CSS support RGB?

Yes, via the rgb() or rgba() functions, supporting comma-separated or modern space-separated specifications.

What is RGBA?

RGBA adds a fourth channel called alpha (0.0 to 1.0) to specify element transparency.

What is HSL?

HSL defines colors using Hue angle degrees (0-360), Saturation percentages, and Lightness percentages.

What is currentColor?

currentColor is a special CSS keyword that references the computed text color value of the current element.

What is transparent?

transparent is a keyword representing a fully clear color coordinate, mathematically equivalent to rgba(0, 0, 0, 0).

How many named colors exist?

There are exactly 148 named color keywords recognized by CSS standards (including duplicate spellings like gray and grey).

Should I use CSS variables?

Yes, CSS variables allow you to store theme color tokens globally inside :root, making dark mode swaps easy.

Are gradients CSS colors?

Gradients are classified as CSS images rather than solid colors, but they are created by declaring multiple color stop transition values.

Is RGBA deprecated?

No, RGBA is not deprecated. However, modern CSS Level 4 merges rgb() and rgba() so that rgb() natively accepts alpha parameters without the "a".

Which browsers support HSL?

All modern desktop and mobile browsers have supported HSL color declarations for over a decade.

Can CSS use CMYK?

No, CSS color spaces are designed for screen display illumination, so CMYK values are not supported directly in web layouts.

Can CSS use LAB colors?

Yes! CSS Color Level 4 introduces the lab(), lch(), oklab(), and oklch() color spaces for wide-gamut monitors.