RGB to Hex Converter
Convert decimal RGB values (0–255) into clean lowercase/uppercase hexadecimal codes with instant clipboard copy and CSS snippet.
How to Use This Tool
- Enter or paste your RGB value or choose one of the curated preset swatches.
- Copy the formatted HEX value directly, or inspect the secondary HEX, RGB, HSL, and OKLCH chips below.
- Click into Tailwind Scale Generator or Contrast Checker to validate accessibility on the converted shade.
Key Features
- Bidirectional parsing supporting CSS Color Level 4 syntax cleanly
- Each channel integer R, G, and B (0–255) converts to base-16 via toString(16) and pads with a leading zero whenever the byte is below 16.
- Instant clipboard feedback with live OKLCH and Display-P3 gamut safety
- Zero server round-trips—every calculation executes immediately in browser memory
Converting 0–255 channels to Hexadecimal
Each channel integer R, G, and B (0–255) converts to base-16 via toString(16) and pads with a leading zero whenever the byte is below 16.
Reference Snippet (JavaScript)
const toHex = (r, g, b) =>
'#' + [r, g, b].map((v) => v.toString(16).padStart(2, '0')).join('');Frequently Asked Questions
Values above 255 or below 0 are safely clamped into the standard 8-bit 0–255 sRGB range.
Yes, optional alpha converts into the final two hex digits (#rrggbbaa).
More Color Tools
View all tools →Color Converter
Convert single or bulk colors across HEX, RGB, HSL, OKLCH, P3, CMYK, and mobile formats.
Color Picker & Eyedropper
Pick exact colors in HEX, RGB, HSL, or OKLCH and sample pixels directly from your screen.
Tailwind Color Scale
Turn any brand color into a balanced 50–950 Tailwind scale with live contrast checks.
Contrast Checker
Check text and UI contrast against WCAG AA/AAA and APCA standards, with 1-click fixes.