How does RGB to HEX conversion work?
RGB values are three decimal numbers from 0–255 representing red, green, and blue light. To convert to HEX, each channel is individually converted from base 10 to base 16, zero-padded to two characters, and concatenated with a # prefix.
For example, rgb(37, 99, 235): 37 in hex is 25, 99 is 63, 235 is EB — giving #2563EB.
Common color reference
Common web colours with their RGB and HEX equivalents.
| Colour name | Hex code | RGB value | HSL value | |
|---|---|---|---|---|
| Black | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) | |
| White | #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) | |
| Red | #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) | |
| Lime | #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) | |
| Blue | #0000FF | rgb(0, 0, 255) | hsl(240, 100%, 50%) | |
| Yellow | #FFFF00 | rgb(255, 255, 0) | hsl(60, 100%, 50%) | |
| Cyan | #00FFFF | rgb(0, 255, 255) | hsl(180, 100%, 50%) | |
| Magenta | #FF00FF | rgb(255, 0, 255) | hsl(300, 100%, 50%) | |
| Orange | #FF8000 | rgb(255, 128, 0) | hsl(30, 100%, 50%) | |
| Coral | #FF6347 | rgb(255, 99, 71) | hsl(9, 100%, 64%) | |
| Silver | #C0C0C0 | rgb(192, 192, 192) | hsl(0, 0%, 75%) | |
| Gray | #808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) | |
| Maroon | #800000 | rgb(128, 0, 0) | hsl(0, 100%, 25%) | |
| Olive | #808000 | rgb(128, 128, 0) | hsl(60, 100%, 25%) | |
| Green | #008000 | rgb(0, 128, 0) | hsl(120, 100%, 25%) | |
| Amber | #F59E0B | rgb(245, 158, 11) | hsl(38, 92%, 50%) | |
| Purple | #800080 | rgb(128, 0, 128) | hsl(300, 100%, 25%) | |
| Teal | #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) | |
| Navy | #000080 | rgb(0, 0, 128) | hsl(240, 100%, 25%) | |
| Indigo | #4B0082 | rgb(75, 0, 130) | hsl(275, 100%, 25%) |
Frequently asked questions
Why are HEX values sometimes 3 digits instead of 6?
When both digits in each pair are identical, CSS allows shorthand — #AABBCC can be written as #ABC. This converter always outputs full 6-digit codes for maximum compatibility.
Can RGB values be decimals?
In standard CSS rgb(), values must be integers from 0–255. Fractional values are clamped or rounded before conversion.