CSS Hex Colors Guide for Developers
How hex color codes work in CSS and how to convert between HEX, RGB, and HSL.
Hex colors are the most common way to specify colors in CSS and design tools. A hex code like #2563eb represents red, green, and blue values in hexadecimal.
Hex color format
- #RRGGBB — 6 digits for red, green, blue (e.g. #FF0000 = red)
- #RGB — 3-digit shorthand when pairs repeat (e.g. #F00 = #FF0000)
- Values range from 00 (none) to FF (full intensity)
- Case insensitive — #abc equals #ABC
When to use each format
- HEX — CSS, design tools, quick copy-paste
- RGB — when you need alpha transparency (rgba)
- HSL — when adjusting hue, saturation, or lightness programmatically