Shard Tools

RGB to Hex

Convert an RGB colour to a hex code in your browser, from any common RGB format.

Maintained by Roshan.

Use RGB to Hex

Converts rgb colour to hex in this tab, with nothing sent anywhere.

Runs entirely on your deviceThe conversion happens in this browser tab. Nothing you type is uploaded, logged or stored, which is worth knowing for anything you would not paste into a search box.

Explore general converters

Find related browser-local tools for nearby tasks without starting another search.

Browse all general converters

About RGB to Hex

Converting RGB to hex is the return trip, and it is the one you make when a colour has come out of code or a calculation and now needs to go into CSS, a design file, or anywhere that expects the compact six-digit form. RGB expresses a colour as three numbers from 0 to 255; hex packs those same three numbers into two digits each. The small friction is that RGB arrives written in many ways - the full rgb(59, 130, 246), or just three numbers, or space-separated, or with stray punctuation - and a rigid parser rejects all but its preferred shape. This tool pulls the three channel values out of whatever form they are in, checks each is within range, and assembles the hex code, so a value from any source converts without being reformatted first.

Using RGB to Hex

  1. The three channel numbers are extracted from the input regardless of the surrounding format - parentheses, commas, or plain spacing all work.
  2. Each value is checked to be within the 0 to 255 range, and a value above that is refused as an error rather than silently clamped.
  3. Each channel is converted to two hex digits, padded so a small value still produces two characters.
  4. The three pairs are joined and prefixed with a hash to form a standard six-digit hex code.
  5. The result is the compact form used by CSS and design tools.

Where rgb to hex helps

Taking a computed colour into CSS

A colour produced in code as RGB converts to the hex a stylesheet or design tool expects.

Normalising colours from mixed sources

Values written in different RGB styles all convert to the same tidy hex form.

Before you use the result

Questions about RGB to Hex

What RGB formats are accepted?

Full rgb() notation, bare comma-separated numbers, and space-separated values all work. The three channels are extracted from any of them.

What if a channel is over 255?

It is refused with a message, since it is outside the valid range rather than a value to guess at.

Is alpha supported?

The alpha of an rgba value is ignored; the result is the opaque hex colour.

Upper or lower case hex?

The output is lower case, which is equivalent to upper case for a colour.

Related tools

Hex to RGB

Convert a hex colour to RGB in your browser, accepting both three and six digit forms.

Hex to HSL

Convert a hex colour to HSL in your browser, the model that makes colours easy to adjust.

Text to Hex

Convert text to hexadecimal in your browser. Each character becomes its UTF-8 bytes in hex.