What is the formula for converting RGB to HEX?
HEX = # + toHex(R) + toHex(G) + toHex(B), where toHex() converts each decimal value (0-255) to a 2-digit padded hex string.
RGB to HEX Converter transforms decimal RGB color values (0-255) into their hexadecimal CSS color code equivalent. Frontend developers use this when a design tool provides an RGB value that needs to be used as a CSS HEX code, when converting Python or JavaScript RGB tuples to CSS colors, or when standardizing a design system's color palette to hex format.
Each RGB channel value (0-255) is converted from decimal to a 2-digit hexadecimal number and concatenated with a # prefix: R=255 becomes ff, G=87 becomes 57, B=51 becomes 33, giving #ff5733. The converter zero-pads single-digit hex values (e.g., 8 becomes 08).
HEX = # + toHex(R) + toHex(G) + toHex(B), where toHex() converts each decimal value (0-255) to a 2-digit padded hex string.
Yes. An alpha value (0-1) is converted to a 2-digit hex alpha channel appended at the end, giving an 8-digit #rrggbbaa hex code.
Each channel (Red, Green, Blue) ranges from 0 to 255. Values outside this range are clamped to 0 or 255 automatically.
No. Color conversion runs entirely in your browser.
Yes, completely free. No login required.
Yes. CSS requires the # prefix for hex colors in color property values and background-color. SVG attributes also use the # prefix.
Tool workspace
Free RGB to HEX converter online — instantly convert RGB or RGBA color values to HEX color codes for CSS and HTML. Enter r, g, b values and get #rrggbb instantly. No login.
Input
rgb(255, 87, 51)
Output
#ff5733