๐จ RGB to Hex Converter: Turn R, G, B Values into a Hex Code
By Shihab Mia ยท Updated 2026-08-01
#4285F4 is rgb(66, 133, 244).
An RGB to hex converter turns three 0 to 255 numbers into the six-digit hex code CSS, design tools, and image editors expect. Enter the red, green, and blue values and the tool converts each channel to a two-digit hexadecimal pair, combines them into a single hex code, and shows a live swatch alongside the equivalent CSS rgb() string. There is no math to do by hand and no risk of a typo in the hex output.
What is the RGB to Hex Converter?
RGB and hex are two different ways of writing down the exact same color, not two different color systems. RGB describes a color as three separate numbers, one each for red, green, and blue light, every one ranging from 0 (none of that light) to 255 (full intensity). Hex takes those same three numbers and packs them into a single six-character string, written in base 16 instead of base 10, so a color can be pasted as one compact token into CSS, HTML, or a design tool instead of three separate fields.
The rgb to hex conversion works one channel at a time. Each 0 to 255 value is converted to a two-digit hexadecimal pair, where the digits run 0 to 9 and then A to F to represent 10 through 15. Because hexadecimal is base 16, two digits cover 16 times 16, or 256 possible values, which lines up exactly with the 0 to 255 range of an RGB channel. The three two-digit pairs are then joined in order (red, then green, then blue) and prefixed with a hash to form the finished hex code, such as #4285F4.
A hex code is really just RGB written more compactly. Splitting #4285F4 back into its pairs gives 42, 85, and F4, and converting each pair from base 16 back to base 10 gives 66, 133, and 244, exactly the RGB values that produced it. This is why the two formats are always interchangeable with no loss of precision: hex is not an approximation of RGB, it is the same three numbers in a different, denser notation that happens to be one string instead of three.
This matters practically because CSS, SVG, image editing software, and most design systems default to accepting hex codes, while color pickers, canvas APIs, and some code libraries hand you RGB triples instead. Anyone copying a color from a screenshot tool, a browser inspector, or a design spec that only lists R, G, and B numbers needs to convert to hex before pasting it into a stylesheet or a hex-only input field. Doing the base conversion by hand is slow and error-prone for six digits at a time, which is exactly the gap an rgb to hex converter closes.
When to use it
- Converting an RGB triple copied from a color picker, a design spec, or a browser dev tool into a hex code for CSS.
- Checking the hex equivalent of a brand color that a client or design system only supplied as RGB numbers.
- Verifying that a hex code someone gave you actually matches the RGB values they described elsewhere.
- Building a small palette of hex swatches quickly by sliding through RGB values and copying each result.
How to use the RGB to Hex Converter
- Enter the Red value (0 to 255) using the slider or the number field.
- Enter the Green value (0 to 255) the same way.
- Enter the Blue value (0 to 255) the same way.
- Read the hex code and CSS rgb() string from the output fields, or press Copy hex to paste it directly into your CSS.
Formula & method
Worked examples
Convert rgb(66, 133, 244), a common bright blue, to hex.
- Red: 66 in base 16 is 42
- Green: 133 in base 16 is 85
- Blue: 244 in base 16 is F4
- Join the pairs: 42 + 85 + F4
- Prefix with #
Result: Result is #4285F4
Convert rgb(255, 87, 34), a warm orange, to hex.
- Red: 255 in base 16 is FF
- Green: 87 in base 16 is 57
- Blue: 34 in base 16 is 22
- Join the pairs: FF + 57 + 22
- Prefix with #
Result: Result is #FF5722
Common decimal to hex channel conversions (0-255 range)
| Decimal (0-255) | Hex pair |
|---|---|
| 0 | 00 |
| 16 | 10 |
| 64 | 40 |
| 128 | 80 |
| 192 | C0 |
| 244 | F4 |
| 255 | FF |
A few well-known RGB values and their hex codes
| Color | RGB | Hex |
|---|---|---|
| Pure red | rgb(255, 0, 0) | #FF0000 |
| Pure white | rgb(255, 255, 255) | #FFFFFF |
| Pure black | rgb(0, 0, 0) | #000000 |
| Mid grey | rgb(128, 128, 128) | #808080 |
| Google blue | rgb(66, 133, 244) | #4285F4 |
Common mistakes to avoid
- Entering a value above 255 or below 0. Each RGB channel only has meaning between 0 and 255. Typing 300 or -10 does not describe a brighter or dimmer light value, it is simply outside range, so the converter clamps it back to 255 or 0 and flags the field.
- Forgetting the leading hash on the hex code. CSS, HTML, and most design tools expect a hex color to start with #. Pasting just 4285F4 without the hash will be read as plain text or an invalid value in many contexts, not a color.
- Mixing up the channel order. Hex pairs are always read in red, green, blue order, matching RGB. Swapping the order (for example reading a hex code as blue, green, red) produces a completely different, wrong color.
- Assuming decimals are allowed in RGB channels. RGB values are whole numbers only. A value like 133.5 is not a valid channel; the converter rounds it, but the source data or design tool it came from may have had an error worth double-checking.
Glossary
- RGB
- A color model that describes a color with three numbers, one each for red, green, and blue light, every one from 0 to 255.
- Hex code
- A six-digit color value written as a hash followed by three base-16 pairs for red, green, and blue, such as #4285F4.
- Hexadecimal (base 16)
- A number system using 16 digits, 0-9 then A-F, where two digits can represent any value from 0 to 255.
- Channel
- One of the three components of an RGB color (red, green, or blue), each stored and converted independently.
- Clamping
- Forcing an out-of-range value back into the valid 0-255 range instead of rejecting it outright.
- CSS rgb() function
- A CSS color notation that writes the three channel values directly, such as rgb(66, 133, 244), as an alternative to a hex code.
Frequently asked questions
How do I convert RGB to hex?
Convert each of the red, green, and blue values (0-255) into a two-digit hexadecimal pair, then join the three pairs in order and add a leading hash. For example, rgb(66, 133, 244) becomes #4285F4.
Why does hex use letters like A to F?
Hex is base 16, so it needs 16 digits per position. After 0-9 it continues with A through F to represent the values 10 through 15, letting two digits cover the full 0-255 range of an RGB channel.
What happens if I enter a number above 255?
The converter clamps it back to 255 (or 0 if it is negative) and shows a short note, since 0-255 is the only valid range for an RGB channel and anything outside it has no meaningful color value.
Is hex the same color as RGB, or an approximation?
It is the exact same color with no rounding or loss. Hex is just RGB written as base-16 pairs instead of base-10 numbers, so converting back and forth always returns the original values.
Do hex codes have to be uppercase?
No, hex letters A-F work the same in uppercase or lowercase in CSS and HTML. This tool outputs uppercase for readability, but #4285f4 and #4285F4 are identical colors.
Can I convert a hex code back to RGB with this tool?
This tool is built for RGB to hex in that direction. To go the other way, split the hex code into its three pairs and convert each from base 16 back to base 10, or use a dedicated hex to RGB converter.
Sources
- CSS Color Value Types , MDN Web Docs