RGB to HEX Converter
RGB to HEX converter translates Red, Green, and Blue decimal color values (0-255) into standard 6-digit hexadecimal codes (#RRGGBB) in real time. Get instant CSS ready color codes for your web design, frontend UI components, and graphic projects with complete mathematical accuracy.
Why Use Our Fast RGB to HEX Converter?
How to Convert RGB to HEX in 3 Simple Steps
Follow this quick guide to translate any RGB color specification into a standard hexadecimal code.
Type or paste your Red (R), Green (G), and Blue (B) integer values ranging from 0 to 255 into their corresponding numeric fields. Each channel represents an 8-bit digital color intensity.
The conversion algorithm divides each decimal channel value by 16 to determine the quotient and remainder, assembling a standard two-digit base-16 hexadecimal pair.
Click the Copy button to capture the formatted 6-character hexadecimal code (such as #17A2B8) directly to your clipboard for CSS stylesheets, Tailwind config, or UI software.
Understanding the Mathematical RGB to HEX Formula
Explore the exact base-10 to base-16 arithmetic that powers digital color representation across all modern displays.
An RGB color model defines each color channel using an 8-bit byte, yielding values from 0 to 255 (256 total values per channel). A hexadecimal code packs these three 8-bit bytes into a 6-character string (#RRGGBB).
For remainders between 10 and 15, base-16 uses alphanumeric letters:10=A, 11=B, 12=C, 13=D, 14=E, 15=F
Let us convert rgb(23, 162, 184) into HEX:
- Red (23): 23 / 16 = 1 (rem 7) => 17
- Green (162): 162 / 16 = 10 (rem 2) => A2
- Blue (184): 184 / 16 = 11 (rem 8) => B8
Display Hardware and the Additive Color Model
How screen emission technology and human trichromatic vision intersect with RGB and hexadecimal formats.
Unlike print (which uses subtractive CMYK ink absorption), screens emit light directly. When Red, Green, and Blue overlap at maximum intensity (255, 255, 255), they create pure white light.
Each color channel uses 8 bits of memory (1 byte). Combining three 8-bit channels provides 24 bits of color depth, creating exactly 2^24 = 16,777,216 distinct identifiable shades.
Graphics shaders and framebuffers store pixels as 32-bit words (RGBA). A 6-character hex string maps directly to memory offsets with zero transformation overhead.
RGB to HEX Code Snippets for Developers
Easily integrate robust color conversion algorithms into your own JavaScript, TypeScript, Python, or CSS workflows.
function rgbToHex(r: number, g: number, b: number): string {
const toHex = (c: number) => {
const hex = Math.max(0, Math.min(255, Math.round(c))).toString(16);
return hex.length === 1 ? '0' + hex : hex;
};
return '#' + (toHex(r) + toHex(g) + toHex(b)).toUpperCase();
}
// Example usage:
console.log(rgbToHex(23, 162, 184)); // "#17A2B8"const rgbToHexBitwise = (r, g, b) =>
'#' + ((1 << 24) + (r << 16) + (g << 8) + b)
.toString(16)
.slice(1)
.toUpperCase();
// Example usage:
console.log(rgbToHexBitwise(255, 99, 71)); // "#FF6347"def rgb_to_hex(r: int, g: int, b: int) -> str:
r_clamped = max(0, min(255, r))
g_clamped = max(0, min(255, g))
b_clamped = max(0, min(255, b))
return f"#{r_clamped:02X}{g_clamped:02X}{b_clamped:02X}"
# Example usage:
print(rgb_to_hex(23, 162, 184)) # "#17A2B8"/* CSS Custom Properties */
:root {
--brand-primary-rgb: 23, 162, 184;
--brand-primary-hex: #17A2B8;
}
.element {
background-color: var(--brand-primary-hex);
border-color: rgba(var(--brand-primary-rgb), 0.5);
}Popular Color Codes: RGB to HEX Reference Table
Quick reference guide for commonly used digital design colors with their exact RGB, HEX, and HSL equivalents.
| Preview | Color Name | HEX Code | RGB Value | HSL Value | Category |
|---|---|---|---|---|---|
| Pure Red | #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) | Primary | |
| Pure Green | #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) | Primary | |
| Pure Blue | #0000FF | rgb(0, 0, 255) | hsl(240, 100%, 50%) | Primary | |
| Pure White | #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) | Neutral | |
| Pure Black | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) | Neutral | |
| Slate Gray | #708090 | rgb(112, 128, 144) | hsl(210, 13%, 50%) | UI Accent | |
| Coral Orange | #FF7F50 | rgb(255, 127, 80) | hsl(16, 100%, 66%) | Vibrant | |
| Teal Blue | #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) | Brand | |
| Amber Gold | #FFBF00 | rgb(255, 191, 0) | hsl(45, 100%, 50%) | Warning | |
| Royal Purple | #7851A9 | rgb(120, 81, 169) | hsl(267, 35%, 49%) | Creative | |
| Crimson | #DC143C | rgb(220, 20, 60) | hsl(348, 83%, 47%) | Alert | |
| Midnight Navy | #191970 | rgb(25, 25, 112) | hsl(240, 64%, 27%) | Dark Mode |
Frequently Asked Questions About RGB to HEX
Everything you need to know about color formats, conversion algorithms, and web standards.
Explore Related Color Conversion Tools
Switch between any web color format with our comprehensive suite of free utilities.