RGB to HEX Converter
Enter red, green and blue values and get the hex code, with a live swatch and a random-colour button.
Set the red, green and blue channels — each a whole number from 0 to 255 — and this tool builds the matching #RRGGBB hex code live, with a swatch showing the colour. It's the reverse of reading a hex code: here you start from the raw channel values, which is handy when you're tuning a colour by eye or pulling RGB numbers out of a design tool. There's also a random-colour button for quick inspiration. It all runs in your browser.
From three numbers to one hex code
Each channel value is converted from decimal to a two-digit hexadecimal pair, and the three pairs are joined into a single code — rgb(99, 102, 241) becomes #6366F1. Single-digit results are padded with a leading zero (so 5 becomes 05, never 5), which keeps every code a valid six characters. Values are clamped to the 0–255 range, so an out-of-range entry is pulled back to the nearest valid number rather than producing a broken code.
When you want hex instead of RGB
Hex is the most compact way to write a colour and is what most stylesheets, design files and brand guides expect. Converting your RGB values to hex gives you a single token you can drop straight into CSS, a graphics program or a documentation table. The Random Color button rolls three fresh channel values at once — a fast way to explore options or generate a placeholder — and the result updates the swatch and code together so you can copy whatever you land on.
Frequently Asked Questions
What range do the R, G and B fields accept?
Each is a whole number from 0 to 255. If you enter something higher or lower, it is clamped to the nearest valid value so the hex output stays correct.
Why is the hex code always six characters?
Each channel becomes a two-digit hex pair, and single digits are zero-padded — so a value of 5 is written 05. That keeps the code a standard, valid #RRGGBB.
What does the Random Color button do?
It picks a random value from 0 to 255 for all three channels at once and updates the swatch and hex code, which is useful for quick ideas or placeholder colours.
Is the output uppercase or lowercase?
The hex code is shown in uppercase (e.g. #6366F1). Hex colours are case-insensitive, so you can lowercase it in your own code without changing the colour.