RGB to HEX Converter

Enter red, green and blue from 0 to 255, or paste an rgb() value.

RGB → HEX
#2E8B57seagreen
HEX#2E8B57
RGBrgb(46, 139, 87)
HSLhsl(146, 50%, 36%)
HSV / HSBhsv(146, 67%, 55%)
CMYKcmyk(67%, 0%, 37%, 45%)
OKLCHoklch(56.9% 0.119 154.9)

Contrast

Aa
4.25:1on white
AAAA largeAAA
Aa
4.95:1on black
AAAA largeAAA

Nearest CSS name

seagreen#2E8B57Details →

Code

Tailwindbg-[#2e8b57]
SwiftUIColor(red: 0.18, green: 0.545, blue: 0.341)
AndroidColor.parseColor("#2E8B57")
FlutterColor(0xFF2E8B57)

How do you convert RGB to HEX?

Convert each of the three values (0 to 255) to a two-digit base-16 number and write them one after another behind a #. Divide the value by 16: the whole number is the first digit and the remainder is the second, with 10 to 15 written as A to F. Values below 16 get a leading zero.

Example: rgb(46, 139, 87)

ChannelValueCalculationHex
Red462 × 16 + 142E
Green1398 × 16 + 118B
Blue875 × 16 + 757

So rgb(46, 139, 87) = #2E8B57, which happens to be the CSS color seagreen.

What is the RGB to HEX formula?

first digit = floor(value ÷ 16)
second digit = value mod 16
HEX = # + RR + GG + BB

How do you convert RGBA to HEX?

Multiply the alpha (0 to 1) by 255, round it, and add it as a fourth pair. rgba(46, 139, 87, 0.5) becomes #2E8B5780 because 0.5 × 255 = 127.5, rounded to 128 = 80 in hex. Paste an rgba() value above to see it.

How do I convert RGB to HEX in JavaScript or Python?

// JavaScript
const toHex = (r, g, b) => "#" + [r, g, b].map(v => v.toString(16).padStart(2, "0")).join("").toUpperCase();
toHex(46, 139, 87); // "#2E8B57"

# Python
"#{:02X}{:02X}{:02X}".format(46, 139, 87)  # '#2E8B57'

Is HEX the same as RGB?

Yes, for web colors they describe the same sRGB values in different notation. #2E8B57 and rgb(46, 139, 87) render identically; hex is shorter, rgb() is easier to read and edit. Both are defined in W3C, CSS Color Module Level 4.

Common RGB values in HEX

HEXRGBCMYKName
#FFFFFF255, 255, 2550, 0, 0, 0white
#0000000, 0, 00, 0, 0, 100black
#FF0000255, 0, 00, 100, 100, 0red
#00FF000, 255, 0100, 0, 100, 0lime
#0000FF0, 0, 255100, 100, 0, 0blue
#FFFF00255, 255, 00, 0, 100, 0yellow
#00FFFF0, 255, 255100, 0, 0, 0aqua
#FF00FF255, 0, 2550, 100, 0, 0fuchsia
#808080128, 128, 1280, 0, 0, 50gray
#FFA500255, 165, 00, 35, 100, 0orange
#800080128, 0, 1280, 100, 0, 50purple
#0080800, 128, 128100, 0, 0, 50teal
#1E90FF30, 144, 25588, 44, 0, 0dodgerblue
#2E8B5746, 139, 8767, 0, 37, 45seagreen
#FF5733255, 87, 510, 66, 80, 0

Formulas checked October 2026 against W3C, CSS Color Module Level 4.

Color names

All color names →

Frequently asked questions

What is rgb(255, 255, 255) in hex?

#FFFFFF, which is white.

How do I convert rgba to hex?

Multiply the alpha by 255, round it and add it as two more hex digits. rgba(46, 139, 87, 0.5) is #2E8B5780.

Why does my hex code have a leading zero?

Every channel needs two hex digits. A value below 16 is written with a leading zero, so 10 becomes 0A.

Are hex codes case sensitive?

No. #2e8b57 and #2E8B57 are the same color.