TechCompare LogoTechCompare

How to convert hex to RGB: the web developer's color format explained

Hex is the right format for opaque colors in web development. It's shorter than rgb(), universally recognized, and copy-pastes cleanly between Figma, VS Code, and browser DevTools. Use the 8-digit variant or rgba() when you need transparency.

Hex color codes like #3B82F6 are just RGB values written in hexadecimal. The first two characters are red (3B = 59), the middle two are green (82 = 130), and the last two are blue (F6 = 246). Hex is the dominant color format on the web because it's compact, universally supported, and easy to copy-paste between design tools and code.

By TechCompare · Updated

Format
HEX
Example: #3B82F6
Category
Web Formats
Color knowledge base

How this is calculated

Hex colors originated in HTML 3.2 and haven't changed since. The format is case-insensitive (#3b82f6 = #3B82F6) and supports shorthand when each channel uses identical hex digits (#FFF = #FFFFFF). The main limitation of hex is that it doesn't support an alpha channel. For transparency, you need the 8-digit hex format (#3B82F6CC) which adds RGBA support, or you switch to the rgba() functional notation in CSS.

Verdict

The format maps two hex characters per channel directly to the 0-255 integer per RGB channel: 3B becomes 59, 82 becomes 130, F6 becomes 246, summing to rgb(59, 130, 246). That 1:1 byte-per-channel structure is why hex survives every design tool round-trip losslessly, where rgb() risks being reformatted or the comma syntax gets mangled. The 3-digit shorthand (#FFF for #FFFFFF) only fires when each channel's two digits are identical, so #F8F8F8 collapses but most real brand colors don't. The 8-digit extension (#3B82F6CC) brings the alpha byte that the original HTML 3.2 spec couldn't express, and CSS Color Level 4+ accepts it natively alongside rgba().

More Color scenarios

Frequently asked questions

Is #FFF the same as #FFFFFF?
Yes. CSS expands 3-digit hex shorthand by doubling each digit. #FFF becomes #FFFFFF (white), #F00 becomes #FF0000 (red). This only works for 3-digit codes where each channel has identical hex digits.
How do I convert a hex color like #3B82F6 to RGB values?
Split the hex string into three two-character pairs: 3B, 82, F6. Convert each pair from base-16 to decimal: 0x3B = 59, 0x82 = 130, 0xF6 = 246. The result is rgb(59, 130, 246). Most spreadsheets, browsers, and design tools accept this conversion natively when you paste a hex code.
What's the difference between #RGB and #RRGGBB hex notation?
Three-digit hex (#F00) is shorthand for the case where each channel's two characters are identical. CSS expands #F00 to #FF0000 by doubling each digit. Six-digit hex (#FF0000) lets you specify any value from 0-255 per channel. Eight-digit hex (#FF0000FF) adds an alpha channel for opacity, supported in CSS Color Level 4+.