RGB to HEX
Convert RGB values to hex colour codes, a whole list at a time.
What this tool does
RGB to HEX reads each line as a colour and writes the sRGB triplet back as a hex colour code. Channels are rounded to the nearest whole number and rendered as two hex digits, so rgb(59, 130, 246) comes back as #3b82f6. What you paste can be a full CSS function, a bare triplet such as 255 255 255 or 59, 130, 246, or percentages like rgb(100% 50% 0%) — a line of loose numbers is read as rgb() provided it carries at least three of them.
Four settings shape the output rather than the colour itself. Uppercase letters turn #3b82f6 into #3B82F6 for codebases that write it that way. The 3-digit form is applied only where every channel pair repeats, so #ffffff collapses to #fff while #ff8801 stays at full length. The leading hash can be switched off for places that supply it themselves, such as an Android colour resource or a query parameter. Translucent colours are either written as 8-digit #RRGGBBAA or cut back to six digits. Each run draws one swatch card per colour — the block of colour carries the full-length code in capitals whatever the settings say, the code in the form you actually asked for sits directly beneath it, and the line you pasted sits under that — and a three-column table follows underneath, listing what you pasted, the hex it became, and the normalised RGB triplet the conversion actually used. Copying takes the bare list of hex codes, one per line, rather than the table.
Three rough edges are worth knowing before you lean on the output. Channel numbers outside 0–255 are clamped with no warning of any kind: rgb(300, -20, 0) converts to #ff0000 and looks like a deliberate red, so an off-by-one in whatever generated the values will not announce itself here. Nothing flags it, but the table's Normalised RGB column shows the triplet the conversion actually used, so reading that against what you pasted is how a stray 300 is caught. Alpha is squeezed into a single byte, so 0.5 becomes the pair 80, which reads back as 0.502; feed 0.502 in again and it still lands on 80, so the loss happens once rather than compounding. And 200 colours is the ceiling for one run; past that the job stops with a count instead of quietly truncating. Lines beginning with // or a hash and a space are skipped as comments, and the whole conversion happens in this browser tab, so the list is not sent anywhere and the page still works with the network off.
How to use it
- Paste one colour per line. rgb() and rgba() functions, bare triplets like 255 255 255, percentages, CSS colour names and hsl(), hwb(), lab() or oklch() values are all accepted.
- Choose the case and the hash. Lowercase with a leading # is the default. Uppercase suits codebases that write hex that way, and the hash can be removed for targets that add it themselves.
- Decide about the 3-digit form. Leave it off for codes that are always full length — six digits, or eight where the alpha is kept — or turn it on to shorten the ones that can be shortened. Colours whose pairs do not repeat are left long either way.
- Decide what happens to translucency. Keep the alpha as an 8-digit hex, or drop it and take the opaque six digits — the right choice when the destination only understands #RRGGBB.
Processing & privacy
Runs on your device. Your file is processed directly in this browser.
Common use cases
Moving values out of a design tool
Pickers in Figma, Sketch and the average image editor hand back separate R, G and B numbers, while the stylesheet wants a single code. Pasting the triplet beats doing the arithmetic by hand.
Normalising the colour notation in a stylesheet
A file that mixes rgb(), colour names and hex is awkward to diff. Running the lot through produces one form, and every card keeps the original line directly beneath the code it resolved to.
Feeding something that only takes hex
Chart libraries, terminal themes, LED and e-ink firmware and a good many config formats accept #RRGGBB and nothing else.
Checking a computed colour from DevTools
The browser reports colours as rgb() or rgba(). Converting one back to hex makes it directly comparable with the design token it was meant to come from.
Questions
Are my colour values sent anywhere?
What happens to rgb(300, -20, 0)?
Why did 50% opacity come back as 80 and not 7f?
Why was my colour not shortened to three digits?
Can I paste something that is not RGB?
Does it handle wide-gamut or print colour?
How do I go the other way?
Related tools
- HEX to RGB — Convert a hex colour to RGB values.
- WCAG Contrast Checker — Test colour pairs against AA and AAA thresholds.
- HEX to HSL — Convert hex to hue, saturation and lightness.
- HSL to HEX — Convert HSL values back to a hex colour.
- CMYK Converter — Convert between RGB and CMYK for print work.
- Color Picker — Pick a colour and copy it in any notation.