Skip to content

All tools (41)

JSON 6
Time & Date 4
Encoding & Decoding 4
Generators 3
Text & Data 4
Logs & Debugging 1
Config & Infra 3
Security & Hashing 4
Color & Design 5
Numbers & Bits 3
Web & Markup 4

Nothing leaves the cave.

Nothing you paste ever leaves your device. There is no server to send it to.

How you can check →
DevToolsCave

    This tool runs entirely in your browser. Nothing you paste is uploaded.

    How you can check →

    RGB to HEX converter

    Converts RGB to HEX, entirely in your browser, with the same round-trip receipt the full color converter shows.

    HEX output

    RGB to hex is an exact, lossless conversion — each of the three 0-255 channel values becomes a two-digit base-16 pair, and three pairs concatenated together is the hex string. There's no rounding involved and no precision to choose, unlike converting to HSL or OKLCH, because hex and RGB are just two different ways of writing down the same three numbers.

    Where a converter can actually go wrong is parsing the input, because rgb() syntax has more valid forms than most people expect. The legacy comma-separated syntax, rgb(59, 130, 246), has been joined by CSS Color 4's space-separated form, rgb(59 130 246), and both are equally valid modern CSS. Alpha can appear as a fourth comma-separated value in the older rgba() function, or as a slash-separated fraction or percentage in either rgb() or rgba() under the modern syntax — rgb(59 130 246 / 0.5) and rgb(59 130 246 / 50%) both mean the same 50% opacity. A parser that only recognizes the comma form will reject perfectly valid modern CSS pasted from a browser's own devtools.

    A worked example, measured directly: rgb(59, 130, 246) converts to #3b82f6 exactly, with alpha at full opacity omitted from the hex output since 6-digit hex has no alpha channel of its own. Add alpha — rgb(59 130 246 / 0.5) — and the correct hex output grows to 8 digits: #3b82f680, where the trailing 80 is 50% opacity expressed as a hex byte (0.5 × 255 ≈ 128, which is 0x80).

    Percentage-based RGB channels are also valid CSS and easy to miss: rgb(23% 51% 96%) converts to #3b82f5, essentially the same blue as the integer example above (a one-unit rounding difference in the blue channel from the percentage-to-255 conversion), and describes each channel as a percentage of 255 rather than a literal 0-255 integer. A converter that only accepts integer channel values will silently fail or misread this form rather than converting it correctly.

    Use this conversion when you have a color specified in RGB — commonly from a design tool's color picker, a JavaScript canvas API, or CSS already using rgb() — and need the more compact hex form for a config file, a database column, or anywhere hex is the expected convention.

    Frequently asked questions

    Does this converter accept both comma and space-separated RGB syntax?
    Yes — both the legacy rgb(59, 130, 246) form and the modern CSS Color 4 rgb(59 130 246) form are accepted, along with alpha as a fourth comma value, a slash-separated fraction, or a slash-separated percentage.
    How does alpha show up in the hex output?
    As two extra hex digits at the end, making an 8-digit hex value (#rrggbbaa). 50% alpha (0.5) becomes 80 in hex — 0.5 × 255 rounds to 128, which is 0x80. Full opacity omits the alpha digits entirely, producing a standard 6-digit hex.
    Can RGB channels be written as percentages instead of 0-255 numbers?
    Yes — rgb(23% 51% 96%) is valid CSS, with each channel as a percentage of 255 rather than an integer. This converter accepts that form as well as the more common integer 0-255 syntax.