My Tool Studio
Color

RGB to HEX Converter

This rgb to hex converter turns red, green and blue values into a HEX color code you can paste into CSS, Figma or a CMS. Drag the Red, Green and Blue sliders, type numbers from 0 to 255, or paste a value such as rgb(24, 119, 242), rgba(24, 119, 242, 0.5) or just 24, 119, 242. The highlighted result shows the hex code, #1877F2 in this case, and an rgba() input returns an 8 digit hex that keeps the transparency. Developers use it to tidy stylesheets that mix notations, and designers use it when a tool gives channel numbers but a form only takes hex. HSL, HSV, CMYK and OKLCH are listed too, and one click switches to HEX to RGB.

Always freeNo sign upRuns in your browser
Result (HEX)
#6366F1
Lowercase#6366f1
hex#6366F1
rgbrgb(99, 102, 241)
hslhsl(239, 84%, 67%)
hsvhsv(239, 59%, 95%)
cmykcmyk(59%, 58%, 0%, 5%)
oklchoklch(58.54% 0.2041 277.12)

How this conversion is calculated

  1. Divide each channel by 16. The whole part is the first hex digit, the remainder the second.
  2. Red 99 = 6 x 16 + 3, so 63. Green 102 = 6 x 16 + 6, so 66. Blue 241 = 15 x 16 + 1, so F1.
  3. Join them after a #: #6366F1.

Code snippets

CSScolor: #6366F1;
CSS variable--brand: #6366F1;
SCSS$brand: #6366F1;
Swift (UIKit)UIColor(red: 0.388, green: 0.4, blue: 0.945, alpha: 1)
SwiftUIColor(red: 0.388, green: 0.4, blue: 0.945, opacity: 1)
Android XML<color name="brand">#6366F1</color>
Kotlin / Jetpack ComposeColor(0xFF6366F1)
Java (Android)Color.argb(255, 99, 102, 241)
FlutterColor(0xFF6366F1)
Unity C#new Color32(99, 102, 241, 255)
.NET C#Color.FromArgb(255, 99, 102, 241)
Python tuple(99, 102, 241)

Convert a list

Paste up to 1,000 values, one per line. Each line is converted to HEX.

More color formats (HWB, LAB, LCH, OKLab, XYZ and more)
RGB %rgb(38.8%, 40%, 94.5%)
HWBhwb(239 38.8% 5.5%)
OKLaboklab(58.54% 0.0253 -0.2025)
CIE LABlab(50.1% 38.69 -70.49)
CIE LCHlch(50.1% 80.4 298.76)
CIE LUV50.1, -8.88, -111.2
CIE XYZ25.769, 18.504, 85.416
CIE xyY0.1987, 0.1427, 18.504
Decimal6514417
Binary01100011 01100110 11110001
Nearest web safe#6666FF
Common colors reference table

Click a name to load it into the converter.

ColorHEXRGBHSL
#000000rgb(0, 0, 0)hsl(0, 0%, 0%)
#FFFFFFrgb(255, 255, 255)hsl(0, 0%, 100%)
#FF0000rgb(255, 0, 0)hsl(0, 100%, 50%)
#00FF00rgb(0, 255, 0)hsl(120, 100%, 50%)
#0000FFrgb(0, 0, 255)hsl(240, 100%, 50%)
#FFFF00rgb(255, 255, 0)hsl(60, 100%, 50%)
#00FFFFrgb(0, 255, 255)hsl(180, 100%, 50%)
#FF00FFrgb(255, 0, 255)hsl(300, 100%, 50%)
#C0C0C0rgb(192, 192, 192)hsl(0, 0%, 75%)
#808080rgb(128, 128, 128)hsl(0, 0%, 50%)
#800000rgb(128, 0, 0)hsl(0, 100%, 25%)
#808000rgb(128, 128, 0)hsl(60, 100%, 25%)
#008000rgb(0, 128, 0)hsl(120, 100%, 25%)
#800080rgb(128, 0, 128)hsl(300, 100%, 25%)
#008080rgb(0, 128, 128)hsl(180, 100%, 25%)
#000080rgb(0, 0, 128)hsl(240, 100%, 25%)
#FFA500rgb(255, 165, 0)hsl(39, 100%, 50%)
#FF6347rgb(255, 99, 71)hsl(9, 100%, 64%)
#FFD700rgb(255, 215, 0)hsl(51, 100%, 50%)
#4B0082rgb(75, 0, 130)hsl(275, 100%, 25%)

