🎨

RGB to HEX

✓ Free & no signup 🔒 Runs 100% in your browser Updated 2026-11-25 Other Tools
—
HEX

When you sample a color with an eyedropper, read values from a camera histogram, or compute channels in code, you end up with three decimal numbers — and the moment those numbers need to travel into CSS, a design file, or a message to a teammate, they need to become a hex code. This tool converts RGB channel values to hex instantly: enter red, green, and blue from 0 to 255, and the hex code appears live, uppercase and hash-prefixed, next to a swatch of the exact color. The conversion is pure math performed in your browser; nothing is transmitted or stored.

The direction matters more than people expect. RGB is how machines and math see color — three independent byte values you can blend, compare, and threshold. Hex is how humans pass color around — six characters, one token, no punctuation to misplace. Converting in this direction is the routine final step of color work done in code, and this page both performs it and shows the underlying arithmetic, so the mapping never feels like magic.

What RGB Values Represent

An RGB color is three channels, each a byte with 256 possible values. Red at full blast with the others off — 255, 0, 0 — is the purest red a screen can show; all three at 255 is white; all three at 0 is black. With 256 values per channel, the system expresses 256 cubed colors: 16,777,216 combinations, the figure behind the marketing phrase 16.7 million colors. Each channel scales linearly: 128 is roughly half brightness, 64 roughly a quarter, 192 roughly three-quarters, with the small remainder explained below.

The byte structure is not an implementation detail — it is the reason hex works so cleanly. Two hex digits describe exactly one byte, 00 through FF, so a color is always exactly six hex digits and never a different length. Channel boundaries are unambiguous in a way that decimal channels are not: rgb(1, 20, 3) is painfully easy to misread, but its hex form 011403 keeps each channel in its own two-character slot.

The Bit Math: How 255 Becomes FF

Hexadecimal is base 16, using digits 0-9 then A through F for the values 10 through 15. One byte holds 0 to 255, and one hex digit holds 0 to 15, so every byte is exactly two hex digits: the first digit counts sixteens, the second counts ones. Converting 255: divide by 16 to get 15 remainder 15; 15 is F in hex, so both digits are F and 255 becomes FF. Converting 87: 87 divided by 16 is 5 remainder 7, giving the digits 5 and 7 — 57. Converting 51: 51 divided by 16 is 3 remainder 3, giving 33.

The opposite direction is even faster once you see the pattern: FF times nothing — F is 15, so 15 times 16 plus 15 equals 255. This is the exact arithmetic a programmer shortcuts with bit shifts: the expression (255 shifted left 16) OR (87 shifted left 8) OR 51 packs the three channels into the single number 16734067, which prints in hex as FF5733. Same bytes, different base.

How to Use This Tool (Step by Step)

  1. Enter the red value from 0 to 255. Fields update live — there is no convert button.
  2. Enter green, then blue. Values outside 0-255 are flagged rather than silently wrapped, which prevents the classic 300-red bug.
  3. Read the hex code from the result, formatted uppercase with a leading hash, ready to paste into CSS or a design tool.
  4. Confirm the swatch matches the color you sampled — the visual check catches swapped channels instantly.
  5. Need lowercase hex without a hash for a specific codebase? Both conventions appear alongside the primary output.

A Worked Example: Sampled Orange to Hex

Suppose an eyedropper reports rgb(255, 87, 51) from a design mockup. Red: 255 divides by 16 into 15 remainder 15, so FF. Green: 87 divides into 5 remainder 7, so 57. Blue: 51 divides into 3 remainder 3, so 33. Concatenate in red-green-blue order and append the hash: #FF5733, a saturated coral orange. Paste it into any stylesheet and the sampled color reappears exactly, because the conversion lost nothing — every byte value has one exact hex spelling.

One more example with awkward numbers, because real samples are rarely round. rgb(131, 58, 180): 131 divided by 16 is 8 remainder 3, giving 83. The 58 gives 3 remainder 10, and 10 is A, giving 3A. The 180 gives 11 remainder 4, and 11 is B, giving B4. The result is #833AB4, a strong violet. Neither conversion involved a calculator — just division by 16 and knowing the digit letters.

Conversion Examples With Recognizable Colors

RGB inputHex outputWhat it looks like
255, 255, 255#FFFFFFwhite
0, 0, 0#000000black
255, 87, 51#FF5733coral orange
131, 58, 180#833AB4violet
46, 139, 87#2E8B57sea green
128, 128, 128#808080standard gray

The gray row settles a common argument: exact mid-gray is 128, hex 80, not 127 — because 255 does not divide evenly in half, 127.5 rounds to 128 by convention. The same rule applies to every 50 percent channel value, which is why gradients computed by naive averaging can be off by one from their design-file targets.

