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.
Yes. CSS requires the # prefix for hex colors in color property values (color, background-color, border-color, etc.). SVG attributes like fill and stroke also use the # prefix. Tailwind CSS utility class names omit the # — you pass the bare 6-digit value in tailwind.config.js, e.g. colors: { brand: "ff5733" }.
The standard 6-digit #rrggbb hex code has no alpha/transparency channel. The 8-digit #rrggbbaa format adds a 2-digit alpha channel at the end, where 00 is fully transparent and ff is fully opaque. Most modern browsers support 8-digit hex codes, but some older tools and design apps only recognize 6-digit codes.
No. The conversion runs entirely in your browser using JavaScript. No data is sent to a server, and no colors are stored or logged.
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