A hex color code uses six hexadecimal digits to represent a color. Format: #RRGGBB, where RR = red, GG = green, BB = blue. Values range from 00 (none) to FF (maximum).
Examples
- #FF0000 = Pure red
- #00FF00 = Pure green
- #0000FF = Pure blue
- #FFFFFF = White
- #000000 = Black
- #808080 = Gray (50%)
Shorthand
When pairs repeat, you can use 3-digit shorthand: #F00 = #FF0000, #0AF = #00AAFF.
Related Formats
RGB: rgb(255, 0, 0). HSL: hsl(0, 100%, 50%). RGBA adds transparency: rgba(255, 0, 0, 0.5).
Web-Safe and Accessible Color Choices
Not every hex color combination is readable β text and background colors need sufficient contrast to meet WCAG accessibility guidelines (a minimum 4.5:1 contrast ratio for normal text). Pairing light gray text (#CCCCCC) on a white background (#FFFFFF), for instance, technically "works" as valid hex codes but fails accessibility standards and is hard to read for many users.
Alpha Transparency
An 8-character hex code (#RRGGBBAA) adds a transparency channel, where AA ranges from 00 (fully transparent) to FF (fully opaque) β increasingly supported in modern CSS as an alternative to the separate rgba() syntax for specifying transparent colors.