RGB to HEX Converter

Convert between RGB (0-255 per channel) and HEX (#RRGGBB) color notation.

Convert Live swatch Bidirectional
Rate this calculator · 5.0 (1)

RGB ↔ HEX

Live swatch · HSL + CMYK · CSS snippets

Instructions — RGB to HEX Converter

1

Pick a direction

Toggle between RGB → HEX and HEX → RGB at the top. Default direction is RGB → HEX. The color swatch updates live as you type.

2

Enter RGB or HEX

For RGB: type each channel (0-255) or drag the sliders. For HEX: paste a 6-digit code, with or without the # prefix. Lowercase and uppercase both work.

3

Copy the output

The HEX, RGB, HSL, and CMYK values appear in the stats panel. The CSS snippet block at the bottom gives a ready-to-paste color declaration in three notations.

Quick rule: divide each RGB channel by 16, take quotient and remainder, map 10-15 to A-F. 255 = 15×16+15 = FF.
Shorthand: if both digits in each pair match, you can write #F33 instead of #FF3333. The calculator shows the short form when available.

Formulas

Each RGB channel is a decimal integer from 0 to 255. Each pair of HEX digits is a base-16 representation of the same range. The conversion is a straightforward radix change, with no rounding or loss.

RGB to HEX
$$ \text{HEX} = \#\,\text{hex}(R)\,\text{hex}(G)\,\text{hex}(B) $$
Convert each channel to two hex digits and concatenate with a # prefix. 64 = 40, 128 = 80, 200 = C8 → #4080C8.
HEX to RGB
$$ R = 16 \cdot d_1 + d_2 $$
Split each pair, multiply the first digit by 16, add the second. C8 = 12×16 + 8 = 200.
Channel range
$$ 0 \le R, G, B \le 255 = \text{FF}_{16} $$
8 bits per channel = 256 values. RGB has 256³ = 16,777,216 possible colors.
RGB to decimal
$$ D = R \cdot 65536 + G \cdot 256 + B $$
A 24-bit integer representation. #FF0000 = 16,711,680 decimal. Useful for older APIs and bitmap formats.
HEX shorthand
$$ \#XYZ = \#XXYYZZ $$
If both digits in every pair match, CSS lets you write three digits instead of six. #F0A is shorthand for #FF00AA.
Worked example
$$ \text{rgb}(255, 165, 0) = \#FFA500 $$
255 → FF, 165 → 10×16+5 = A5, 0 → 00. Result: orange.

Reference

Quick reference — common web colors
NameRGBHEXHSL
Red255, 0, 0#FF0000hsl(0, 100%, 50%)
Green0, 128, 0#008000hsl(120, 100%, 25%)
Blue0, 0, 255#0000FFhsl(240, 100%, 50%)
Yellow255, 255, 0#FFFF00hsl(60, 100%, 50%)
Cyan0, 255, 255#00FFFFhsl(180, 100%, 50%)
Magenta255, 0, 255#FF00FFhsl(300, 100%, 50%)
Orange255, 165, 0#FFA500hsl(39, 100%, 50%)
Purple128, 0, 128#800080hsl(300, 100%, 25%)
Gray128, 128, 128#808080hsl(0, 0%, 50%)
Silver192, 192, 192#C0C0C0hsl(0, 0%, 75%)
White255, 255, 255#FFFFFFhsl(0, 0%, 100%)
Black0, 0, 0#000000hsl(0, 0%, 0%)

HEX digit lookup

Manual conversion uses these single-digit values.

Decimal ↔ HEX digit
DecimalHEX
0-90-9
10A
11B
12C
13D
14E
15F
Channel power-of-2
HEXDecimal
000 (off)
4064 (25%)
80128 (50%)
BF191 (75%)
C0192
FF255 (full)

Modern CSS supports HEX, RGB, HSL, RGBA (with alpha), HSLA, and now LAB and OKLCH. HEX is still the most common in production stylesheets because of its compactness and universal support.

Article — RGB to HEX Converter

RGB to HEX Converter: Web Color Codes Explained

RGB and HEX are two notations for the same color information. RGB uses three decimal channels from 0 to 255 (red, green, blue); HEX packs those three values into six hexadecimal digits with a leading hash, such as #FFA500 for orange. The conversion is a radix change with no rounding: every RGB value has exactly one HEX equivalent and vice versa.

To convert RGB to HEX, take each channel, divide by 16 for the first digit, use the remainder for the second, and map 10-15 to letters A-F. To convert HEX back, split into pairs, multiply the first digit by 16, and add the second. The math takes 30 seconds by hand and zero seconds with the calculator above.

What does RGB to HEX mean

A digital color on a screen is three lights mixed together: red, green, and blue, each at some intensity between zero and full brightness. RGB notation writes those three intensities as integers from 0 to 255. rgb(255, 0, 0) is pure red at full intensity. rgb(255, 255, 255) is all three at full, which the eye reads as white.

HEX notation encodes the same three numbers as base-16 digits, packed into a string. The advantage is compactness: #FF0000 takes seven characters; rgb(255, 0, 0) takes thirteen. In a CSS file with hundreds of color declarations, that difference adds up. HEX is the dominant format in stylesheets, design files, and brand guidelines.

Did you know

HEX color notation entered the web in 1996 with CSS 1.0, but the underlying RGB color model is older. It was formalized in the 1853 work of James Clerk Maxwell, who demonstrated that any visible color could be reproduced by mixing red, green, and blue light in varying intensities.

The RGB to HEX formula

The conversion is a base change, not a calculation in the usual sense:

RGB to HEX conversion
HEX_pair = (channel ÷ 16) × 16 + (channel mod 16)
Decimal 10 11 12 13 14 15 HEX A B C D E F

Worked example for orange, rgb(255, 165, 0):

Red: 255 ÷ 16 = 15 remainder 15 → F and F → FF. Green: 165 ÷ 16 = 10 remainder 5 → A and 5 → A5. Blue: 0 → 00. Concatenate with a hash: #FFA500. The same color, written two ways.

The reverse is just as direct. Given #4080C8: split into 40, 80, C8. 40 = 4×16 + 0 = 64. 80 = 8×16 + 0 = 128. C8 = 12×16 + 8 = 200. Result: rgb(64, 128, 200), a medium sky blue.

RGB, HEX, and HSL compared

Three notations for the same color space, each with different strengths:

  • RGB: rgb(255, 0, 0). Verbose but human-readable. Best for JavaScript animations and programmatic color manipulation.
  • HEX: #FF0000. Compact and universal. Standard in CSS files, design tool exports, and brand documents.
  • HSL: hsl(0, 100%, 50%). Hue, saturation, lightness — matches how designers think. Best for generating tints and shades.
  • RGBA: rgba(255, 0, 0, 0.5). RGB plus an alpha channel from 0 to 1 for transparency.
  • HSLA: hsla(0, 100%, 50%, 0.5). HSL plus alpha. Increasingly common in modern stylesheets.
  • OKLCH: oklch(0.628 0.258 29). New in 2023, designed for perceptual uniformity. Adopted in CSS Color Level 4.

The first three (RGB, HEX, HSL) describe the same sRGB color space, so any color one can express, the others can too. They differ only in human ergonomics, not in the colors they can produce.

How many RGB and HEX colors exist

With 8 bits per channel and three channels, RGB has 256³ = 16,777,216 distinct colors. Every one of them has a unique HEX equivalent. That is enough range that the eye cannot distinguish adjacent codes: the gap between #FF0000 and #FF0001 is invisible on a normal monitor.

Tip

Older 16-bit displays could only show 65,536 colors. Mid-1990s web designers used a 216-color "web safe" palette to avoid dithering on those screens. Today every browser and display supports the full 16.7M range; web-safe palettes are a historical curiosity.

Recent displays (HDR, P3 wide-gamut) can render colors beyond standard sRGB. CSS Color Level 4 added new notation for those, including color(display-p3 r g b) and oklch(). RGB and HEX are still standard for ordinary sRGB content, which is over 95% of web traffic.

RGB to HEX in CSS and design tools

CSS accepts color in any of these notations interchangeably:

color: #FFA500;
color: rgb(255, 165, 0);
color: hsl(39, 100%, 50%);

All three produce the same orange. In practice, designers paste HEX out of Figma, Sketch, or Photoshop. Developers occasionally switch to rgb() or rgba() when they need to compute a color in JavaScript — channel arithmetic is easier on decimal numbers than on hex strings.

CSS file
#FFA500
7 chars, designer-friendly
JavaScript
rgb(255, 165, 0)
15 chars, easy to manipulate

HEX shorthand and alpha transparency

When both digits in every pair of a HEX code match, CSS allows a 3-digit shorthand: #FF3366 can be written #F36. Each shorthand digit expands to itself doubled: F → FF, 3 → 33, 6 → 66. The colors are exactly the same; only the typing is shorter.

Shorthand only works for 8/16-divisible colors. #FFA500 cannot be shortened because A and 5 differ between the two digits of their pairs. The calculator above flags whether shorthand is possible for any given color.

For transparency, modern CSS supports 8-digit HEX (#RRGGBBAA), where the last pair is the alpha channel. #FF0000FF is opaque red; #FF000080 is red at 50% opacity. Browser support is universal in 2025, but for maximum compatibility many teams still use rgba() instead.

Don't confuse HEX with named colors

"red" in CSS equals #FF0000 — but "darkred" equals #8B0000, not #800000. CSS named colors are a fixed list of 147 specific values, not a calculation. When in doubt, use HEX or RGB to make the exact color explicit.

Common RGB to HEX mistakes

The errors that come up most often:

  • Forgetting the hash — CSS color: FF0000 is invalid; it must be #FF0000.
  • Wrong digit count — HEX must be 3, 4, 6, or 8 digits. #FFA50 (five digits) is invalid.
  • Non-hex characters — only 0-9 and A-F are allowed. #GG0000 is meaningless.
  • Mixing RGB scales — channels are 0-255, not 0-100 or 0-1. rgb(0.5, 0.5, 0.5) is wrong.
  • Assuming HEX is case-sensitive — it is not. #ff0000 = #FF0000.
  • Treating HEX like a magnitude — #FFFFFF is white because all channels are full, not because the number is "biggest."

RGB to HEX quick reference

The colors most often referenced in design briefs and stylesheets:

  • Pure red: rgb(255, 0, 0) = #FF0000
  • Pure green: rgb(0, 128, 0) = #008000 (CSS named "green")
  • Pure blue: rgb(0, 0, 255) = #0000FF
  • Black: rgb(0, 0, 0) = #000000
  • White: rgb(255, 255, 255) = #FFFFFF
  • Mid gray: rgb(128, 128, 128) = #808080
  • Orange: rgb(255, 165, 0) = #FFA500
  • Hot pink: rgb(255, 105, 180) = #FF69B4

The full conversion is in the calculator at the top of the page. Type any RGB value or paste any HEX code; the swatch and stats update live. Copy the CSS snippet at the bottom and paste directly into your stylesheet.

FAQ

For each channel: divide by 16 to get the first hex digit, take the remainder for the second. Map 10-15 to A-F. Example: 200 ÷ 16 = 12 remainder 8 → C8. The full color rgb(64, 128, 200) becomes #4080C8.
Split into three pairs (RR, GG, BB). For each pair: first digit × 16 + second digit. Example: C8 = 12 × 16 + 8 = 200. So #4080C8 becomes rgb(64, 128, 200).
3-digit HEX expands each digit to two identical digits: #F0A = #FF00AA, #ABC = #AABBCC. Shorthand only works when both digits in each pair are the same. CSS supports it natively.
Standard 6-digit HEX does not. 8-digit HEX (HEXA) does: #RRGGBBAA where AA is the alpha channel (00 = transparent, FF = opaque). Modern browsers support 8-digit HEX; for broad compatibility use rgba() instead.
Yes — HEX is case-insensitive. Uppercase is the more common convention in design tools and CSS files, but lowercase is also valid. Most editors and linters will normalize one way or the other.
16,777,216 colors (256³). Each channel has 256 values, giving 256 × 256 × 256 unique combinations. This is called 24-bit color and matches the capability of every modern display.
RGB describes a color by light channels; HSL describes it by hue, saturation, and lightness. RGB matches how screens emit light; HSL matches how humans think about color (this red, but lighter). Both notations describe the same color space.
HEX is more compact: #FF0000 versus rgb(255, 0, 0). It also pastes easily from design tools like Figma and Photoshop, which export HEX by default. RGB is preferred when you need to compute or animate channel values in JavaScript.
One of 216 colors defined for 256-color displays in the 1990s. Each channel uses one of six values: 0, 51, 102, 153, 204, 255 (00, 33, 66, 99, CC, FF in HEX). Web-safe palettes are obsolete on modern hardware but still appear in retro designs.