Last updated: March 2026
How to Convert RGB to HEX
Converting RGB color values to HEX codes is essential for web developers and designers. RGB defines colors using three decimal numbers from 0 to 255, while HEX uses a compact six-character hexadecimal string that is the standard format in CSS, HTML attributes, and design tools like Figma and Sketch.
To convert, simply paste your RGB value into the input field above. The tool accepts standard CSS notation like rgb(255, 87, 51) and automatically outputs the HEX equivalent along with nine other color formats. No need to do any math — the conversion is instant and accurate.
The RGB to HEX Conversion Formula
The conversion from RGB to HEX is a base-10 to base-16 transformation applied to each color channel independently:
- Take the red value (0-255) and convert to hexadecimal. For 255: 255 / 16 = 15 remainder 15, which is FF.
- Repeat for green. For 87: 87 / 16 = 5 remainder 7, which is 57.
- Repeat for blue. For 51: 51 / 16 = 3 remainder 3, which is 33.
- Combine with a hash prefix: #FF5733
Each channel value maps to exactly two hex digits, with values below 16 getting a leading zero (e.g., 10 becomes 0A). This conversion is completely lossless — the identical color is represented in both notations.
When to Use RGB vs HEX
Use HEX when writing CSS stylesheets, storing colors in design tokens, sharing color values with teammates, or copying from design tools. HEX is more compact and universally recognized in web development contexts.
Use RGB when you need to manipulate individual color channels in JavaScript, work with canvas drawing operations, or need transparency via RGBA. RGB is also more human-readable when you need to quickly understand a color's composition — rgb(255, 0, 0) is obviously pure red, while #FF0000 requires hexadecimal knowledge.
Use RGBA when you need semi-transparent colors. While 8-digit HEX supports alpha, RGBA is more widely supported in older browsers and more readable. For example, rgba(37, 99, 235, 0.5) is clearly a half-transparent blue.
Common RGB to HEX Examples
rgb(255, 255, 255)→ #FFFFFF — Whitergb(0, 0, 0)→ #000000 — Blackrgb(37, 99, 235)→ #2563EB — Bluergb(16, 185, 129)→ #10B981 — Emeraldrgb(239, 68, 68)→ #EF4444 — Redrgb(245, 158, 11)→ #F59E0B — Amber
Frequently Asked Questions
How do I convert RGB to HEX?
To convert RGB to HEX, take each channel value (0-255) and convert it to a two-digit hexadecimal number. For rgb(255, 87, 51): 255 = FF, 87 = 57, 51 = 33, giving you #FF5733. This tool does the conversion automatically — just type or paste any RGB value and the HEX code appears instantly.
What RGB format does the converter accept?
The converter accepts standard CSS RGB notation like rgb(255, 87, 51) as well as RGBA with alpha like rgba(255, 87, 51, 0.5). It also handles the modern CSS syntax with spaces instead of commas. You can paste values directly from your browser DevTools, design software, or any other source.
Can I convert RGBA to HEX with transparency?
Yes. When you enter an RGBA value with an alpha channel, the tool generates an 8-digit HEX code where the last two digits represent the alpha value. For example, rgba(255, 87, 51, 0.5) converts to #FF573380. This format is supported in all modern browsers.
Why would I need to convert RGB to HEX?
HEX codes are the standard color format in CSS, HTML, and most design tools. They are more compact than RGB values and easier to copy-paste into stylesheets. Many design handoff tools like Figma and Zeplin display colors as HEX by default, so converting RGB to HEX ensures consistency across your workflow.
What happens if my RGB values are out of range?
RGB channel values must be between 0 and 255. If you enter a value above 255, the converter clamps it to 255. Values below 0 are clamped to 0. This ensures the output is always a valid HEX color code.