Color Code Converter
Color Code Converter
e.g. #31A095, 31a095, #FFF, rgb(49, 160, 149), 49,160,149, hsl(174, 53%, 41%), red
#31A095rgb(49, 160, 149)hsl(174, 53%, 41%)174°, 69%, 63%69%, 0%, 7%, 37%Approximation for screen colorsPaste 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
- Paste or type a color in Color code, for example
#31A095,31a095,rgb(49, 160, 149),49,160,149,hsl(174, 53%, 41%)orteal. All formats update instantly. - Or drag the R, G and B sliders, or type 0–255 in the boxes next to them. That is RGB to HEX.
- 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.
- Drag the A slider to set the Opacity. HEX becomes eight digits (for example
#31A09580) and RGB and HSL becomergba()andhsla(). - Click the copy icon next to a format and paste it straight into CSS, Figma or Photoshop.
- 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?
| Format | Example | What it is | Used in |
|---|---|---|---|
| RGB | rgb(49, 160, 149) | Red, green and blue light, each from 0 to 255; all three at 255 make white | Screens, web, code |
| HEX | #31A095 | The same three RGB numbers, each written as two hexadecimal digits | HTML, CSS, design tools |
| HSL | hsl(174, 53%, 41%) | Hue (0–360°), saturation and lightness; easier than RGB when you want a lighter or softer shade | CSS, color schemes |
| HSV / HSB | 174°, 69%, 63% | Hue, saturation and value (brightness); the color picker in Photoshop and Illustrator uses it | Design software |
| CMYK | 69%, 0%, 7%, 37% | Cyan, magenta, yellow and black ink | Printing |
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:
| Channel | Decimal | ÷ 16 | Hex |
|---|---|---|---|
| R | 49 | 3 remainder 1 | 31 |
| G | 160 | 10 remainder 0 | A0 |
| B | 149 | 9 remainder 5 | 95 |
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 = 49A0= 10 × 16 + 0 = 16095= 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.
| Color | Name | CSS name | HEX | RGB |
|---|---|---|---|---|
| Black, white & gray | ||||
| Black | black | #000000 | 0, 0, 0 | |
| Dim gray | dimgray | #696969 | 105, 105, 105 | |
| Gray | gray | #808080 | 128, 128, 128 | |
| Silver | silver | #C0C0C0 | 192, 192, 192 | |
| Light gray | lightgray | #D3D3D3 | 211, 211, 211 | |
| White | white | #FFFFFF | 255, 255, 255 | |
| Reds & pinks | ||||
| Red | red | #FF0000 | 255, 0, 0 | |
| Dark red | darkred | #8B0000 | 139, 0, 0 | |
| Maroon | maroon | #800000 | 128, 0, 0 | |
| Tomato | tomato | #FF6347 | 255, 99, 71 | |
| Coral | coral | #FF7F50 | 255, 127, 80 | |
| Pink | pink | #FFC0CB | 255, 192, 203 | |
| Hot pink | hotpink | #FF69B4 | 255, 105, 180 | |
| Deep pink | deeppink | #FF1493 | 255, 20, 147 | |
| Oranges, yellows & browns | ||||
| Orange | orange | #FFA500 | 255, 165, 0 | |
| Dark orange | darkorange | #FF8C00 | 255, 140, 0 | |
| Gold | gold | #FFD700 | 255, 215, 0 | |
| Yellow | yellow | #FFFF00 | 255, 255, 0 | |
| Khaki | khaki | #F0E68C | 240, 230, 140 | |
| Beige | beige | #F5F5DC | 245, 245, 220 | |
| Wheat | wheat | #F5DEB3 | 245, 222, 179 | |
| Chocolate | chocolate | #D2691E | 210, 105, 30 | |
| Sienna | sienna | #A0522D | 160, 82, 45 | |
| Brown | brown | #A52A2A | 165, 42, 42 | |
| Greens | ||||
| Lime | lime | #00FF00 | 0, 255, 0 | |
| Green | green | #008000 | 0, 128, 0 | |
| Forest green | forestgreen | #228B22 | 34, 139, 34 | |
| Sea green | seagreen | #2E8B57 | 46, 139, 87 | |
| Spring green | springgreen | #00FF7F | 0, 255, 127 | |
| Olive | olive | #808000 | 128, 128, 0 | |
| Cyans & blues | ||||
| Aqua (cyan) | aqua | #00FFFF | 0, 255, 255 | |
| Teal | teal | #008080 | 0, 128, 128 | |
| Turquoise | turquoise | #40E0D0 | 64, 224, 208 | |
| Sky blue | skyblue | #87CEEB | 135, 206, 235 | |
| Light blue | lightblue | #ADD8E6 | 173, 216, 230 | |
| Dodger blue | dodgerblue | #1E90FF | 30, 144, 255 | |
| Royal blue | royalblue | #4169E1 | 65, 105, 225 | |
| Steel blue | steelblue | #4682B4 | 70, 130, 180 | |
| Blue | blue | #0000FF | 0, 0, 255 | |
| Navy | navy | #000080 | 0, 0, 128 | |
| Purples | ||||
| Lavender | lavender | #E6E6FA | 230, 230, 250 | |
| Violet | violet | #EE82EE | 238, 130, 238 | |
| Fuchsia (magenta) | fuchsia | #FF00FF | 255, 0, 255 | |
| Purple | purple | #800080 | 128, 0, 128 | |
| Indigo | indigo | #4B0082 | 75, 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.