HEX to RGB Converter
Paste a hex code and get its red, green and blue channels - the values you need for rgba(), canvas work and any tool that will not take hex.
Example conversion
#dc143c
converts to
rgb(220, 20, 60)
About HEX to RGB conversion
A hex color code is red, green and blue written in base 16. Splitting
#0d6efd into 0d, 6e and
fd and reading each pair as a decimal number gives you
rgb(13, 110, 253) - the same color, in the notation that code
and image tools prefer. The conversion is exact in both directions, because
hex and RGB are two ways of writing one model rather than two different
color spaces.
Most of the time you convert this way because something needs the
channels as separate numbers. CSS transparency is the classic case:
rgba() takes an alpha value that plain hex historically could
not express. Canvas drawing, image processing, shader code, spreadsheet
conditional formatting and countless APIs all want three integers rather
than a string of hex digits.
When should you use HEX to RGB?
- Adding transparency in CSS - turning
#0d6efdintorgba(13, 110, 253, 0.5)for overlays, shadows and tints. - Working with canvas or SVG in JavaScript - most drawing and pixel-manipulation APIs think in channels.
- Feeding a design tool or app that wants sliders - plenty of software still asks for R, G and B fields.
- Doing math on a color - blending, dimming or calculating contrast all need numeric channels.
- Reading a brand hex code into a non-web context - a presentation template, a game engine or an embedded display.
How the conversion works
Strip the leading hash, then split the remaining six characters into
three pairs and read each as a base-16 number. For #0d6efd:
0d= (0 x 16) + 13 = 13 red6e= (6 x 16) + 14 = 110 greenfd= (15 x 16) + 13 = 253 blue
Three-digit shorthand codes expand first by doubling every digit, so
#abc becomes #aabbcc before the pairs are read.
This converter accepts codes with or without the hash and in either case,
so pasting #0D6EFD, 0d6efd or #abc
all work.
HEX vs RGB
- Notation, not model - both describe the same three channels; hex uses base 16, RGB uses base 10.
- Where you meet them - hex dominates CSS, HTML and brand guides; RGB dominates image editors, canvas APIs and anything doing arithmetic on colors.
- Alpha -
rgba()has expressed opacity for decades; the eight-digit hex form is newer and less common in older codebases. - Length -
#0d6efdis far shorter thanrgb(13, 110, 253), which is why stylesheets favour it. - Error-proneness - a mistyped hex digit silently produces a different color; an out-of-range RGB number is usually caught.
Named CSS colors in HEX and RGB
The sixteen basic CSS color keywords plus eight more that come up constantly, each shown in both models side by side. Pick any row to drop that color into the converter and read it in the other eight models too.
Frequently asked questions
Does this converter support shorthand hex like #abc?
Yes. Three-digit codes are expanded by doubling each digit, so
#abc is read as #aabbcc and converts to
rgb(170, 187, 204). You can also leave out the hash entirely.
How do I turn a hex color into rgba() with opacity?
Convert the hex code here to get the three channels, then add your
alpha as a fourth value between 0 and 1. For example
#0d6efd becomes rgba(13, 110, 253, 0.5) at
half opacity.
What does an eight-digit hex code mean?
The last two digits are alpha - opacity - in the same 00 to ff range.
#0d6efdff is fully opaque and #0d6efd00 is
fully transparent. This converter reads the six-digit color portion; the
alpha pair is separate from the color itself.
Why does my hex code not convert?
A valid code has exactly three or six hexadecimal characters (0-9 and a-f) after an optional hash. Codes containing other letters, the wrong number of digits, or a trailing name copied along with them will be rejected - check for stray spaces or characters.
Is the conversion reversible?
Yes, exactly. Run the result through the RGB to HEX converter and you get your original code back, since both notations describe the identical 24-bit color.