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.
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
- Enter red, green, and blue values from 0 to 255 in the three input fields.
- Or click the color picker to choose visually ” the RGB fields update automatically.
- Read the HEX result below, with live preview and a one-click Copy button.
- 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
- Brand guidelines. Brand books and style guides publish HEX, not rgb(), because HEX is more compact and easier to paste into CSS.
- Design handoff. Figma, Sketch, and Adobe tools copy HEX by default ” converting a computed rgb() value back to HEX makes handoff round-trip cleanly.
- SVG and HTML. Fill, stroke, and background attributes accept HEX everywhere, including inside inline SVG paths.
- Configuration files. Tailwind, JSON themes, and many style tokens expect HEX strings, not numeric channels.
- Palette sharing. Design palettes are easier to copy, compare, and share as six-character HEX strings than as triplets.
Common mistakes
- Passing a channel value above 255 or below 0 ” the converter clamps it, but the color is now different from what you intended.
- Rounding too early ” if you compute an RGB triplet from a perceptual operation, round only once, at the end.
- Using shorthand when it is not allowed. #FC0 is only valid when every pair repeats ” #FE5000 has no three-digit form.
- Mixing channel order ” RGB is red, green, blue; some native Windows APIs historically used BGR.
- Assuming HEX supports alpha the same way as rgba() ” it does via HEX8 (#RRGGBBAA), but browser support in older tooling is thinner.
RGB vs HEX at a glance
| Attribute | RGB | HEX |
|---|---|---|
| Format | rgb(R, G, B) | #RRGGBB |
| Digits | base 10 | base 16 |
| Length | 12“20 chars | 7 chars |
| Human readability | channel-by-channel | compact |
| Best for | computed values | static 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.