Pantone Colors

RGB to HEX Converter

An RGB to HEX converter turns a red, green, blue triplet into a six-digit hexadecimal color code. For example, rgb(255, 0, 0) becomes #FF0000 ” pure red. The conversion is exact: each channel of 0“255 becomes a two-digit hex pair, so no information is lost and no rounding occurs.

or pick a color

What is RGB to HEX conversion?

RGB is a color model where red, green, and blue light are combined additively. Each channel ranges from 0 (off) to 255 (full intensity), which is 256 levels per channel and 16,777,216 possible colors total. This is the model monitors use natively.

HEX is the same color written in base-16 notation. The hash symbol marks a color literal, and the six digits that follow are split into three pairs: red, green, blue. Each pair is a hexadecimal number from 00 to FF, equivalent to the decimal range 0“255.

The conversion is purely a base change: 255 decimal is FF hex, 80 decimal is 50 hex, 0 is 00. There is no color space shift, no gamma correction, and no perceptual matching. A converter is just a formatter that presents the same color in a shorter notation ” which is why HEX is so common in CSS, design tools, and brand guidelines.

How to use this converter

  1. Enter red, green, and blue values from 0 to 255 in the three input fields.
  2. Or click the color picker to choose visually ” the RGB fields update automatically.
  3. Read the HEX result below, with live preview and a one-click Copy button.
  4. Shorthand is detected automatically when the pairs match ” for example rgb(255, 204, 0) shows as both #FFCC00 and #FC0.

How the conversion works technically

To convert one channel, divide by 16 and record the quotient and remainder. The quotient becomes the first hex digit, the remainder the second. Both are then written in hexadecimal ” 0“9 stay as-is, 10“15 become A“F.

Example: rgb(254, 80, 0). 254 / 16 = 15 remainder 14, so 254 ’ FE. 80 / 16 = 5 remainder 0, so 80 ’ 50. 0 / 16 = 0 remainder 0, so 0 ’ 00. Result: #FE5000, an orange.

In code the same operation is a bit shift: hex = (r << 16) | (g << 8) | b, then format as six uppercase hex digits. Browsers do this internally every time they encounter an rgb() value in CSS.

Accuracy and limitations

RGB to HEX is lossless when channel values are integers. Each channel maps to exactly one two-digit hex pair, so the conversion is reversible with no error. HEX cannot represent fractional channels, however ” if your RGB value has decimals (from a gradient computation, for example), round first.

Both formats describe colors in the sRGB color space. Neither can represent wide-gamut colors like Display P3 or Rec. 2020. For those, use rgb(display-p3 ) or color() in modern CSS instead of HEX.

Use cases

Common mistakes

RGB vs HEX at a glance

AttributeRGBHEX
Formatrgb(R, G, B)#RRGGBB
Digitsbase 10base 16
Length12“20 chars7 chars
Human readabilitychannel-by-channelcompact
Best forcomputed valuesstatic values

Frequently asked questions

How do I convert RGB to HEX?

Convert each channel from decimal (0“255) to a two-digit hex value. Divide by 16, take the quotient as the first digit and the remainder as the second. rgb(255, 0, 0) becomes FF 00 00, which is #FF0000.

Why is HEX written with a # symbol?

The # marks the value as a hexadecimal color literal so CSS, SVG, and HTML can distinguish it from a number or identifier. The hash is not part of the color value itself.

Is RGB to HEX conversion exact?

Yes. Every rgb(r, g, b) triplet with integer channels in 0“255 maps to exactly one #RRGGBB value, and vice versa. No rounding is involved as long as channel values are integers.

Can I convert RGB with a decimal channel to HEX?

HEX requires integer channels. Round any decimal values to the nearest integer before converting ” for example rgb(127.5, 0, 0) rounds to rgb(128, 0, 0), which is #800000.

What is the shortest valid HEX code?

Three digits. When every pair of digits is identical ” #FFCC00 becomes #FC0 ” the shorthand is allowed. Shorthand is not allowed when the pairs differ, so #FE5000 has no shorter form.

Related converters

Last reviewed: