Text & Developer tool

Hex to RGB Color Converter

Enter a colour code, see the colour and copy its RGB, HEX and HSL values.

  • Instant results
  • Working shown
  • No sign-up
  • Runs in your browser
ToolUpdates as you type
#4f46e5
rgb(79, 70, 229)
RGB value of #4f46e5
  • HEX#4f46e5
  • RGBrgb(79, 70, 229)
  • HSLhsl(243, 75%, 59%)
  • Red4F hex = 79
  • Green46 hex = 70
  • BlueE5 hex = 229
  • Contrast with white text6.29 : 1
  • Contrast with black text3.34 : 1

Each pair of hex digits is one channel: first digit × 16 + second digit. A contrast of 4.5 : 1 or more is the usual minimum for normal-size text.

Everything is worked out in your browser. Nothing is sent or saved.

How it works

This hex to RGB converter reads a colour code such as #ff5733 and shows the colour with its RGB value, rgb(255, 87, 51), and its HSL value. It also works the other way: type red, green and blue numbers, paste an rgb() value or use the colour picker, and copy the hex code.

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

  1. Type or paste a code such as #ff5733, #f53 or rgb(255, 87, 51) in the first box.
  2. Or click the Colour picker to choose a colour visually.
  3. Or change the Red, Green and Blue boxes (0 to 255) to convert RGB to hex.
  4. Read the HEX, RGB and HSL values below the swatch.
  5. 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. #00ff00 is 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.

Frequently asked questions

How do I convert hex to RGB by hand?
Split the six digits into three pairs: red, green and blue. Convert each pair from base 16 to base 10 using first digit × 16 + second digit. For #ff5733: ff = 15 × 16 + 15 = 255, 57 = 5 × 16 + 7 = 87, 33 = 3 × 16 + 3 = 51, so the colour is rgb(255, 87, 51).
How do I convert RGB to hex?
Convert each number from 0 to 255 into two hex digits and join them after a #. For rgb(79, 70, 229): 79 = 4F, 70 = 46 and 229 = E5, so the hex code is #4F46E5. Upper or lower case letters mean the same colour.
What is a 3-digit hex code like #f53?
It is a short form where each digit is doubled. #f53 is the same as #ff5533. Only colours whose pairs repeat can be written this way.
What do 8-digit hex codes mean?
The last two digits are the alpha (opacity) channel. #4f46e580 is the colour #4f46e5 at about 50% opacity, which is rgba(79, 70, 229, 0.502) in RGB form.
What do the contrast numbers mean?
They compare the colour with white and with black text using the WCAG formula. A ratio of at least 4.5 : 1 is the usual minimum for normal text, so pick the text colour with the higher number.

Try another tool

See all free tools
Chat with us