Key takeaways
- CSS supports named colors, hex, rgb(), hsl(), oklch() and more.
- Use CSS variables so each color is defined once.
- color-mix() and alpha syntax create variations without hard-coding values.
CSS gives you many ways to write a color. This guide shows what each does best.
Named colors
CSS defines 148 color names such as navy and tomato. They are handy for prototypes. Browse them in the named colors list.
Hex
Compact and universal, including shorthand (#0AF) and eight-digit alpha (#1E90FF80). See our hex guide.
rgb() and hsl()
The modern syntax uses spaces and a slash for alpha: rgb(30 144 255 / 50%) and hsl(210 100% 56% / 0.5). HSL is great for creating lighter or darker variants by changing one number.
oklch()
OKLCH uses perceptual lightness, so equal steps look equally different. It is supported in current browsers and ideal for generated scales. Convert any color with the OKLCH converter.
color-mix()
Blend colors in CSS: color-mix(in srgb, var(--brand) 20%, white) gives a tint without a new variable.
Variables and currentColor
Define colors once as custom properties and reuse them. The currentColor keyword reuses the element's text color for borders and icons, so they always match.
Opacity
The opacity property fades an element and its children. A color with alpha only affects that color, so text on top stays solid. Use the hex with opacity tool to get the exact value.
Gradients
linear-gradient(), radial-gradient() and conic-gradient() take any of the formats above. Build them visually in the gradient generator.
Choosing a format
Share colors as hex, build scales in HSL or OKLCH, and use variables everywhere. Our comparison post explains the trade-offs.