Skip to content

RGB to HEX Converter

Convert RGB to HEX: enter RGB values or paste an rgb() color to get its hex code.

RGB values (0–255) and alpha (0–1)

rgb(30, 144, 255), rgba(30, 144, 255, 0.5) or rgb(30 144 255 / 50%)

HEX
#1E90FF
CSS
rgb(30, 144, 255)

Need the reverse? Use the HEX to RGB converter. For an opacity slider and Android #AARRGGBB output, try the RGBA to HEX converter.

How to convert RGB to HEX

  1. Enter red, green and blue values from 0 to 255 — or paste an rgb() or rgba() value.
  2. Set alpha below 1 if the color should be transparent.
  3. Copy the 6-digit HEX code, the 8-digit version with alpha, or the short form when there is one.

How the conversion works

Each channel is written as a two-digit hexadecimal number (00–FF) and the three are joined after a #. Numbers below 16 get a leading zero, so 9 becomes 09.

rgb(46, 139, 87) → #2E8B57
46  → 2 × 16 + 14 → 2E
139 → 8 × 16 + 11 → 8B
87  → 5 × 16 + 7  → 57

Alpha is scaled from 0–1 to 0–255 and added as a fourth pair. When every pair has two identical digits, CSS also accepts a short form: #FFCC00 can be written #FC0.

Features

  • Number fields with validation: values outside 0–255 are reported, not clamped.
  • Paste CSS values in comma or space syntax, including percentages.
  • 6-digit, 8-digit (with alpha) and short HEX output with a live preview.

RGB to HEX examples

RGB and RGBA values with their HEX codes
SwatchHEXRGB / RGBA
#FFFFFFrgb(255, 255, 255)
#000000rgb(0, 0, 0)
#FF6347rgb(255, 99, 71)
#1E90FFrgb(30, 144, 255)
#2E8B57rgb(46, 139, 87)
#FFD700rgb(255, 215, 0)
#00000080rgba(0, 0, 0, 0.5)
#1E90FF40rgba(30, 144, 255, 0.25)

Common RGB to HEX mistakes

  • Dropping the leading zero. Every channel needs two digits: rgb(9, 9, 9) is #090909, not #999 — which is a much lighter gray.
  • Swapping the channel order. Some APIs, such as Windows GDI and OpenCV, store colors as BGR. Paste those values in the wrong order and red and blue trade places.
  • Using the wrong scale. Values from 0 to 1 (as in many shaders and design APIs) must be multiplied by 255 first: 0.5 is 128, or 80 in HEX.
  • Losing transparency. A 6-digit HEX code is always opaque. Keep alpha with an 8-digit code, which the RGBA to HEX converter handles in CSS and Android order.

RGB and HEX values of common colors

