Home / Blog / Color & design

Color & design

Find a HEX Code from RGB: Convert and Pad Each Channel

Turn RGB channel values into a six-digit HEX color, including leading-zero examples, decimal rounding, supported input ranges and exact round-trip checks.

To find a six-digit HEX code from RGB, convert the red, green and blue channel values to hexadecimal separately. Write each channel using exactly two digits, then join them in red-green-blue order after a hash sign. For RGB values 5, 128 and 250, the result is #0580fa.

Convert one byte at a time

For an integer channel, divide by sixteen. The whole-number quotient supplies the first digit and the remainder supplies the second. Digits above nine use a through f. A channel of 250 is fifteen groups of sixteen plus ten, so it becomes fa. A channel of 128 becomes 80 because eight times sixteen is 128 with no remainder.

ChannelDecimalQuotient and remainderHEX pair
Red50 and 505
Green1288 and 080
Blue25015 and 10fa

Leading zeroes are part of the channel representation. Joining 5, 80 and fa without padding produces only five digits and loses the fixed pair boundaries. Keep 05 even though the decimal value is still five. Uppercase 0580FA represents the same channels as lowercase 0580fa.

Enter the values in the correct mode

Open RGB to HEX and select RGB → HEX. Enter 5, 128, 250, then check that the HEX line reads #0580fa. The converter also accepts the function-shaped input rgb(255, 99, 71), which produces #ff6347. Keep exactly three comma-separated channels.

The accepted channel range is zero through 255. This converter rounds decimal channels to whole byte values for its six-digit output. For example, 12.4 rounds to 12 and 12.6 rounds to 13. If your source deliberately preserves fractional precision, recognize that a six-digit byte representation is a quantized output rather than a lossless record of those fractions.

Identify inputs that need a different interpretation

A missing channel, an extra fourth value or a non-finite number is not a complete supported RGB input. The tool rejects values outside its stated range instead of silently substituting a boundary value. After an invalid entry, the previous output and preview should be cleared and Copy should remain unavailable until the input is valid again.

Normalized values such as 0.5, 0.25 and 1 use a different scale when the source API defines them as zero-to-one components. Multiply by 255 and apply the intended rounding policy before entering byte values. Do not assume that small decimal inputs automatically imply normalization: in this tool, 1 is the byte value one.

Decode the result to confirm channel order

Split #0580fa back into 05, 80 and fa and convert them to decimal. You should recover 5, 128 and 250 in that order. Check another asymmetric example, such as 255, 99 and 71, so a red-blue swap cannot pass unnoticed. Equal-channel gray is useful for a separate test but cannot expose every ordering mistake.

For integer byte inputs, this round trip is exact. For decimal inputs, compare with the explicitly rounded byte values. Record that distinction if the conversion is part of a design-token migration or an export pipeline where another tool expects higher precision.

Check black and white as endpoint tests: 0, 0, 0 must become #000000, and 255, 255, 255 must become #ffffff. These cases also reveal missing padding or a mistaken channel maximum of 256.

Use the correct portion of the result

The Copy action returns the labeled HEX, RGB and HSL text. A color field expecting one HEX value needs only the hash and six digits from the HEX line. Preserve any separate opacity setting in the destination; this converter does not attach an alpha channel to its six-digit result. Numeric equivalence also does not establish print matching or interface readability, which require their own context.

Syntax reference

See the CSS color reference for additional color forms and syntax beyond this converter.