Format Code Now
/
Web & markupRGB to Hex Converter Next: Hex to HSL Converter ›

RGB to Hex Converter

WM-07

Paste rgb() colors, one per line, and get hex codes back. Write the numbers as rgb(255, 136, 0), rgb(255 136 0) or just 255 136 0.

Runs in your browser. Nothing is uploaded.

RGB colors, one per line

Hex

How to use it

  1. Paste one RGB color per line.
  2. Choose uppercase letters or the short form if you want them. The short form is only used when it is exact.
  3. Read the hex codes in the result box. A color with alpha comes out as 8-digit hex.
  4. Copy the result or download it.

What counts as RGB input

rgb() and rgba() are read in the older comma form and the newer space form, including a slash before alpha, as in rgb(0 0 0 / 50%). Each channel can be a number or a percentage. Decimals are rounded to the nearest whole number, and anything above 255 or below 0 is clamped to the range rather than rejected. A bare list of three numbers separated by spaces or commas is accepted too, which is handy when you copy values from a design tool.

Alpha and the short form

When alpha is below 1 the result has eight digits, with alpha scaled to a byte: 0.5 becomes 80, since 0.5 times 255 is 127.5 and rounds up to 128. An alpha of 1 is left off, so you get a normal six digit code. The short form such as #f80 is only produced when every pair of digits repeats, so no information is lost. Turn it off if you want every code to be the same length.

How it runs

The arithmetic happens in your browser, so the colors you paste are not uploaded anywhere. Other formats such as hsl(), hsv(), cmyk() and CSS color names are also read and written as hex, which makes this page work as a general to-hex converter.

Error messages and what to do

MessageWhat it meansFix
Line 1: rgb() needs 3 values, plus an optional alpha, but has 2The function has too few or too many numbers.Give red, green and blue, and an optional fourth value for alpha.
Line 1: "1 2" has 2 values; RGB needs 3A plain list of numbers must have exactly three values.Add the missing channel, or write the color as rgb(r, g, b).

Questions people ask

How do I convert RGB to hex?

Write each channel as two hex digits and join them. For rgb(255, 136, 0), 255 is ff, 136 is 88 and 0 is 00, so the code is #ff8800. Paste your values above and the page does this for every line.

How do I convert rgba to hex?

Convert the three channels as usual, then multiply alpha by 255, round it and add it as a fourth pair. rgba(0, 0, 0, 0.5) becomes #00000080. Browsers read 8-digit hex in CSS, but very old software may not.

Can I paste values like 255, 136, 0 without rgb()?

Yes. A list of three numbers separated by spaces or commas works. That is useful for values copied from a color picker. Percent signs are accepted too, so 100% 50% 0% is read as percentages of 255.

Why is my hex code in lowercase?

Lowercase is the default and is the common style in CSS. Tick Uppercase hex letters to get #FF8800 instead. Both forms mean the same color, and CSS does not care about the case.

What happens to values above 255?

They are clamped to 255, and negative values to 0, the way CSS treats out-of-range channels. rgb(300, -5, 0) becomes #ff0000. The page does not warn about it, so check your source if the result looks wrong.

About this tool

Reads rgb() and rgba() in the older comma form and the newer space form with a slash for alpha. Channel values can be numbers from 0 to 255 or percentages; decimals are rounded to the nearest whole number and anything outside the range is clamped. A plain list such as 255 136 0 or 255, 136, 0 also works. When the color has an alpha below 1 the result is an 8-digit hex, with alpha rounded to the nearest byte; an alpha of 1 gives a normal 6-digit code. The short form (#f80) is only used when every pair of digits repeats. Any other color format works as input too: hex, rgb(), hsl(), hsv(), cmyk() or a CSS color name.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.