How to use

01

Enter the RGB values

Type or paste into Input (RGB), for example rgb(24, 119, 242) or 24, 119, 242. You can also drag the Red, Green and Blue sliders or type into the number boxes beside them.

02

Check the preview and result

The swatch shows the color and the Result (HEX) card shows the code. If a value is out of range, a message explains the problem, such as a number above 255.

03

Copy the hex code

Press Copy on the result, or on the Lowercase variant if your codebase uses lowercase hex. For rgba() input, HEX without alpha gives the plain 6 digit code as well.

Why RGB to HEX Converter

RGB to hex: the manual method

Converting by hand takes three short divisions. Work through red, green and blue in turn. Divide the number by 16. The whole part becomes the first hex digit and the remainder the second. Use A for 10, B for 11, C for 12, D for 13, E for 14 and F for 15.

Example with rgb(24, 119, 242). Red: 24 / 16 = 1 remainder 8, giving 18. Green: 119 / 16 = 7 remainder 7, giving 77. Blue: 242 / 16 = 15 remainder 2, giving F2. Join them after a hash and you get #1877F2.

RGBHEXColor
rgb(0, 0, 0)#000000Black
rgb(255, 255, 255)#FFFFFFWhite
rgb(255, 0, 0)#FF0000Red
rgb(0, 128, 0)#008000Green
rgb(0, 0, 255)#0000FFBlue
rgb(128, 128, 128)#808080Gray
rgb(255, 165, 0)#FFA500Orange
rgb(24, 119, 242)#1877F2A bright blue

Common questions

How do I convert RGB to hex manually?
Divide each value by 16. The whole number is the first hex digit and the remainder is the second, using A to F for 10 to 15. For 242: 242 / 16 = 15 remainder 2, so F2. Do this for red, green and blue and join the pairs after a #.
How do I convert RGBA to hex with transparency?
Convert the alpha to a 0 to 255 number by multiplying by 255 and rounding, then write it as a hex pair at the end. rgba(24, 119, 242, 0.5) becomes #1877F280, because 0.5 x 255 rounds to 128, which is 80 in hex. The converter does this for you.
What is rgb(255, 255, 255) in hex?
It is #FFFFFF, white. 255 is the largest value one channel can hold, and 255 in hex is FF. rgb(0, 0, 0) is #000000, black.
Why are hex color codes 6 characters long?
Each of the three channels needs two hex digits to cover 0 to 255, since 16 x 16 is 256. Three channels times two digits gives six. An optional seventh and eighth digit add alpha.
Is RGB to hex conversion lossless?
Yes, for whole numbers from 0 to 255. Both notations store the same 8 bits per channel, so converting back and forth gives the same values. Decimal or percentage inputs are rounded to the nearest whole number first.
Can I paste RGB numbers without the rgb() wrapper?
Yes. 24, 119, 242 and 24 119 242 both work. The modern CSS form rgb(24 119 242 / 50%) is accepted too, and percentages such as rgb(100%, 50%, 0%) are converted to 0 to 255 first.
What happens if an RGB value is above 255?
The converter shows the message Each RGB value must be between 0 and 255 and does not produce a code. Browsers clamp such values in CSS, which can hide a typo, so the tool flags it instead.
Does the RGB to HEX converter output uppercase or lowercase?
The main result is uppercase, which is easier to read. The Lowercase row gives the same code in lowercase. CSS treats both the same.
How do I get Swift or Android code for an RGB color?
Scroll to Code snippets under the converter. It shows the same color as a UIColor and SwiftUI Color for iOS, an Android XML color and a Kotlin or Java value, plus Flutter, Unity and .NET, each with its own Copy button.

More Color tools

View all