Tools / Color Converter / RGB → HEX

RGB to HEX Converter.

RGB to HEX is the reverse of reading a hex string: take each 0-255 channel, convert it to a two-digit base-16 number, and concatenate them behind a #. The only gotcha is zero-padding — a channel like 5 must become 05, not 5.

HEX
All formats

    The RGB → HEX formula

    hex = '#' + toHex(R) + toHex(G) + toHex(B) where toHex(n) = n.toString(16).padStart(2,'0').

    Worked example

    Convert rgb(154, 42, 42):

    1. Red: 154 = 9A in hex
    2. Green: 42 = 2A in hex
    3. Blue: 42 = 2A in hex
    4. Concatenate: #9A2A2A

    JavaScript

    const h = n => n.toString(16).padStart(2,"0");
    const hex = "#" + h(154) + h(42) + h(42); // "#9a2a2a"

    FAQ

    Why pad to two digits?

    Each channel must occupy exactly two hex digits. Without padding, rgb(5, 16, 255) would collapse to #510ff instead of #0510FF.

    Upper or lower case?

    Both are valid and identical to browsers. Designers often prefer uppercase for readability; it carries no semantic difference.

    Looking for a combination we don’t have yet?

    Tell us the colour, mood, or palette you were after — it shapes which editorial combinations we add next.