Hex to RGB Converter Online: Color Code Translation Guide
How hex and RGB color codes work, how to convert between them by hand with worked examples, and when to use each format in CSS, design tools and apps, plus transparency and contrast tips.
Designers hand over colors as hex codes like #1E90FF; code and design tools often want RGB values like rgb(30, 144, 255). They're the same color written two ways, and converting between them takes seconds once you know how. This guide explains both formats, shows the conversion step by step, and covers transparency, accessibility and good habits for managing colors.
How Screen Colors Work
Screens create color by mixing red, green and blue light. Each of the three channels has 256 levels, from 0 (off) to 255 (full brightness). That gives 256 × 256 × 256 = 16,777,216 possible colors.
- All three at 0 = black
- All three at 255 = white
- Equal values in between = shades of grey
Hex and RGB are two ways of writing the same three numbers.
The RGB Format
rgb(R, G, B), with each value from 0 to 255.
Color · RGB · Hex
Red · rgb(255, 0, 0) · #FF0000
Green · rgb(0, 255, 0) · #00FF00
Blue · rgb(0, 0, 255) · #0000FF
Yellow · rgb(255, 255, 0) · #FFFF00
Cyan · rgb(0, 255, 255) · #00FFFF
Magenta · rgb(255, 0, 255) · #FF00FF
White · rgb(255, 255, 255) · #FFFFFF
Grey · rgb(128, 128, 128) · #808080
Black · rgb(0, 0, 0) · #000000
The Hex Format
#RRGGBB: the same three values written in hexadecimal (base 16), two characters each. Hexadecimal uses the digits 0–9 and then A–F for 10–15, so two hex digits cover 00 (0) to FF (255).
Shorthand: when each pair is a repeated digit, CSS lets you write three characters instead of six. #F60 means #FF6600, and #FFF means #FFFFFF.
Hex codes aren't case-sensitive: #ff5733 and #FF5733 are the same color.
Converting Hex to RGB
- Remove the #.
- Split the code into three pairs: RR, GG, BB.
- Convert each pair to decimal: (first digit × 16) + second digit, where A=10, B=11, C=12, D=13, E=14, F=15.
Example: #FF5733
- FF = (15 × 16) + 15 = 255
- 57 = (5 × 16) + 7 = 87
- 33 = (3 × 16) + 3 = 51
Result: rgb(255, 87, 51)
Example: #1E90FF
- 1E = (1 × 16) + 14 = 30
- 90 = (9 × 16) + 0 = 144
- FF = 255
Result: rgb(30, 144, 255)
Converting RGB to Hex
- Divide each value by 16.
- The whole-number answer is the first hex digit; the remainder is the second.
- Write any value under 16 with a leading zero (for example, 9 becomes 09).
- Join the three pairs after a #.
Example: rgb(30, 144, 255)
- 30 ÷ 16 = 1 remainder 14 → 1E
- 144 ÷ 16 = 9 remainder 0 → 90
- 255 ÷ 16 = 15 remainder 15 → FF
Result: #1E90FF
Example: rgb(0, 128, 0) → 00, 80, 00 → #008000
Converting in Code and Tools
- JavaScript, hex to RGB: parseInt("57", 16) returns 87.
- JavaScript, RGB to hex: (87).toString(16).padStart(2, "0") returns "57".
- Browser developer tools: in Chrome, Edge and Firefox, Shift-click the color swatch next to any CSS color to cycle between hex, RGB and HSL.
- Design tools: Figma, Photoshop, Illustrator and Canva all show and accept both formats in their color pickers.
Transparency: RGBA and 8-Digit Hex
To make a color semi-transparent, add an alpha value:
- RGB with alpha: rgb(30 144 255 / 50%) in modern CSS, or the older rgba(30, 144, 255, 0.5). Alpha runs from 0 (fully transparent) to 1 (fully opaque).
- 8-digit hex: #RRGGBBAA, where the last pair is the alpha from 00 (transparent) to FF (opaque). 50% opacity is about 80, so #1E90FF80.
Other Color Formats You'll Meet
- HSL (hue, saturation, lightness): hsl(210 100% 56%). Hue is an angle on the color wheel (0–360°). HSL makes it easy to create lighter or darker versions of a color by changing just the lightness, which is why many design systems use it.
- HSV/HSB: similar to HSL, and common in design-software color pickers.
- CMYK: cyan, magenta, yellow and black ink percentages, used for printing. Screen RGB colors can look different in print, especially bright blues and greens, so always proof important printed colors.
Lighter and Darker Versions
- Tints (lighter): mix with white by moving each channel towards 255. Red #FF0000 becomes #FF6666.
- Shades (darker): mix with black by moving each channel towards 0. Red becomes #990000.
- Tones (muted): mix with grey. Red becomes something like #CC6666.
In practice, adjusting the lightness in HSL is often easier than editing RGB values by hand.
Accessibility: Contrast Matters
The Web Content Accessibility Guidelines (WCAG) set minimum contrast between text and its background:
Level · Normal text · Large text (about 24px, or 19px bold)
AA (minimum) · 4.5:1 · 3:1
AAA (enhanced) · 7:1 · 4.5:1
Interface elements such as buttons, form borders and icons need at least 3:1 against their surroundings. Free tools such as the WebAIM Contrast Checker, and the contrast information in browser developer tools, calculate the ratio for any two colors.
Color vision deficiency affects roughly 1 in 12 men and 1 in 200 women, most commonly as difficulty telling red from green. So don't rely on color alone: add labels, icons or patterns, especially for errors, charts and status indicators.
Good Habits for Managing Colors
- Use CSS custom properties (variables) such as --color-primary: #1E90FF; so each color is defined once.
- Name colors by role, not appearance: --color-accent or --text-muted rather than --blue, so a rebrand doesn't leave you with a "blue" variable that's actually green.
- Pick one format per project for consistency. Hex is the most common for solid colors; use RGB or HSL with alpha where you need transparency.
- Document your palette, listing hex and RGB values (and CMYK for print) in your brand guidelines.
Troubleshooting
- Color looks wrong: check for a typo, such as the letter O instead of zero, or a missing character. A hex code must be 3, 4, 6 or 8 characters long.
- RGB value rejected: each value must be between 0 and 255.
- Colors look different on different screens: screens vary in calibration and color range. Stick to the standard sRGB color space for the web, and check on more than one device.
Conclusion
Hex and RGB are two notations for the same thing: three numbers from 0 to 255 for red, green and blue. Convert hex to RGB by turning each pair into decimal (first digit × 16 + second digit), and RGB to hex by dividing by 16. Add an alpha value for transparency, check contrast for readability, and keep your palette in variables, and your colors will be consistent everywhere.