RGB to HEX Converter

Convert RGB numbers into a hex color code, with the actual division algorithm shown and the closest named color identified.

Going From Three Numbers to One String

RGB values are how most graphics tools and code hand you color in the first place — three separate numbers from 0 to 255, one per channel, straight from a canvas pixel read, an image editor's color panel, or an API response. Hex packs that same information into a single compact string, which is what most CSS, design tools, and style guides actually expect.

Going from RGB to hex means running each of those three decimal numbers through a base conversion — turning a familiar base-10 number into base 16. It's the reverse of the more commonly discussed hex-to-RGB direction, and it comes up constantly whenever raw pixel or channel data needs to become a clean, shareable color code.

At a glance:
• Each RGB channel (0–255) converts independently into a 2-digit hex pair
• The three pairs are concatenated in order — red, then green, then blue
• Values outside 0–255 get clamped before conversion, since hex can't represent them
• Every valid RGB triple has exactly one correct hex equivalent — never more than one

RGB to HEX Converter

#2D8CFF
Closest named color: —

Division Ladder: Converting the Red Channel

The Successive-Division Algorithm

Core method:

Divide by 16 repeatedly, record each remainder, read them bottom to top

Worked Example

Given: Red channel value 45

Step 1: 45 ÷ 16 = 2, remainder 13 (13 in hex is "D")
Step 2: 2 ÷ 16 = 0, remainder 2 (2 in hex is "2")
Step 3: The quotient hit 0, so stop — reading the remainders from last to first gives "2D"

This is the mirror image of converting hex back to decimal, where you multiply each digit by its place value and add. Here, you're peeling off one hex digit at a time by dividing, working from the smallest place value outward until nothing is left.

Landmark Decimal-to-Hex Values Worth Recognizing

A handful of round decimal values come up constantly in color work — recognizing their hex equivalents on sight saves a lookup.

Reference Table

Decimal Hex Why It's Common
0 00 Channel fully off
128 80 Roughly half intensity
192 C0 Common light gray value
255 FF Channel fully on — the maximum

Where This Direction of Conversion Comes Up

Reading Pixel Data From a Canvas: JavaScript's getImageData returns raw RGB(A) values for every pixel — turning any of those values into a hex string for display or storage requires exactly this conversion.

Color Extraction From Photos: Tools that pull a dominant or average color out of an uploaded image typically compute it as an RGB average first, then convert that result to hex for use in a swatch or CSS variable.

API Responses Returning RGB: Some design and image-processing APIs return color data as separate R, G, B fields rather than a hex string, leaving the conversion to whatever consumes that response.

Print-to-Web Color Workflows: Print software and older design tools sometimes report color as RGB triples, which then need converting to hex before they can be dropped into a website's CSS.

Programmatic Color Generation: Code that generates colors algorithmically (random accent colors, data-driven chart colors, procedurally generated art) usually works in RGB internally and converts to hex only at the point of output.

Hardware & Sensor Color Readings: Physical color sensors typically report raw RGB channel intensities, which need this same conversion before the reading can be used or displayed as a standard web color.

Getting Clean Conversions Every Time

✓ Clamp values before converting: RGB values technically shouldn't exceed 255 or drop below 0, but if a calculation produces an out-of-range number, clamp it to the nearest valid boundary rather than letting it produce an invalid hex code.

✓ Round decimals first: If a value arrives as a decimal (from an average, a percentage calculation, or a gradient interpolation), round it to the nearest whole number before converting — hex has no fractional digit representation.

✓ Don't forget the leading "#": The hex digits themselves are the color value, but virtually every context that consumes hex color (CSS, design tools, image formats) expects the leading hash symbol as well.

✓ Percentages need converting to 0–255 first: If a color tool gives channel values as percentages (0–100%) instead of 0–255, multiply by 2.55 and round before running the hex conversion.

✓ Four-channel RGBA needs an extra step: Converting an RGBA value to 8-digit hex requires converting the alpha channel too — but alpha is usually expressed as a 0–1 decimal, which needs scaling to 0–255 first, unlike the color channels.

✓ Named colors are a convenience, not a requirement: A hex code always works even when a matching named color exists — named colors are just shorthand for a small, fixed set of hex values.

Where CSS's Named Colors Actually Came From

Named Colors Predate the Web: The list of color names browsers recognize today — "tomato," "steelblue," "rebeccapurple," and dozens more — traces back to the X11 Window System's color name list, developed for Unix graphical displays in the 1980s, long before HTML or CSS existed.

CSS Inherited the List Almost Wholesale: When CSS color specifications were formalized in the 1990s and expanded in later revisions, they adopted a large portion of the existing X11 naming convention rather than inventing an entirely new vocabulary, giving web developers a familiar, if occasionally inconsistent, set of names to work with.

Every Named Color Is Just a Hex Shortcut: Underneath the friendly name, each one resolves to a fixed, specific hex value — "tomato" is nothing more than a memorized alias for #FF6347, offering no functionality a raw hex code doesn't already provide.

RGB Numbers Came From Hardware, Not Design: Long before any of this naming convention existed, representing color as three separate red, green, and blue intensity values was already the natural language of display hardware itself, since that's literally how a screen's phosphors or subpixels physically produce color.

Frequently Asked Questions

Q: What happens if I enter an RGB value above 255?

It gets clamped down to 255, the maximum a single channel can represent — hex notation has no way to express a value beyond that ceiling.

Q: Can RGB values have decimals?

In practice, standard 8-bit color channels are always whole numbers from 0 to 255. If a calculation produces a decimal, it should be rounded to the nearest whole number before converting to hex.

Q: Does every RGB combination have a matching hex code?

Yes — every valid RGB triple (each channel between 0 and 255) converts to exactly one 6-digit hex code, with no exceptions and no ambiguity.

Q: Why does my converted color not exactly match a named color?

Named colors only cover a small, fixed list of specific hex values out of the 16.7 million possible colors — most RGB combinations simply don't have an exact named match, so the closest one shown is an approximation, not an exact hit.

Q: Is there a faster mental shortcut for common RGB-to-hex conversions?

Memorizing landmark values like 0=00, 128=80, 192=C0, and 255=FF covers a surprising number of everyday cases, since many design systems favor round or near-round channel values.

Q: How is this different from just using getComputedStyle or a browser color picker?

Browser tools return a result without showing the underlying math — this conversion is identical, just with the actual base-16 division process made visible for anyone who wants to understand or verify it manually.