Skip to main content

Color Code Converter

Color Code Converter

Paste any color code and the other formats convert instantly. You can also drag the RGB sliders or pick a color.

e.g. #31A095, 31a095, #FFF, rgb(49, 160, 149), 49,160,149, hsl(174, 53%, 41%), red

R
G
B
A
Opacity 100%
White text 3.19 : 1
Black text 6.59 : 1
Contrast ratio: 4.5 : 1 or higher is easy to read for body text (WCAG AA).
HEX
#31A095
RGB
rgb(49, 160, 149)
HSL
hsl(174, 53%, 41%)
HSV / HSB
174°, 69%, 63%
CMYK
69%, 0%, 7%, 37%Approximation for screen colors

Paste any color code and convert RGB to HEX or HEX to RGB instantly, along with HSL, HSV (HSB) and CMYK. HEX with or without #, three-digit shorthand like #FFF, rgb(), hsl() and color names all work, and every format can be copied as ready-to-use CSS. Handy for web pages, design files and brand colors.


How to use the color code converter​

  1. Paste or type a color in Color code, for example #31A095, 31a095, rgb(49, 160, 149), 49,160,149, hsl(174, 53%, 41%) or teal. All formats update instantly.
  2. Or drag the R, G and B sliders, or type 0–255 in the boxes next to them. That is RGB to HEX.
  3. Click the color swatch next to the input to open the color picker. In desktop Chrome and Edge it has an eyedropper that picks any color on your screen.
  4. Drag the A slider to set the Opacity. HEX becomes eight digits (for example #31A09580) and RGB and HSL become rgba() and hsla().
  5. Click the copy icon next to a format and paste it straight into CSS, Figma or Photoshop.
  6. The preview shows the contrast ratio of white and black text on your color. Body text should have at least 4.5 : 1 (WCAG AA), so you can tell whether a button needs white or black text.

What are RGB, HEX, HSL and CMYK?​

FormatExampleWhat it isUsed in
RGBrgb(49, 160, 149)Red, green and blue light, each from 0 to 255; all three at 255 make whiteScreens, web, code
HEX#31A095The same three RGB numbers, each written as two hexadecimal digitsHTML, CSS, design tools
HSLhsl(174, 53%, 41%)Hue (0–360°), saturation and lightness; easier than RGB when you want a lighter or softer shadeCSS, color schemes
HSV / HSB174°, 69%, 63%Hue, saturation and value (brightness); the color picker in Photoshop and Illustrator uses itDesign software
CMYK69%, 0%, 7%, 37%Cyan, magenta, yellow and black inkPrinting

RGB and HEX are two ways of writing the same numbers, so converting between them is exact. HSL and HSV are also calculated from RGB and rounded to whole numbers. CMYK is only an approximation of a screen color; see the FAQ below.

How to convert RGB and HEX by hand​

RGB to HEX: divide each number by 16​

Divide R, G and B by 16. The quotient is the first digit and the remainder the second; 10–15 are written A–F. For RGB 49, 160, 149:

ChannelDecimal÷ 16Hex
R493 remainder 131
G16010 remainder 0A0
B1499 remainder 595

Put them together with a # in front: #31A095.

HEX to RGB: convert each pair back to decimal​

Split the HEX code into pairs and calculate first digit × 16 + second digit (A–F mean 10–15):

  • 31 = 3 × 16 + 1 = 49
  • A0 = 10 × 16 + 0 = 160
  • 95 = 9 × 16 + 5 = 149

For more binary and hexadecimal conversions, use the number base converter.

Three-digit HEX codes​

#FFF and #F60 are shorthand: repeat each digit to get the full code, so #FFF = #FFFFFF and #F60 = #FF6600. Only colors whose pairs are made of two identical digits can be shortened; #31A095 cannot.

RGB to CMYK formula​

Divide R, G and B by 255, then:

  • K = 1 − max(R, G, B)
  • C = (1 − R − K) ÷ (1 − K)
  • M = (1 − G − K) ÷ (1 − K)
  • Y = (1 − B − K) ÷ (1 − K)

For #31A095, K = 1 − 160 ÷ 255 ≈ 37%, C ≈ 69%, M = 0% and Y ≈ 7%.

Converting color codes in Excel and code​

Excel, with R, G and B in A1, B1 and C1:

RGB to HEX: ="#"&DEC2HEX(A1,2)&DEC2HEX(B1,2)&DEC2HEX(C1,2)
HEX to RGB (code in D1, for example #31A095):
R: =HEX2DEC(MID(D1,2,2))
G: =HEX2DEC(MID(D1,4,2))
B: =HEX2DEC(MID(D1,6,2))

The same formulas work in Google Sheets.

JavaScript:

// RGB to HEX
const toHex = (r, g, b) => '#' + [r, g, b].map((v) => v.toString(16).padStart(2, '0')).join('').toUpperCase();
toHex(49, 160, 149); // '#31A095'

// HEX to RGB
const toRgb = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
toRgb('#31A095'); // [49, 160, 149]

Python:

'#{:02X}{:02X}{:02X}'.format(49, 160, 149) # '#31A095'
tuple(int('31A095'[i:i + 2], 16) for i in (0, 2, 4)) # (49, 160, 149)

Color code chart​

The English names below are CSS color names you can use directly in CSS (for example color: tomato;), or paste into the converter above to get the other formats. The 16 original HTML colors (black, gray, silver, white, red, maroon, purple, fuchsia, lime, green, olive, yellow, blue, navy, teal and aqua) are all included.

ColorNameCSS nameHEXRGB
Black, white & gray
Blackblack#0000000, 0, 0
Dim graydimgray#696969105, 105, 105
Graygray#808080128, 128, 128
Silversilver#C0C0C0192, 192, 192
Light graylightgray#D3D3D3211, 211, 211
Whitewhite#FFFFFF255, 255, 255
Reds & pinks
Redred#FF0000255, 0, 0
Dark reddarkred#8B0000139, 0, 0
Maroonmaroon#800000128, 0, 0
Tomatotomato#FF6347255, 99, 71
Coralcoral#FF7F50255, 127, 80
Pinkpink#FFC0CB255, 192, 203
Hot pinkhotpink#FF69B4255, 105, 180
Deep pinkdeeppink#FF1493255, 20, 147
Oranges, yellows & browns
Orangeorange#FFA500255, 165, 0
Dark orangedarkorange#FF8C00255, 140, 0
Goldgold#FFD700255, 215, 0
Yellowyellow#FFFF00255, 255, 0
Khakikhaki#F0E68C240, 230, 140
Beigebeige#F5F5DC245, 245, 220
Wheatwheat#F5DEB3245, 222, 179
Chocolatechocolate#D2691E210, 105, 30
Siennasienna#A0522D160, 82, 45
Brownbrown#A52A2A165, 42, 42
Greens
Limelime#00FF000, 255, 0
Greengreen#0080000, 128, 0
Forest greenforestgreen#228B2234, 139, 34
Sea greenseagreen#2E8B5746, 139, 87
Spring greenspringgreen#00FF7F0, 255, 127
Oliveolive#808000128, 128, 0
Cyans & blues
Aqua (cyan)aqua#00FFFF0, 255, 255
Tealteal#0080800, 128, 128
Turquoiseturquoise#40E0D064, 224, 208
Sky blueskyblue#87CEEB135, 206, 235
Light bluelightblue#ADD8E6173, 216, 230
Dodger bluedodgerblue#1E90FF30, 144, 255
Royal blueroyalblue#4169E165, 105, 225
Steel bluesteelblue#4682B470, 130, 180
Blueblue#0000FF0, 0, 255
Navynavy#0000800, 0, 128
Purples
Lavenderlavender#E6E6FA230, 230, 250
Violetviolet#EE82EE238, 130, 238
Fuchsia (magenta)fuchsia#FF00FF255, 0, 255
Purplepurple#800080128, 0, 128
Indigoindigo#4B008275, 0, 130

FAQ​

How do I convert RGB to HEX?​

Write each of the three numbers from 0 to 255 as a two-digit hexadecimal number (divide by 16: the quotient is the first digit and the remainder the second, with 10–15 written A–F), join them and put # in front. RGB 49, 160, 149 becomes 31, A0 and 95, so the HEX code is #31A095.

How do I convert HEX to RGB?​

Split the HEX code into pairs and turn each pair back into a decimal number: first digit × 16 + second digit, with A–F meaning 10–15. #31A095 splits into 31, A0 and 95, which is RGB 49, 160, 149.

Can I convert a HEX code to Pantone?​

Not exactly. Pantone colors are numbered inks mixed to a recipe, not values you can calculate from RGB. Design tools and Pantone’s own guides can suggest the closest Pantone match for a HEX color, but always check a printed swatch. This converter works with the screen color codes used in web and design files.

What does a three-digit code like #FFF mean?​

It is shorthand for a six-digit code: repeat each digit, so #FFF is #FFFFFF (white) and #F60 is #FF6600. Only colors whose pairs are two identical digits can be written this way.

How do I add transparency to a color code?​

Add two more digits to the HEX code to get an eight-digit #RRGGBBAA code: 00 is fully transparent, FF is opaque and 80 is about 50%. In RGB, write rgba(49, 160, 149, 0.5), where the last number from 0 to 1 is the opacity.

Why does CMYK print differently from the screen?​

Screens mix RGB light and printers use CMYK ink, and the two can show different ranges of color, so very bright RGB colors cannot be printed. Any RGB to CMYK conversion online is a formula-based approximation; the real printed color also depends on the printer, paper and color profile. For important print jobs, ask the printer for a proof.

How do I find the color code of something on my screen?​

In desktop Chrome or Edge, click the swatch next to the input in this tool and use the eyedropper to pick any color on your screen. For colors on a web page you can also open the browser’s developer tools (F12) and look at the CSS. On Windows, Microsoft PowerToys has a color picker (Win + Shift + C); macOS comes with Digital Color Meter.

Are HEX codes case-sensitive?​

No. #31A095 and #31a095 are the same color, and CSS and most software accept both. This tool always shows uppercase.