RGB to HEX

Convert RGB values to hex colour codes, a whole list at a time.

Runs on your deviceDesign & ColorWorkingNo account needed

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

  1. 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.
  2. 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.
  3. 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.
  4. 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?
No. The parsing and the arithmetic are done by JavaScript inside this page, so nothing is transmitted or logged, and the tool behaves identically on a laptop with the wifi switched off.
What happens to rgb(300, -20, 0)?
It clamps to #ff0000. Channels outside 0–255 are pulled to the nearest legal value rather than rejected, and no warning is shown. The clamped rgb(255, 0, 0) is never printed anywhere; what the card shows is the line you pasted, so the stray 300 is still on screen, but nothing flags it and you have to catch it yourself.
Why did 50% opacity come back as 80 and not 7f?
Alpha becomes one byte in an 8-digit hex. 0.5 × 255 is 127.5, which rounds up to 128, and 128 is 80 in hexadecimal. Convert that pair back and you get 0.502, so a fraction rarely survives a round trip untouched.
Why was my colour not shortened to three digits?
The short form only exists where each pair is a repeated digit. #ffcc00 becomes #fc0, but #ffcc01 cannot shorten because 01 is not a repeat. When alpha is included, its pair has to repeat as well.
Can I paste something that is not RGB?
Yes. Hex, CSS colour names, hsl(), hwb(), lab(), lch(), oklab(), oklch() and color(srgb …) are all read, so a mixed list from a stylesheet converts without being sorted into notations first.
Does it handle wide-gamut or print colour?
No. Inside color() only srgb and srgb-linear are understood — color(display-p3 1 0 0) is refused by name rather than converted — and a P3 triplet pasted as bare numbers is simply read as sRGB. Nothing else carries an ICC profile either, and a lab() or oklch() colour outside sRGB is clipped channel by channel, which can shift the hue as well as the intensity.
How do I go the other way?
HEX to RGB takes hex codes and returns rgb() values in four notations. HEX to HSL and CMYK Converter cover the other colour models.

Related tools