Skip to content
Hex Calculator

RGB to Hex Converter

Convert RGB values like rgb(37, 99, 235) into a 6-digit hex color code — the compact format CSS and design tools expect.

Hex result
#2563EB

How RGB to Hex Conversion Works

Each RGB channel (0-255) converts independently to a 2-digit hex number, zero-padded if needed. Concatenate the three pairs in red-green-blue order and prefix with # to get the standard 6-digit hex color code.

RGB to Hex Example, Step by Step

rgb(37, 99, 235) = #2563EB

rgb(37, 99, 235) = #2563EB

37 (decimal) = 25 (hex) -> Red
99 (decimal) = 63 (hex) -> Green
235 (decimal) = EB (hex) -> Blue

Concatenate: 25 + 63 + EB = 2563EB
StepDescriptionResult
Convert red37 (decimal) = 25 (hex)25
Convert green99 (decimal) = 63 (hex)63
Convert blue235 (decimal) = EB (hex)EB
Combine with # prefixjoin all three pairs#2563EB

A channel under 16 still gets 2 hex digits — 5 (decimal) becomes 05 (hex), not just 5, since hex colors are always exactly 6 digits.

Where RGB to Hex Actually Comes Up

Converting a Design Tool's Color Picker Value

Some tools and file formats surface a color as RGB channels rather than hex — converting gives you the compact code to paste straight into CSS.

rgb(37, 99, 235) -> #2563EB

Turning Canvas Pixel Data Into a CSS Color

Reading a pixel from an HTML canvas with getImageData() returns raw RGBA byte values — converting the RGB portion to hex gives you a color you can apply directly in CSS or store in a design token.

pixel RGB -> CSS hex value

Matching a Print or Photography Color Value

Photo editing and print workflows often report color as RGB — converting to hex bridges that into web and app development where hex is the standard format.

photo tool RGB -> web hex code

Common Mistakes With RGB to Hex

  • Forgetting to zero-pad single-digit hex values (5 must become 05, not 5).
  • Entering a channel value above 255, which has no valid hex representation.
  • Mixing up the channel order when typing values manually.

Why Use This Calculator Instead of Doing It by Hand

  • Accepts both rgb() function syntax and plain comma-separated numbers
  • Runs entirely in your browser — nothing you type gets sent anywhere
  • Zero-pads single-digit channels automatically, so the output is always valid 6-digit hex
  • Flags out-of-range channel values instead of producing an invalid color

Frequently Asked Questions

How do you convert RGB to hex?

Convert each 0-255 channel value to a 2-digit hex number and concatenate them in red-green-blue order. rgb(37, 99, 235) becomes 25, 63, EB — #2563EB.

What format does this tool accept for RGB input?

Either plain comma-separated numbers (37, 99, 235) or a full rgb() function string (rgb(37, 99, 235)) — both work the same.

What if a channel value is over 255?

The tool flags it as an error — RGB channels are limited to 0-255 because that's the full range a single byte can hold.

Do I need to round decimal RGB values first?

Yes, RGB channels are whole numbers 0-255. If a tool gives you a decimal channel value, round it before converting.

Why does the hex output always have 6 digits?

Each channel converts to exactly 2 hex digits (00-FF), and there are 3 channels, so the full form is always 6 digits — single digits get zero-padded (5 becomes 05).

I picked a color in Photoshop or Figma and it shows RGB — how do I get the hex code?

Enter the three channel values shown in the color picker here — most design tools display RGB alongside hex already, but this is handy when a tool only shows one or the other, or when you're working from raw pixel data.

Why does JavaScript's getImageData() give me RGB instead of hex?

Canvas pixel data is stored as raw RGBA byte values internally, not as hex strings — converting to hex here is a quick way to get a usable CSS color from pixel data you read out of an image.