About RGB to HEX Conversion
RGB and HEX are two ways of writing the same colour. An RGB value like rgb(37, 99, 235) gives the red, green and blue intensities as decimal numbers from 0 to 255. A HEX code like #2563EB gives those same three channels as pairs of hexadecimal digits. The colour is identical — only the notation differs.
Where HEX is compact and easy to paste, RGB is easier to manipulate in code — you can adjust individual channels, animate transitions, or compute new colours with arithmetic. Design tools usually give you HEX, but web APIs usually want RGB. This converter bridges the two instantly.
How RGB to HEX conversion works
Each RGB channel is a number from 0 to 255. Two hex digits can represent exactly 256 values (00 through FF), which is why each channel maps neatly to a pair. Convert each number to base 16, pad to two digits, and concatenate.
| Channel | Decimal | Hex pair | Calculation |
|---|---|---|---|
| Red | 37 | 25 | 2×16 + 5 = 37 |
| Green | 99 | 63 | 6×16 + 3 = 99 |
| Blue | 235 | EB | 14×16 + 11 = 235 |
So rgb(37, 99, 235) becomes #2563EB. The conversion is lossless — every RGB triplet maps to exactly one HEX code and vice versa.
Reference values
| Colour | RGB | HEX |
|---|---|---|
| Black | rgb(0, 0, 0) | #000000 |
| White | rgb(255, 255, 255) | #FFFFFF |
| Red | rgb(255, 0, 0) | #FF0000 |
| Green | rgb(0, 255, 0) | #00FF00 |
| Blue | rgb(0, 0, 255) | #0000FF |
| Mid grey | rgb(128, 128, 128) | #808080 |
Hex digit values
Each hex digit represents one of 16 values. Two digits give 16 × 16 = 256 combinations, matching the 0–255 range of an RGB channel.
| Decimal | Hex | Decimal | Hex |
|---|---|---|---|
| 0 | 00 | 128 | 80 |
| 16 | 10 | 170 | AA |
| 32 | 20 | 200 | C8 |
| 64 | 40 | 240 | F0 |
| 100 | 64 | 255 | FF |
Alpha transparency (RGBA)
RGBA adds a fourth channel — alpha — controlling opacity from 0 (fully transparent) to 255 (fully opaque). Modern browsers support 8-digit HEX, where the last two digits are the alpha value:
#2563EB= fully opaque blue#2563EBCC= same blue at 80% opacity (CC = 204)#2563EB80= same blue at 50% opacity (80 = 128)
This tool converts the three colour channels. To add alpha, append the two hex digits yourself using the pattern above.
Common use cases
CSS stylesheets
Convert design tool values into HTML-ready hex codes.
Canvas & WebGL
Convert runtime RGB into hex for style attributes.
Batch processing
Convert an entire palette at once.
Brand specs
Publish palettes in both RGB and HEX.
Accessibility
Convert computed RGB values for contrast tests.
Cross-format docs
Produce hex codes alongside CMYK for print.
Privacy and accuracy
This RGB to HEX converter runs entirely in your browser. All conversions happen locally in JavaScript with no server calls. The values you enter are never transmitted, stored or logged.