Common Mistakes This Tool Prevents

  • Out-of-range channels: 300 in the red field is invalid, not clamped. Some libraries silently wrap values modulo 256, turning a typo into a completely different hue.
  • Swapped channel order: entering blue into the green field produces a plausible-looking but wrong color. The swatch makes the swap obvious in one glance.
  • Lowercase confusion: hex digits are case-insensitive, but some tooling compares strings case-sensitively; the tool shows both forms so you can match your destination's convention.
  • Fractional inputs: channels are integers by definition; if a computation produced 152.5, round it first — and remember the off-by-one midpoint rule above.
  • Percentage mixing: rgb(80%, 20%, 60%) is a different notation; converting percentages requires multiplying by 2.55 first, which is a different operation than pasting raw bytes.

Practical Uses in Daily Work

  • Code to CSS: a script computed a blend like half of 52, 152, 219 and produced channels 26, 76, 110 — this page turns that into #264E6E for the stylesheet in one glance.
  • Data visualization: generating colors programmatically by stepping channels, then emitting hex tokens for chart configuration.
  • Design handoff: sampling a photo in an image editor that reports decimal values, then passing a single hex code to the design team.
  • Accessibility checks: contrast formulas consume channel values, but reports and ticket discussions quote hex, so the final step is always this conversion.
  • Theme generation: deriving hover states by subtracting a fixed amount from each channel, then converting each result to hex for the palette file.

Tips and Best Practices

  • Anchor the landmarks: 0 is 00, 128 is 80, 255 is FF — knowing those three lets you sanity-check any conversion mentally.
  • Always do the swatch check before shipping; channel swaps outnumber real bugs in most color-related fix lists.
  • Keep theme colors in hex and do arithmetic in RGB — convert at the boundaries, compute in the middle.
  • When documenting colors for teammates, give hex plus the rgb() form; the pair prevents transcription errors in both directions.
  • This conversion is exact and local — unreleased brand colors can be processed here without any network call.

Frequently Asked Questions

How do I convert RGB values to a hex code?
Convert each channel from decimal to two hex digits, then concatenate in red-green-blue order behind a hash. For rgb(255, 87, 51): 255 is FF, 87 is 57, and 51 is 33, producing #FF5733. The per-channel math is division by 16 — 87 divided by 16 gives 5 remainder 7, hence 57. This tool automates it: enter the three values from 0 to 255 and the uppercase hex code appears live, alongside a swatch that confirms you entered the channels in the right order.
Why is 255 written as FF in hex colors?
Because hexadecimal is base 16: one hex digit represents 0 through 15, with letters A through F standing for 10 through 15, and one byte holds 0 through 255. Since 255 is 15 sixteens plus 15 ones — the maximum a byte can hold — it is written with the maximum digit twice: FF. The same logic makes 128 into 80 and 0 into 00. Hex pairs fit bytes exactly, which is why every RGB color is precisely six hex digits and why FF consistently means full channel strength in CSS and design tools.
What is the hex code for 50 percent gray in RGB?
The convention is rgb(128, 128, 128), hex #808080. Half of 255 is 127.5, and since channels must be whole bytes, the standard rounds up to 128 — written 80 in hex. The nearby 127, hex 7F, is also seen in code that truncates instead of rounding, and the one-step difference is imperceptible but real. CSS actually defines two named grays in this zone: gray is #808080 at exactly this value, while dimgray and lightgray sit on either side of it.
Do hex color codes need to be uppercase?
No — hex digits are case-insensitive, so #ff5733, #FF5733, and #Ff5733 are the same color and every browser parses them identically. Case only matters for consistency and tooling: some codebases enforce lowercase through style linters, and a few string-comparison routines in scripts are case-sensitive and would treat ff5733 and FF5733 as different tokens. This tool outputs uppercase with a leading hash by default and shows the lowercase form alongside, so you can copy whichever matches your project's convention without manual retyping.
Can RGB values be greater than 255?
Not in standard 8-bit RGB — each channel is one byte with a range of exactly 0 to 255. Values above that are either errors or a different color model: high-bit-depth imaging uses 10 or 16 bits per channel with larger maximums, and HDR video extends brightness beyond standard range, but neither is what CSS or design tools mean by RGB. This tool rejects out-of-range input rather than clamping or wrapping it, because some libraries silently apply modulo 256 — turning a typo like 300 into a completely different, plausible-looking color.
How do I convert RGBA with transparency to hex?
Write the alpha as a fourth byte pair in the eight-digit hex form: rgb(255, 87, 51) at half opacity becomes #FF573380, since half of 255 rounds to 128 and 128 in hex is 80. The standard checkpoints make mental conversion easy — FF is fully opaque, 80 is half, 40 is a quarter. Browser support for 8-digit hex is universal in current versions, but older tools and some design applications only accept six digits, in which case express transparency separately using rgba() notation instead of forcing it into the hex code.

Related Tools