HEX to RGB Converter

Convert HEX to RGB from shorthand, six-digit or alpha codes, see exactly how each pair decodes, and find the nearest Pantone ink.

HEX Code

Accepts 3, 4, 6 or 8 digits, with or without #.

Expanded
#C8102E
Pair by pair
Red
C8
200
Green
10
16
Blue
2E
46
Alpha
none, so opaque

Try shorthand like #F0A or an alpha code like #C8102E80.

Your colour in RGB

rgb(200, 16, 46)

#C8102E

#C8102E in every format

Alpha has no CMYK equivalent, so the CMYK chip describes the colour as fully opaque, using the uncalibrated formula.

From screen to print

The closest Pantone match for this colour

A hex code only describes light on a screen, so here are the three Pantone Matching System inks closest to #C8102E, each shown on coated (C) and uncoated (U) stock.

  1. Coated
    Uncoated
    Best matchPantone 186-C100.0% match
  2. Coated
    Uncoated
    Match 2Pantone 200-C97.6% match
  3. Coated
    Uncoated
    Match 3Pantone 193-C96.2% match

Match this code in HEX to Pantone

Scores use the same weighted RGB ranking as our Pantone converters, and a printed swatch book is the final check.

Reading a Hex Code: Pairs, Positions and Base 16

A six-digit hex code is three numbers packed side by side. Read it in pairs from the left: the first pair is red, the second green, the third blue. Nothing in the code labels the pairs, so position is the only thing that tells a parser which channel is which — swap two pairs and you have a different colour, not a typo that software can catch.

Each pair is a two-digit number in base 16. The left digit counts sixteens and the right digit counts ones, with the letters A to F standing in for ten to fifteen. Case makes no difference, so #c8102e and #C8102E are the same HTML color code; uppercase is simply easier to read on a spec sheet. Here is #C8102E decoded one pair at a time:

  1. C8 — C is 12, and 12 × 16 = 192; add 8 and red is 200.
  2. 10 — 1 × 16 = 16; add 0 and green is 16.
  3. 2E — 2 × 16 = 32; add E, which is 14, and blue is 46.
  4. Written as CSS, the colour is rgb(200, 16, 46).

The # is punctuation rather than part of the value. CSS insists on it, but design tools, spreadsheets and brand documents often drop it, so this converter reads codes with or without one. Source code frequently writes the same number as 0xC8102E, and the helper most libraries call hex2rgb expects the plain digits; neither form is valid inside a stylesheet. For the reverse direction, the RGB to HEX converter encodes channel values back into a code.

How Shorthand Codes Expand

Three- and four-digit codes are shorthand, and they expand by doubling every digit, never by padding with zeros. #F0A becomes #FF00AA, not #F000A0. The rule is mechanical, so a parser never has to guess, and it is also why #ABC and #A0B0C0 are unrelated colours despite looking alike.

Doubling a digit multiplies its value by 17: a lone F becomes FF, which is 15 × 17 = 255, and a lone 8 becomes 88, which is 136. Shorthand can therefore express only channel values that are multiples of 17 — sixteen levels per channel rather than 256, and 4,096 colours in total rather than more than sixteen million.

That ceiling is why most brand colours have no shorthand at all. Of the sixteen basic CSS colours in the table at the end of this page, 8 can be shortened; the rest use pairs such as 80 and C0, which are not doubled digits.

8-Digit Codes and the Alpha Channel

An eight-digit code adds a fourth pair for alpha, the opacity of the colour, and CSS places it last. #C8102E80 is red 200, green 16, blue 46 and alpha 80. The alpha pair decodes like any other — 80 is 128 — but CSS expresses opacity as a fraction, so a hex to RGBA conversion divides that byte by 255: 128 ÷ 255 is about 0.502.

So #C8102E80 becomes rgba(200, 16, 46, 0.502). In current CSS the same colour can also be written rgb(200 16 46 / 50.2%), because the Level 4 syntax lets rgb() carry alpha directly and keeps rgba() only as a legacy alias. A four-digit code follows the same path after expansion: #C80A is #CC8800AA, with an alpha of 170 ÷ 255, about 0.667.

