Understanding Hex Color Codes and Conversions
Learn how hex color codes work, how to convert between hex and RGB values, pick accessible color combinations, and use common hex codes in your designs.
Hex color codes are everywhere in web design, graphic design, and digital art. Every color you see on a screen can be represented as a six-character code starting with a hash symbol. Understanding how these codes work — and how they relate to RGB values — gives you precise control over color in any project.
What Is a Hex Color Code?
A hex color code is a six-digit hexadecimal (base-16) number that represents a color. The format is #RRGGBB, where RR is the red component, GG is the green component, and BB is the blue component. Each pair ranges from 00 (no intensity) to FF (full intensity).
The hexadecimal system uses 16 symbols: 0-9 and A-F. The letter A represents 10, B is 11, C is 12, D is 13, E is 14, and F is 15. So FF in hexadecimal equals 255 in decimal — the maximum intensity for a single color channel.
Examples:
#FF0000— Pure red (red at full, green at zero, blue at zero)#00FF00— Pure green#0000FF— Pure blue#FFFFFF— White (all channels at maximum)#000000— Black (all channels at zero)#808080— Medium gray (all channels at 128)
How Hex Maps to RGB
Every hex color has a direct RGB equivalent. The conversion is straightforward: take each two-character pair and convert it from hexadecimal to decimal.
For the color #3498DB:
- Red: 34 hex = (3 x 16) + 4 = 52
- Green: 98 hex = (9 x 16) + 8 = 152
- Blue: DB hex = (13 x 16) + 11 = 219
So #3498DB equals rgb(52, 152, 219) — a medium blue.
To convert the other direction (RGB to hex), divide each decimal value into groups of 16:
- 52: 52 / 16 = 3 remainder 4, so hex = 34
- 152: 152 / 16 = 9 remainder 8, so hex = 98
- 219: 219 / 16 = 13 remainder 11, so hex = DB
Use our Hex Color Converter to do these conversions instantly.
Shorthand Hex Notation
When each pair of digits in a hex code consists of two identical characters, you can abbreviate it to three characters:
#FFFFFFbecomes#FFF#000000becomes#000#AABBCCbecomes#ABC#FF6600becomes#F60
This shorthand only works when the pattern matches. #3498DB can’t be shortened because none of its pairs are identical digits.
Eight-Digit Hex (Alpha Channel)
An eight-digit hex code adds transparency: #RRGGBBAA. The last two digits represent the alpha (opacity) channel, where 00 is fully transparent and FF is fully opaque.
#FF000080— Red at 50% opacity#00000033— Black at 20% opacity#FFFFFFFF— White, fully opaque (same as#FFFFFF)
This format is supported in all modern browsers and is useful when you need transparent colors without switching to rgba() notation.
Common Color Codes Worth Memorizing
Having a handful of hex codes in your memory speeds up design work:
| Color | Hex | RGB |
|---|---|---|
| White | #FFFFFF | 255, 255, 255 |
| Black | #000000 | 0, 0, 0 |
| Red | #FF0000 | 255, 0, 0 |
| Green | #00FF00 | 0, 255, 0 |
| Blue | #0000FF | 0, 0, 255 |
| Yellow | #FFFF00 | 255, 255, 0 |
| Cyan | #00FFFF | 0, 255, 255 |
| Magenta | #FF00FF | 255, 0, 255 |
| Orange | #FFA500 | 255, 165, 0 |
| Gray (50%) | #808080 | 128, 128, 128 |
| Slate Blue | #6A5ACD | 106, 90, 205 |
| Coral | #FF7F50 | 255, 127, 80 |
Color Theory Basics for Hex Codes
Complementary Colors
Complementary colors sit opposite each other on the color wheel. To find the complement of a hex color mathematically, subtract each channel from FF:
Complement of #3498DB:
- Red: FF - 34 = CB
- Green: FF - 98 = 67
- Blue: FF - DB = 24
Complement: #CB6724 — a warm orange, which pairs well with the original blue.
Adjusting Brightness
To make a color lighter, increase all three channels by the same amount (moving toward #FFFFFF). To darken, decrease all three channels (moving toward #000000).
#3498DB(original blue)#5AB2F5(lighter — added about 38 to each channel)#1A6EAB(darker — subtracted about 26 from each channel)
Creating Tints and Shades
A tint mixes a color with white. A shade mixes it with black. In hex terms:
- To create a tint, interpolate each channel toward FF
- To create a shade, interpolate each channel toward 00
Professional design systems often define 9-10 shades of each brand color (from nearly white to nearly black) for use across different contexts.
Accessibility and Color Contrast
Choosing colors that look good is only half the job. Colors must also be accessible to people with visual impairments.
WCAG Contrast Requirements
The Web Content Accessibility Guidelines (WCAG) define minimum contrast ratios between text and background colors:
- Normal text: At least 4.5:1 contrast ratio (AA standard)
- Large text (18px+ bold or 24px+): At least 3:1 contrast ratio
- Enhanced (AAA): At least 7:1 for normal text
For example, #FFFFFF text on a #3498DB background has a contrast ratio of approximately 3.5:1 — it passes for large text but fails for normal body text. Switching the text to #FFFFFF and darkening the blue to #2471A3 would bring the ratio above 4.5:1.
Color Blindness Considerations
Approximately 8% of men and 0.5% of women have some form of color vision deficiency. The most common type is red-green color blindness. Design tips:
- Don’t rely solely on color to convey information — add icons, patterns, or labels
- Avoid red/green combinations for critical indicators (use red/blue or add text labels)
- Test your color palette with a color blindness simulator
Other Color Formats and When to Use Them
HSL (Hue, Saturation, Lightness)
HSL is often more intuitive for design work because you can adjust lightness and saturation independently. hsl(210, 70%, 53%) represents the same blue as #3498DB but makes it easy to create lighter or darker variants by changing only the lightness value.
Named Colors
Most design environments recognize 140+ named colors like red, coral, slateblue, and papayawhip. These are convenient for quick prototyping but offer limited selection compared to the 16.7 million colors available through hex codes.
CMYK
CMYK (Cyan, Magenta, Yellow, Key/Black) is used for print design. Hex codes are for screens only. If your design will be printed, you need to convert your hex palette to CMYK values and verify the colors look correct in print proofs, as many vibrant screen colors can’t be reproduced in print.
Frequently Asked Questions
Why do hex codes use letters instead of just numbers?
Hex codes use base-16 notation because each two-character pair needs to represent values from 0 to 255. In base-10, that would require three digits per channel (making codes 9 characters long). Base-16 fits the 0-255 range into exactly two characters (00 to FF), keeping codes compact at six characters for three channels. The letters A through F simply represent the values 10 through 15.
Are hex colors and RGB colors the same thing?
They represent the same colors using different notation. #FF6600 and rgb(255, 102, 0) produce an identical orange. Hex is more common in design files and stylesheets because it’s shorter. RGB is sometimes preferred in code that performs color calculations because the decimal values are easier to do math with.
How many colors can hex codes represent?
Exactly 16,777,216 colors (256 x 256 x 256). Each of the three channels has 256 possible values (0 to 255), and the total number of combinations is 256 cubed. This is often referred to as “true color” or “24-bit color” and covers the full range of colors that standard displays can produce.
What is the difference between hex and HEX with an alpha channel?
Standard hex (#RRGGBB) defines only color with full opacity. Eight-digit hex (#RRGGBBAA) adds an alpha channel for transparency, where AA ranges from 00 (fully transparent) to FF (fully opaque). For example, #FF000080 is a semi-transparent red. All modern browsers support the eight-digit format.
Can I use hex colors in email templates?
Yes, hex colors are the safest choice for HTML emails. Many email clients have limited support for other color formats, but hex has worked reliably across email clients for decades. Stick to the six-digit format (#RRGGBB) for maximum compatibility, as some older email clients may not support shorthand or eight-digit hex.
Related Calculators
Related Articles
- Color Theory Basics for Web Design
Master color theory for web design including the color wheel, complementary palettes, WCAG contrast requirements, and color psychology to create effective interfaces.
- How to Minify CSS for Faster Websites
Learn what CSS minification does, why it speeds up your website, what it removes from your stylesheets, and best practices for minifying CSS in production.
- Cron Job Examples for Common Tasks (Copy-Paste Ready)
Practical cron job examples with clear explanations. Copy-paste ready crontab schedules for backups, reports, cleanup, monitoring, and automation tasks.
- Common JSON Syntax Errors and How to Fix Them
Fix JSON syntax errors fast with this developer guide. Learn the top 5 JSON parsing errors, before/after examples, and debugging techniques to validate JSON instantly.
Share this article
Have suggestions for this article?