Skip to content
100% in your browser. Nothing you paste is uploaded — all processing runs locally. Read more →

RGB → Hex

Paste an RGB value, get hex back. rgb(37, 99, 235)#2563eb. The full converter at the bottom also gives you HSL and OKLCH.

#2563eb
Presets
🔒 100% client-side · uses browser's native color parsing · no upload

The conversion in one line

rgb(R, G, B)  →  "#" + hex(R) + hex(G) + hex(B)
   each component padded to 2 hex digits, lowercase

Where hex(n) is n.toString(16).padStart(2, "0") in JavaScript, or format(n, "02x") in Python.

Common conversions

RGBHexName
rgb(0, 0, 0)#000000Black
rgb(255, 255, 255)#ffffffWhite
rgb(255, 0, 0)#ff0000Red
rgb(34, 197, 94)#22c55eTailwind green-500
rgb(168, 85, 247)#a855f7Tailwind purple-500
rgb(244, 114, 182)#f472b6Tailwind pink-400
rgb(251, 191, 36)#fbbf24Tailwind amber-400
rgb(75, 85, 99)#4b5563Tailwind gray-600

In code

// JavaScript
const hex = (r, g, b) =>
  "#" + [r, g, b].map(n => n.toString(16).padStart(2, "0")).join("");
hex(37, 99, 235);  // "#2563eb"

// Python
def rgb_to_hex(r, g, b):
    return "#{:02x}{:02x}{:02x}".format(r, g, b)

// Bash
printf "#%02x%02x%02x\n" 37 99 235

// Go
import "fmt"
fmt.Sprintf("#%02x%02x%02x", r, g, b)

// CSS (Color Module 4 supports rgb() with alpha and modern syntax)
.brand { color: rgb(37 99 235); }                 // space-separated
.brand { color: rgb(37 99 235 / 0.5); }            // alpha

Edge cases

Try the related tools

FAQ

What input forms are accepted?

The RGB field accepts rgb(r, g, b), r, g, b, r g b, and percentage forms like rgb(50%, 25%, 75%). The output hex uses 6 lowercase digits.

Can I convert RGBA?

The alpha channel doesn't fit in 6-digit hex. CSS Color Module 4 added 8-digit hex (#RRGGBBAA) for alpha — paste an RGBA value and the converter ignores the alpha; for the 8-digit form you can append aa manually (alpha as 2 hex digits).

What if my values are floats (0.0–1.0)?

The converter expects 0–255. If you have 0.0–1.0 floats, multiply by 255 first: 0.5127 (or 128 depending on rounding). Image-processing libraries often use floats; CSS uses integers.