RGB to HEX

Convert RGB and RGBA values to HEX color codes.

Type a RGB value or pick a color – the result updates instantly.

​

Preview

RGB to HEX Converter

Type three channel values – for example 138, 43, 226 – and get the HEX color code #8A2BE2 (Blue Violet). The tool accepts rgb() and rgba() notation, bare comma- or space-separated numbers, and percentages, and it previews the color as you type.

Converting a channel step by step

Every channel from 0 to 255 fits into two hexadecimal digits. Divide by 16: the quotient is the first digit and the remainder the second.

Channel Decimal ÷ 16 HEX
Red 138 8 r 10 8A
Green 43 2 r 11 2B
Blue 226 14 r 2 E2

Joined together, rgb(138, 43, 226) is #8A2BE2. Values below 16 need a leading zero, so a channel of 9 is written 09, not 9.

Transparency

If you paste an rgba() value with an alpha below 1, the result gains a fourth pair. rgba(138, 43, 226, 0.5) becomes #8A2BE280, because 0.5 × 255 = 127.5, which rounds to 128 (hex 80). The "All formats" table below the result always lists both the plain and the alpha version.

Common reasons to convert

  • CSS and style guides: many teams standardize on HEX because it is short and easy to search for in a codebase.
  • Screenshots and color pickers: operating system pickers and image editors often report RGB, while your stylesheet expects HEX.
  • Design tokens: tools such as Tailwind config files, SVG fill attributes, and Android XML resources commonly use #RRGGBB.
  • Sharing colors: one short code is easier to paste into a chat or a ticket than three numbers.

RGB and HEX are two spellings of the same 8-bit value, so the conversion is exact. To decode a code back into channels, use HEX to RGB; for a color's position on the color wheel, try RGB to HSV.

Frequently Asked Questions

Divide each channel by 16. The whole number is the first hex digit and the remainder is the second, with 10 to 15 written as A to F. For 226: 226 / 16 = 14 remainder 2, so it becomes E2.

You can type rgb(138, 43, 226), rgba(138, 43, 226, 0.5), 138, 43, 226, or 138 43 226. Percentages such as rgb(100%, 50%, 0%) also work.

When the alpha is below 1, the result becomes an 8-digit HEX code. rgba(138, 43, 226, 0.5) converts to #8A2BE280, because 0.5 × 255 rounds to 128, which is 80 in hex.

No. #8A2BE2 and #8a2be2 are the same color. The converter outputs uppercase, which many style guides prefer for readability.