Beginner

RGB to HEX Color Converter

Convert any red, green and blue color values into a web-ready #RRGGBB hex code and a CSS rgb() string.
0 to 255
0 to 255
0 to 255
HEX color code
4,360,181

#4287F5 · rgb(66, 135, 245)

HEX code
#4287F5
CSS rgb() string
rgb(66, 135, 245)
Red
66
Green
135
Blue
245

#4287F5

color mix

Red

14.8%

Green

30.3%

Blue

54.9%

Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

To convert RGB to HEX, round and clamp each channel to 0-255, then write each as a two-digit hexadecimal pair and join them after a "#". For example rgb(66, 135, 245) becomes #4287F5. The same channels also form the CSS string rgb(66, 135, 245), describing an identical color.

Formula
HEX = '#' + [R, G, B].map(c => c.toString(16).padStart(2, '0')).join('')
How this is calculated

Each color channel — Red, Green and Blue — is an 8-bit value ranging from 0 to 255. Enter the three channel values; any input is rounded to the nearest integer and clamped into the 0..255 range so out-of-range numbers stay valid.

To build the hex code, every channel is converted from decimal to base-16 (hexadecimal). A single byte (0-255) maps to exactly two hex digits, so each value is padded with a leading zero when needed (for example 5 becomes "05"). The three two-digit pairs are concatenated after a leading "#" and uppercased to produce the standard #RRGGBB format used in CSS and design tools.

The CSS rgb() string simply lists the same clamped integer channels as rgb(R, G, B). Both notations describe the identical color: #FFFFFF equals rgb(255, 255, 255) (white) and #000000 equals rgb(0, 0, 0) (black). The donut shows the relative weight of each channel in the mix.

Frequently asked questions

Standard RGB uses 8 bits per channel, giving 256 possible levels (0-255) for red, green and blue. Values below 0 or above 255 are clamped to that range.

A value from 0 to 255 fits in one byte, which is exactly two hexadecimal digits (00 to FF). Smaller numbers are zero-padded so the result is always six digits total.

Yes. They are two notations for the same color. The hex form is compact while rgb() is more readable; both are valid CSS color values.

Also known as

rgb to hex
rgb to hex converter
color code converter
hex color
css color
convert rgb to hex
rgb to hex code
html color converter

APA

TG we-Calculate Editorial Team. (2026). RGB to HEX Color Converter [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/rgb-to-hex-color-converter

Chicago

TG we-Calculate Editorial Team. "RGB to HEX Color Converter." TG we-Calculate. 2026. https://we-calculate.com/calculator/rgb-to-hex-color-converter.

IEEE

TG we-Calculate Editorial Team, "RGB to HEX Color Converter," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/rgb-to-hex-color-converter

BibTeX

@misc{wecalculate_rgb_to_hex_color_converter, title = {RGB to HEX Color Converter}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/rgb-to-hex-color-converter}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?