Alpha bytes nearest each 10% opacity step
Alpha pairDecimalOpacity
FF2551 (100%)
E62300.902 (90.2%)
CC2040.8 (80%)
B31790.702 (70.2%)
991530.6 (60%)
801280.502 (50.2%)
661020.4 (40%)
4D770.302 (30.2%)
33510.2 (20%)
1A260.102 (10.2%)
0000 (0%)

Only eleven of the 256 possible bytes appear here, one for each 10% step. Round percentages rarely land on an exact byte, so a tool that stores 50% writes 80 and reads it back as 50.2% — a harmless difference, but one that explains why an opacity can come back from a round trip looking slightly changed.

Why Some Hex Codes Are Rejected

A hex colour is valid only if, after an optional #, it has exactly 3, 4, 6 or 8 characters and every character is 0–9 or A–F. Everything else fails, and most failures trace back to a handful of habits:

  • Letters outside A–F. G, O, I and L all turn up in hand-typed codes. The letter O in place of a zero is the most common of them, and the converter above points it out when it spots one.
  • The wrong length. Five or seven digits usually means a character was dropped or doubled while copying from a PDF, and there is no safe way to guess which one went missing.
  • Spaces and extra symbols. A space inside the code, a doubled ##, or a 0x prefix copied from source code all break parsing even when every digit is correct.
  • Names instead of codes. CSS understands keywords such as teal or crimson, but they are names rather than hex, so they need a lookup instead of a conversion.

When a code is rejected, the HEX to RGB result keeps showing the last valid colour and the field explains what is wrong, so you can fix one character instead of retyping the whole value.

Why Design Tools Disagree by One

Decoding is exact, so if two applications show different numbers after a HEX to RGB conversion, the difference was introduced somewhere else. Three causes account for nearly all of it.

  • Floating-point storage.Many tools keep channels as fractions between 0 and 1 — Figma's plugin API describes colours that way. Storing 200 as 0.784 and reading it back is fine, but an edit such as a blend or a brightness change can land between two whole numbers, and each tool rounds that in its own way.
  • Colour management.An eyedropper samples what is on screen after the document has been converted to the monitor's profile, and a screenshot may carry a display profile of its own. Sample the same colour from a screenshot and from the source file and the readings can differ by a few levels.
  • Other scales. Some pickers show channels as percentages, and high-bit-depth editors such as Photoshop in 16-bit mode keep far more than 256 levels per channel. Bringing either back to 0–255 involves rounding, which is enough to move a value by one.

The practical rule is to treat the hex code as the source of truth and copy it, rather than retyping numbers read off a picker. If a value has to pass through several tools, compare the final result with the original code.

From a Web Code to a Print Reference

Knowing that #C8102E is rgb(200, 16, 46) tells you what a screen should display, not what a printer should put on paper. When a colour that started life in a stylesheet has to appear on packaging or signage, it needs a print reference, and there are two kinds to choose from.

For a spot ink, the HEX to Pantone converter ranks the closest Pantone Matching System colours and shows how each looks on coated and uncoated paper. If you already hold a PMS number, the Pantone to HEX lookup returns its screen value from our library. For four-colour process work, the HEX to CMYK converter gives a starting build and lists what to send a printer alongside it.

New to spot colour? What Pantone is and how PMS numbers work covers the system in plain terms, and our step-by-step guide to matching a hex code to Pantone walks through the judgement calls no converter can make for you.

HEX to RGB for the 16 CSS Named Colours

Every browser recognises these sixteen keywords, whose values were fixed in HTML 4 and carried unchanged into the W3C list of CSS named colours. The table decodes each one and gives its shorthand where one exists.

