RGB to HEX Converter — Turn RGB values into hex codes, and hex codes into RGB, with a live preview.

Enter red, green and blue numbers, pick a color, or paste a hex code and see every format at once: HEX, RGB and HSL. A live preview and a contrast check show which text color works best. Everything runs in your browser.

Convert a color Your colors stay in your browser
RGB to HEX converter with a color preview, RGB number fields and a hex code

Pick or type a color

Aa

Color codes

HEX
–
RGB (CSS)
–
HSL (CSS)
–
–Best text color on it
–Contrast ratio
The guide

RGB to HEX Guide: Color Codes, HSL, and Contrast

Learn how color codes work and how to pick readable color pairs.

A simple explanation

What does an RGB to HEX converter do?

Screens make every color by mixing red, green and blue light. RGB writes the mix as three numbers from 0 to 255. HEX writes the same three numbers in base 16 as a short code such as #1F3A5F, which is what CSS, design tools and brand guides usually use.

Enter the three numbers, pick a color with the picker, or paste a hex code. All formats update together, and you also get an HSL version and a check of which text color reads best on it.

Common reasons to convert

Why People Convert RGB to HEX

Web design and CSS

Turn a color from a design file or a screenshot picker into the hex code your stylesheet needs.

Brand and documents

Keep a brand color consistent between a logo file, a slide deck and a website.

Accessibility

Check which text color works on a background and see the contrast ratio before you publish.

The maths behind it

How RGB Becomes HEX

Each of the three numbers is turned into a two-digit base-16 value, then the three pairs are joined.

RGB: 31, 58, 95 31 = 1F (1 × 16 + 15) 58 = 3A (3 × 16 + 10) 95 = 5F (5 × 16 + 15) HEX: #1F3A5F

Base 16 uses the digits 0-9 and the letters A-F, where A is 10 and F is 15. A short code like #FA0 is shorthand: each digit is doubled, so it means #FFAA00.

Handy figures

Common Colors in RGB and HEX

ColorRGBHEX
Black0, 0, 0#000000
White255, 255, 255#FFFFFF
Red255, 0, 0#FF0000
Green0, 255, 0#00FF00
Blue0, 0, 255#0000FF
Yellow255, 255, 0#FFFF00
Orange255, 165, 0#FFA500
Gray128, 128, 128#808080
Convert in a few steps

How to Use the RGB to HEX Converter

  1. Type the red, green and blue values, or click the swatch to use the color picker.
  2. Or paste a hex code in the Hex field to go the other way.
  3. Read the HEX, RGB and HSL codes, and check the contrast ratio and best text color.
  4. Press Copy beside the format you need.
Better results

Simple Tips for Working with Colors

  • For readable text, aim for a contrast ratio of at least 4.5 : 1 for normal text and 3 : 1 for large text.
  • Hex codes are not case-sensitive, so #1f3a5f and #1F3A5F are the same color.
  • The leading # is needed in CSS but optional here. You can paste codes with or without it.
  • Screens and printers show color differently, so a printed color may not match what you see on screen.
Good to know

Limitations and Privacy

Privacy

Your colors are converted in your browser. Nothing is sent to our server or stored. Only the lowercase choice is remembered on your device.

Limitations

The tool works with standard 8-bit sRGB colors, 0 to 255 per channel. It does not handle transparency (RGBA or 8-digit hex), CMYK for print, or wide-gamut color spaces.

Common questions

RGB to HEX Converter FAQ

How do I convert RGB to HEX?

Enter the red, green and blue values, each from 0 to 255. The tool converts each number to two base-16 digits and joins them, so 31, 58, 95 becomes #1F3A5F.

How do I convert HEX to RGB?

Paste the hex code into the Hex field. The three RGB numbers fill in at once. For example, #FF8800 is 255, 136, 0.

Does the hex code need a # sign?

No. You can type it with or without the #, and short codes such as #FA0 work too. The result always includes the # so it is ready for CSS.

What do the three RGB numbers mean?

They are the amount of red, green and blue light, from 0 (none) to 255 (full). 0, 0, 0 is black and 255, 255, 255 is white.

What is the HSL value for?

HSL describes a color as hue, saturation and lightness. It is often easier to adjust by hand, for example to make a color a little lighter, and it works directly in CSS.

What does the contrast ratio tell me?

It shows how well black or white text stands out on your color. A ratio of 4.5 : 1 or more is the usual minimum for normal text under the WCAG accessibility guidelines.

Can I include transparency?

Not here. This tool handles opaque colors only, with no alpha channel. For transparency, add an alpha value yourself in rgba() in your CSS.

Is my data saved or sent anywhere?

No. The conversion runs in your browser and nothing leaves your device. Only your lowercase choice is remembered for next time.

From people using this tool

Reviews

Loading reviews…
Keep going

More tools in the box

The homepage features dozens more free tools that don't require an API key.

Suggest a tool