How to convert hex to RGB
A hex colour code is three numbers in base 16, one each for red, green and blue light, from 00 (none) to FF (full, 255). Hex digits run 0–9 then A–F for 10–15, so each pair is first digit × 16 + second digit:
Here it is with your numbers:
- Red: 25 is 2 × 16 + 5 = 37.
- Green: 63 is 6 × 16 + 3 = 99.
- Blue: EB is 14 × 16 + 11 = 235.
It means #2563EB is rgb(37, 99, 235) on a scale where 0 is none of that light and 255 is full.
A 3-digit code is a short form with each digit doubled (#36F is #3366FF). An 8-digit code adds a fourth pair for alpha, how see-through the colour is: 00 is invisible and FF is solid.
Source W3C · CSS Color Module Level 4, §5.2 The RGB hexadecimal notations ↗
How to convert RGB to hex
Go the other way: divide each value by 16. The whole number is the first hex digit and the remainder the second (10 – 15 are A – F).
Here it is with your numbers:
- Red: 37 ÷ 16 is 2 remainder 5, so 25.
- Green: 99 ÷ 16 is 6 remainder 3, so 63.
- Blue: 235 ÷ 16 is 14 remainder 11, so EB.
- Put them together after a #: #2563EB.
It means rgb(37, 99, 235) and #2563EB are the same colour.
Basic CSS colours in hex and RGB
| Name | Hex | RGB |
|---|---|---|
| black | #000000 | 0, 0, 0 |
| silver | #C0C0C0 | 192, 192, 192 |
| gray | #808080 | 128, 128, 128 |
| white | #FFFFFF | 255, 255, 255 |
| maroon | #800000 | 128, 0, 0 |
| red | #FF0000 | 255, 0, 0 |
| purple | #800080 | 128, 0, 128 |
| fuchsia | #FF00FF | 255, 0, 255 |
| green | #008000 | 0, 128, 0 |
| lime | #00FF00 | 0, 255, 0 |
| olive | #808000 | 128, 128, 0 |
| yellow | #FFFF00 | 255, 255, 0 |
| navy | #000080 | 0, 0, 128 |
| blue | #0000FF | 0, 0, 255 |
| teal | #008080 | 0, 128, 128 |
| aqua | #00FFFF | 0, 255, 255 |
Source W3C · CSS Color Module Level 4, §6.1 Named colors ↗
FAQs
How do I convert hex to RGB?
Split the code into three pairs, one each for red, green and blue, and turn each pair from hexadecimal into a number from 0 to 255: the first digit × 16 plus the second. #2563EB is 25, 63 and EB, which is 37, 99 and 235.
Source W3C · CSS Color Module Level 4, §5.2 The RGB hexadecimal notations ↗
Is hex the same as RGB?
Yes, the same colour written two ways. A 6-digit hex code is just the red, green and blue values in base 16: #FF0000 and rgb(255, 0, 0) are both pure red.
What is #0000ff in RGB?
rgb(0, 0, 255): no red, no green and full blue. CSS calls it blue.
What is the RGB value for #fffff?
#fffff has 5 digits, which isn’t a valid hex colour (it needs 3, 4, 6 or 8). You probably meant #ffffff, which is rgb(255, 255, 255): white.
Source W3C · CSS Color Module Level 4, §5.2 The RGB hexadecimal notations ↗
Sources
- W3C: CSS Color Module Level 4, §5.2 The RGB hexadecimal notations
- W3C: CSS Color Module Level 4, §6.1 Named colors