The 16 CSS basic colour keywords decoded from HEX to RGB
KeywordHEXShorthandRGBAs percentages
black#000000#000rgb(0, 0, 0)rgb(0%, 0%, 0%)
silver#C0C0C0nonergb(192, 192, 192)rgb(75.3%, 75.3%, 75.3%)
gray#808080nonergb(128, 128, 128)rgb(50.2%, 50.2%, 50.2%)
white#FFFFFF#FFFrgb(255, 255, 255)rgb(100%, 100%, 100%)
maroon#800000nonergb(128, 0, 0)rgb(50.2%, 0%, 0%)
red#FF0000#F00rgb(255, 0, 0)rgb(100%, 0%, 0%)
purple#800080nonergb(128, 0, 128)rgb(50.2%, 0%, 50.2%)
fuchsia#FF00FF#F0Frgb(255, 0, 255)rgb(100%, 0%, 100%)
green#008000nonergb(0, 128, 0)rgb(0%, 50.2%, 0%)
lime#00FF00#0F0rgb(0, 255, 0)rgb(0%, 100%, 0%)
olive#808000nonergb(128, 128, 0)rgb(50.2%, 50.2%, 0%)
yellow#FFFF00#FF0rgb(255, 255, 0)rgb(100%, 100%, 0%)
navy#000080nonergb(0, 0, 128)rgb(0%, 0%, 50.2%)
blue#0000FF#00Frgb(0, 0, 255)rgb(0%, 0%, 100%)
teal#008080nonergb(0, 128, 128)rgb(0%, 50.2%, 50.2%)
aqua#00FFFF#0FFrgb(0, 255, 255)rgb(0%, 100%, 100%)

The percentage column is an older CSS form that predates hex being universal: gray can be written rgb(50.2%, 50.2%, 50.2%). It is also where rounding creeps back in, because half of 255 is 127.5, and a browser has to settle on a whole channel value before anything reaches the screen.

Frequently Asked Questions

#C8102E is rgb(200, 16, 46). The code splits into the pairs C8, 10 and 2E: C8 is 12 × 16 + 8 = 200, 10 is 1 × 16 = 16, and 2E is 2 × 16 + 14 = 46. It is a deep red, and our Pantone data lists Pantone 186 C at exactly the same screen value.
Double each digit first, then convert as normal. #F0A expands to #FF00AA, so red is FF (255), green is 00 (0) and blue is AA (170), giving rgb(255, 0, 170). Never pad with zeros instead: #F0A is not #F000A0. Each shorthand digit is worth 17 times its value, so F becomes 255 and 8 becomes 136.
Decode the first six digits as red, green and blue, then divide the final pair by 255 to get the opacity. #C8102E80 gives rgb(200, 16, 46) with an alpha byte of 80, which is 128, and 128 ÷ 255 is about 0.502 — so the CSS value is rgba(200, 16, 46, 0.502). A four-digit code works the same way once its digits are doubled.
A valid code has 3, 4, 6 or 8 characters, all from 0–9 and A–F, with at most one # in front. The usual culprits are the letter O typed instead of a zero, a character lost while copying, a space inside the code, or a 0x prefix copied from source code. This converter names the exact problem under the field.
In CSS, yes: a stylesheet needs #C8102E, and C8102E on its own is not a colour. Outside CSS it is optional — design tools, spreadsheets and brand guidelines often leave it out — so this converter accepts codes either way. Put the # back whenever you paste the value into HTML, CSS or an SVG file.
No. #c8102e, #C8102E and #c8102E describe exactly the same colour, because the hexadecimal digits A to F carry the same values in either case. Uppercase is common in brand guidelines because it is easier to read aloud and harder to misread, while lowercase is common in minified CSS. Pick one convention per project so codes stay easy to search.
Decoding a hex code is exact, so a difference of one or two levels comes from somewhere else: a tool storing channels as fractions and rounding after an edit, an eyedropper reading the colour-managed screen instead of the file, or a picker working in percentages or 16-bit. Copy the hex code between tools rather than retyping numbers from a picker.
Only as a closest match. Pantone colours are physical inks and a hex code describes light from a screen, so no formula turns one into the other exactly. The panel on this page shows the three nearest coated PMS inks with their uncoated versions, and the HEX to Pantone converter ranks more. Confirm the final choice against a printed swatch book.