How RGB to HEX conversion works
Going from RGB to HEX is pure notation: each 0–255 channel becomes two base-16 digits. Nothing is calculated or rounded, so every RGB colour has exactly one six-digit code.
- Take each channel (0–255).
- First digit = channel ÷ 16, rounded down; second digit = the remainder.
- Write the digits as 0–9 and A–F (10 = A … 15 = F); pad single digits with a leading 0.
- Join them after a
#:#RRGGBB. If every pair is a repeated digit you may shorten it to#RGB.
Worked example: rgb(244, 67, 54) to HEX
Here is the converter's own calculation for rgb(244, 67, 54), step by step. The result, #F44336, is exactly what the tool above shows for this input.
- Red 244 = 15 × 16 + 4 → F4; green 67 = 4 × 16 + 3 → 43; blue 54 = 3 × 16 + 6 → 36.
- Joined:
#F44336.
Material Design 500 colours in RGB and HEX
The primary (500) shade of each hue in the 2014 Material Design palette.
| Colour | RGB | HEX |
|---|---|---|
| red | rgb(244, 67, 54) | #F44336 |
| pink | rgb(233, 30, 99) | #E91E63 |
| purple | rgb(156, 39, 176) | #9C27B0 |
| deep-purple | rgb(103, 58, 183) | #673AB7 |
| indigo | rgb(63, 81, 181) | #3F51B5 |
| blue | rgb(33, 150, 243) | #2196F3 |
| light-blue | rgb(3, 169, 244) | #03A9F4 |
| cyan | rgb(0, 188, 212) | #00BCD4 |
| teal | rgb(0, 150, 136) | #009688 |
| green | rgb(76, 175, 80) | #4CAF50 |
| light-green | rgb(139, 195, 74) | #8BC34A |
| lime | rgb(205, 220, 57) | #CDDC39 |
| yellow | rgb(255, 235, 59) | #FFEB3B |
| amber | rgb(255, 193, 7) | #FFC107 |
| orange | rgb(255, 152, 0) | #FF9800 |
| deep-orange | rgb(255, 87, 34) | #FF5722 |
Source: Material Design 2 colour palette (material-colors 1.2.6)
Precision test: every RGB value through the converter
Nothing can be lost here. We converted all 16,777,216 RGB colours to HEX and back: 100% came back identical, and 16,777,216 distinct codes were produced, one for every colour.
Method: every whole-number RGB value, through the converter's own code and back, compared on the 0–255 scale (how we test).
| Measure | Result |
|---|---|
| RGB values tested | 16,777,216 |
| Distinct HEX results | 16,777,216 |
| Came back exactly | 100% |
| Largest change (0–255 levels) | 0 |
| Average change | 0 |
Last updated · Source: Pixohub exhaustive test of lib/color-math.ts
Where you'll use RGB to HEX
Copying a colour out of code into a design tool
Browser DevTools, Python's Pillow and most screenshot pickers report rgb() or a tuple. Figma, Canva and brand guidelines mostly use HEX, so the conversion is the usual hand-over step.
Writing compact CSS and SVG
#F44336 is shorter than rgb(244, 67, 54) and is accepted by every CSS and SVG parser, including old email clients that predate rgb() with spaces.
Keys in design tokens
HEX codes are a convenient unique key for a colour in JSON tokens or spreadsheets, since every RGB colour has exactly one code (in uppercase or lowercase).
Common mistakes
- Forgetting the leading zero: red 5 is
05, not5;#5FFis shorthand for #55FFFF, a different colour. - Feeding percentages or 0–1 floats (from Swift, Unity or shaders) straight in: multiply by 255 and round first.
- Dropping alpha silently:
rgba(244, 67, 54, 0.5)needs an 8-digit code,#F4433680; a 6-digit code is fully opaque. - Expecting a hex value to look the same in every app: the code is exact, but apps that don't colour-manage may display it slightly differently on wide-gamut screens.