RGB to HEX converter

To convert RGB to HEX, write each red, green and blue value (0–255) as a two-digit base-16 number and join them after #: rgb(37, 99, 235) = #2563eb. Paste any rgb() or rgba() value below to convert it.

Paste an rgb() or rgba() value from your CSS, a design tool or a browser inspector and get the matching HEX code, with alpha kept as an 8-digit HEX.

HEX#2563eb
RGBrgb(37, 99, 235)
HSLhsl(221, 83%, 53%)

How to convert RGB to HEX

Start with rgb(37, 99, 235). Divide each channel by 16: the whole number is the first hex digit and the remainder is the second (10–15 are written a–f). 37 → 2 r 5 = 25, 99 → 6 r 3 = 63, and 235 → 14 r 11 = eb. Join the pairs after a hash to get #2563eb. Values under 16 get a leading zero, so 5 becomes 05.

For rgba(), convert the alpha too: multiply it by 255 and write the result as two hex digits at the end. An alpha of 0.5 becomes 128, which is 80 in hex, so rgba(0, 0, 0, 0.5) is #00000080.

Common RGB to HEX values

ColorRGBHEXHSL
Whitergb(255, 255, 255)#ffffffhsl(0, 0%, 100%)
Blackrgb(0, 0, 0)#000000hsl(0, 0%, 0%)
Redrgb(239, 68, 68)#ef4444hsl(0, 84%, 60%)
Bluergb(37, 99, 235)#2563ebhsl(221, 83%, 53%)
Greenrgb(34, 197, 94)#22c55ehsl(142, 71%, 45%)
50% transparent blackrgba(0, 0, 0, 0.5)#00000080hsla(0, 0%, 0%, 0.5)

RGB to HEX converter FAQs

How do I convert RGB to HEX?

Convert each of the three channels (0 to 255) into a two-digit base-16 number, padding with a leading zero when needed, then join them after a hash. For rgb(37, 99, 235): 37 is 25, 99 is 63 and 235 is eb, so the HEX code is #2563eb.

How do I convert rgba() with transparency to HEX?

Convert the red, green and blue channels as usual, then multiply the alpha (0 to 1) by 255, round it and write it as two hex digits at the end. rgba(0, 0, 0, 0.5) gives 0.5 × 255 = 127.5, rounded to 128, which is 80 in hex, so the result is the 8-digit code #00000080.

Why is my HEX code 3 digits sometimes?

Three-digit HEX is CSS shorthand that works when both digits of every pair are the same: #fff means #ffffff and #f00 means #ff0000. A color like #2563eb has no shorthand. This converter always outputs the full six-digit form, which every browser and design tool accepts.

Related color tools

More color tools

Image tools

CSS generators

Image & SVG tools

Typography & units

More free tools

All free tools