Common colors with their RGB, HEX and approximate CMYK values. Linked names have their own page with shades and matching colors.
ColorRGBHEXCMYK
Gold255, 215, 0#FFD7000%, 16%, 100%, 0%
White255, 255, 255#FFFFFF0%, 0%, 0%, 0%
Blue0, 0, 255#0000FF100%, 100%, 0%, 0%
Green0, 128, 0#008000100%, 0%, 100%, 50%
Red255, 0, 0#FF00000%, 100%, 100%, 0%
Orange255, 165, 0#FFA5000%, 35%, 100%, 0%
Black0, 0, 0#0000000%, 0%, 0%, 100%
Yellow255, 255, 0#FFFF000%, 0%, 100%, 0%
Grey128, 128, 128#8080800%, 0%, 0%, 50%
Pink255, 192, 203#FFC0CB0%, 25%, 20%, 0%
Royal Blue65, 105, 225#4169E171%, 53%, 0%, 12%
Brown165, 42, 42#A52A2A0%, 75%, 75%, 35%
Purple128, 0, 128#8000800%, 100%, 0%, 50%
Light Blue173, 216, 230#ADD8E625%, 6%, 0%, 10%
Cream255, 253, 208#FFFDD00%, 1%, 18%, 0%
Teal0, 128, 128#008080100%, 0%, 0%, 50%
Dark Blue0, 0, 139#00008B100%, 100%, 0%, 45%
Beige245, 245, 220#F5F5DC0%, 0%, 10%, 4%
Sky Blue135, 206, 235#87CEEB43%, 12%, 0%, 8%
Maroon128, 0, 0#8000000%, 100%, 100%, 50%
Dark Green0, 100, 0#006400100%, 0%, 100%, 61%
Sage Green156, 175, 136#9CAF8811%, 0%, 22%, 31%
Khaki240, 230, 140#F0E68C0%, 4%, 42%, 6%
Burgundy128, 0, 32#8000200%, 100%, 75%, 50%
Navy Blue0, 0, 128#000080100%, 100%, 0%, 50%
Emerald Green80, 200, 120#50C87860%, 0%, 40%, 22%
Light Grey211, 211, 211#D3D3D30%, 0%, 0%, 17%
Magenta255, 0, 255#FF00FF0%, 100%, 0%, 0%
Silver192, 192, 192#C0C0C00%, 0%, 0%, 25%
Lavender230, 230, 250#E6E6FA8%, 8%, 0%, 2%
Lime0, 255, 0#00FF00100%, 0%, 100%, 0%
Cyan0, 255, 255#00FFFF100%, 0%, 0%, 0%
Coral255, 127, 80#FF7F500%, 50%, 69%, 0%
Tomato255, 99, 71#FF63470%, 61%, 72%, 0%
Crimson220, 20, 60#DC143C0%, 91%, 73%, 14%
Hot Pink255, 105, 180#FF69B40%, 59%, 29%, 0%
Turquoise64, 224, 208#40E0D071%, 0%, 7%, 12%
Dodger Blue30, 144, 255#1E90FF88%, 44%, 0%, 0%
Indigo75, 0, 130#4B008242%, 100%, 0%, 49%
Olive128, 128, 0#8080000%, 0%, 100%, 50%

Related color tools

The other color converters: HEX to RGB, RGBA to HEX, RGB to CMYK and CMYK to RGB. To find a color visually, use the color picker; for every CSS color name, see the HTML color codes.

Frequently asked questions

How do I convert RGB to HEX by hand?
Convert each channel (0–255) to a two-digit base-16 number and join them. rgb(30, 144, 255) becomes 1E, 90 and FF, so the HEX code is #1E90FF.
How is alpha converted?
Alpha from 0 to 1 is multiplied by 255 and written as two more hex digits. An alpha of 0.5 becomes 80, so rgba(30, 144, 255, 0.5) is #1E90FF80.
Why does the converter reject 256 or negative values?
Each RGB channel is one byte, so it must be between 0 and 255. Instead of silently clamping a typo to a different color, the converter tells you which value is out of range.
Can I use decimals?
Yes. CSS allows fractional RGB values, so the converter accepts them and rounds to the nearest whole number for the HEX code.
Can I set alpha as a percentage?
Paste a value such as rgb(30 144 255 / 50%) and the percentage is converted to the alpha pair (80). For an opacity slider and the Android #AARRGGBB order, use the RGBA to HEX converter.
What are the HEX codes for black, white and pure red?
Black rgb(0, 0, 0) is #000000, white rgb(255, 255, 255) is #FFFFFF and pure red rgb(255, 0, 0) is #FF0000. The reference table on this page lists about 40 more common colors with their RGB, HEX and CMYK values.
Why are red and blue swapped after converting?
The values probably came from a source that stores colors as BGR, such as Windows GDI or OpenCV. Enter them in R, G, B order — or swap the first and last numbers — before converting.
Should I use HEX or rgb() in CSS?
Either: browsers treat #1E90FF and rgb(30 144 255) as exactly the same color. HEX is shorter and common in design handoffs; rgb() is easier to read and to give an alpha value, as in rgb(30 144 255 / 50%).