This hex to RGB color converter shows any colour code as a colour swatch along with its RGB, HEX and HSL values. Type a hex code, paste an rgb() value, use the colour picker or set the red, green and blue numbers directly. Every value updates together, and each has a copy button.
How to use the color code converter
- Type or paste a code such as
#ff5733,#f53orrgb(255, 87, 51)in the first box. - Or click the Colour picker to choose a colour visually.
- Or change the Red, Green and Blue boxes (0 to 255) to convert RGB to hex.
- Read the HEX, RGB and HSL values below the swatch.
- Click Copy HEX, Copy RGB or Copy HSL and paste it into your CSS.
How hex to RGB conversion works
A hex colour is three numbers written in base 16, one each for red, green and blue. Each pair of digits runs from 00 (0) to ff (255).
| Hex code | Red pair | Green pair | Blue pair | RGB |
|---|---|---|---|---|
| #ff5733 | ff = 255 | 57 = 87 | 33 = 51 | rgb(255, 87, 51) |
| #4f46e5 | 4f = 79 | 46 = 70 | e5 = 229 | rgb(79, 70, 229) |
| #000000 | 00 = 0 | 00 = 0 | 00 = 0 | rgb(0, 0, 0), black |
| #ffffff | ff = 255 | ff = 255 | ff = 255 | rgb(255, 255, 255), white |
To convert one pair, multiply the first digit by 16 and add the second. The letters a to f stand for 10 to 15, so e5 = 14 × 16 + 5 = 229. The number system converter shows this step by step for any number.
Common mistake: A common mistake is mixing up the order. Hex codes are always red, then green, then blue.
#00ff00is pure green, not blue.
RGB to hex, HSL and other formats
| Format | Example (same colour) | Where you see it |
|---|---|---|
| HEX | #4f46e5 | CSS, design tools, brand guides |
| RGB | rgb(79, 70, 229) | CSS, image editors |
| RGBA | rgba(79, 70, 229, 0.5) | CSS with transparency |
| HSL | hsl(243, 75%, 59%) | CSS, when you want lighter or darker shades |
HSL stands for hue (the colour on a wheel, 0 to 360 degrees), saturation (how strong) and lightness (how light). To make a lighter shade of a colour, keep the hue and raise the lightness.
Use the colour in HTML and CSS
All these lines set the same text colour, so use whichever your project uses:
.title { color: #4f46e5; }
.title { color: rgb(79, 70, 229); }
.title { color: hsl(243, 75%, 59%); }
Try them in the online HTML, CSS and JS editor, or learn the basics in the CSS tutorial.
Pro tip: Check contrast before you use a colour for text or buttons. The tool shows the contrast ratio with white and with black text. Pick the one at 4.5 : 1 or higher so people can read it on a phone in sunlight.
Want a smooth blend of two colours? Use the CSS gradient generator.
