About the RGB to HEX
This tool converts rgb() and rgba() values to HEX codes. A plain RGB gives a 6-digit code; an RGBA with alpha below 1 gives an 8-digit code with the alpha channel. It accepts values with or without the rgb() wrapper and separated by commas or spaces. Convert several at once, one per line.
Each channel is written as exactly two base-16 digits, zero-padded, so 31 becomes 1f and 7 becomes 07. Dropping that leading zero is a classic bug, because #1f7c16 and #1f7c6 are not the same string and the five-digit version is not valid CSS at all. Percentage inputs are scaled before conversion, so rgb(50%, 20%, 100%) is read as 128, 51, 255.
Alpha is the mirror image of the problem you get going the other way: a 0 to 1 decimal is multiplied by 255 and rounded, so 0.5 lands on 80 rather than 7f. That rounding loses information, which means taking a HEX code to RGBA and back can move the alpha byte by one. The colour on screen does not change, but a string comparison in a snapshot test will fail, and that is usually where the mismatch is first noticed.
HEX is the most compact colour notation and the usual form in design tools and markup. To convert back, use HEX to RGB; if you would rather tune the colour than record it, RGB to HSL gives you handles for hue and lightness.
How to use
- Paste rgb() or rgba() values, one per line.
- Copy the HEX codes.
- Alpha below 1 gives an 8-digit code.
Common questions
- Do I need the rgb() wrapper?
- No, a bare "31, 193, 107" works too.
- How is alpha represented?
- As two extra hex digits (#RRGGBBAA). Fully opaque colours give a 6-digit code.
- Are percentage RGB values supported?
- Yes, rgb(50%, 20%, 100%) is handled.