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.

    Paid links below. As an Amazon Associate we earn from qualifying purchases.

    Library

    Colour references for your next project

    Compare the original references behind this archive. Check the contents, edition and format before choosing a book.

    Book links are Amazon Associates affiliate links. Your price is unchanged; a small commission supports the archive. As an Amazon Associate we earn from qualifying purchases.

    Torn between the two Wada dictionaries? Vol 1 vs Vol 2, compared plate by plate →

    Book links are Amazon Associates affiliate links. Your price is unchanged; a small commission supports the archive. As an Amazon Associate we earn from qualifying purchases.

    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.