Tools
EN

RGB to Hex Color Converter

Set the red, green and blue values with the sliders or type them in, and get the hex color code instantly. You can also paste a CSS value such as rgb(124, 58, 237) or an rgba() value with transparency.

RGB values

All color formats

HEX
RGB
RGBA
HSL
HSV
CMYK
CSS name

How it is calculated

Private: your data is processed in your browser and never uploaded.

How to convert RGB to hex

  1. Enter the red, green and blue values (0–255) with the sliders or number fields, or paste a CSS rgb() value.
  2. The hex code appears instantly, together with HSL, HSV and CMYK. Set alpha below 1 to get an 8-digit hex code with transparency.
  3. Copy the hex code, or follow the formula to see how each value was converted.

RGB to hex formula

Each RGB channel from 0 to 255 becomes exactly two hex digits. Divide the value by 16: the whole-number result is the first digit and the remainder is the second, with 10–15 written as A–F. Example for rgb(124, 58, 237):

Joined after a # this gives #7C3AED. Always write two digits per channel: 9 becomes 09, not 9.

RGB to hex conversion in code

Adding transparency (alpha)

For an 8-digit code, multiply the opacity (0–1) by 255, round it and append it as two more hex digits: 0.5 × 255 = 127.5 → 128 → 80, so rgba(124, 58, 237, 0.5) = #7C3AED80.

OpacityHexOpacityHex
100%FF50%80
90%E640%66
80%CC30%4D
75%BF25%40
70%B320%33
60%9910%1A

Frequently asked questions

What is the formula to convert RGB to hex?

For each channel the first hex digit is the value divided by 16 (whole number) and the second is the remainder, with 10–15 written as A–F. Join the three pairs after a #: rgb(255, 165, 0) → FF, A5, 00 → #FFA500.

Why must every channel have two hex digits?

A hex color is read in fixed pairs. rgb(0, 128, 9) must be written #008009; dropping the leading zeros would shift the pairs and give a different or invalid color.

Can a hex color code store transparency?

Yes. Modern browsers accept 8-digit codes #RRGGBBAA, where the last pair is the alpha value from 00 (fully transparent) to FF (opaque). rgba(124, 58, 237, 0.5) becomes #7C3AED80.

Is the RGB to hex conversion exact?

Yes for whole RGB values: every number from 0 to 255 has exactly one two-digit hex form, so converting back gives the same values. Only alpha is rounded to the nearest of 256 steps.