Free tool

RGB to HEX converter

Enter red, green and blue values from 0 to 255 to get the HEX code: rgb(255, 87, 51) is #FF5733. Drag the sliders or paste rgb(), rgba() or three plain numbers; alpha turns into an 8-digit code.

Free · no sign-up · runs in your browser, nothing is uploaded

[swap: HEX to RGB →]
RGB value
read as rgb()#FF5733rgb(255, 87, 51)
HEX result
HEX#FF5733
No #FF5733
0x integerdecimal value0xFF5733 = 16734003
The math
  1. Red: 255 ÷ 16 = 15 remainder 15 → FF
  2. Green: 87 ÷ 16 = 5 remainder 7 → 57
  3. Blue: 51 ÷ 16 = 3 remainder 3 → 33

= #FF5733

Divide by 16: the quotient is the first hex digit, the remainder the second. 10=A, 11=B, 12=C, 13=D, 14=E, 15=F.

Other formats
RGBCSS Color 4rgb(255 87 51)
RGB (legacy)rgb(255, 87, 51)
HSLhsl(10.6 100% 60%)
HWBhwb(10.6 20% 0%)
OKLCHoklch(68.04% 0.21 33.69)
OKLaboklab(68.04% 0.1747 0.1165)
LabCIE, D50lab(61.03% 63.55 55.96)
LCHCIE, D50lch(61.03% 84.67 41.37)
HSV / HSBnot CSShsv(10.6, 80%, 100%)
CMYKnaive, no ICC profilecmyk(0%, 65.9%, 80%, 0%)
Nearest Tailwind color
  • orange-600#f54900ΔE 3.6
  • orange-500#ff6900ΔE 4.3
  • red-400#ff6467ΔE 5

Distance is ΔE OK × 100 in OKLab; under about 2 is hard to tell apart. Nearest CSS name: tomato (ΔE 2.2).

WCAG contrast
Aaon white3.15:1✗ AA✓ AA large✗ AAA✓ UI 3:1
Aaon black6.66:1✓ AA✓ AA large✗ AAA✓ UI 3:1
Aawhite text on it3.15:1✗ AA✓ AA large✗ AAA✓ UI 3:1

WCAG 2.2: 4.5:1 for body text (AA), 3:1 for large text and UI parts, 7:1 for AAA.

Tints and shades
click to use

Tints (+ white), 10% to 90%

Shades (+ black), 10% to 90%

The RGB to HEX formula

Each RGB channel is one byte, a number from 0 to 255. Written in base 16 it always fits in two digits. Divide by 16: the whole-number result is the first digit, the remainder is the second.

rgb(255, 87, 51)

255 ÷ 16 = 15 remainder 15  → F F  → FF
 87 ÷ 16 =  5 remainder  7  → 5 7  → 57
 51 ÷ 16 =  3 remainder  3  → 3 3  → 33

= #FF5733

Digits above 9 are letters: A=10, B=11, C=12, D=13, E=14, F=15. A value under 16 needs a leading zero: 5 is 05, not 5. Forgetting the zero is the most common bug in hand-written converters, because #FF573 is not a valid color.

Worked examples

RGBPer channelHEX
rgb(0, 0, 0)00 · 00 · 00#000000
rgb(255, 255, 255)FF · FF · FF#FFFFFF
rgb(30, 144, 255)1E · 90 · FF#1E90FF
rgb(46, 204, 113)2E · CC · 71#2ECC71
rgb(99, 91, 255)63 · 5B · FF#635BFF
rgb(15, 23, 42)0F · 17 · 2A#0F172A
rgb(255, 85, 51)FF · 55 · 33#FF5533 = #F53
rgba(255, 87, 51, 0.5)FF · 57 · 33 · 80#FF573380

What RGB input the converter accepts

Paste any of these. The swatch and sliders follow, and the URL keeps the value, so you can share a link to the result.

InputRead as
rgb(255, 87, 51)Classic comma syntax
rgb(255 87 51 / 50%)CSS Color 4 space syntax with alpha after /
rgba(255, 87, 51, 0.5)rgba() is an alias of rgb() in CSS Color 4
rgb(100% 34% 20%)Percentages, 100% = 255
255, 87, 51 or 255 87 51Plain numbers, as copied from Figma or Photoshop fields

Bulk mode converts a whole list, one color per line, and lets you choose uppercase, lowercase or no #. Lines it cannot read are marked with the reason.

Convert RGB to HEX in code

JavaScript

const rgbToHex = (r, g, b) =>
  '#' + [r, g, b].map(v => Math.round(v).toString(16).padStart(2, '0')).join('').toUpperCase();

rgbToHex(255, 87, 51); // '#FF5733'

Python

def rgb_to_hex(r: int, g: int, b: int) -> str:
    return f'#{r:02X}{g:02X}{b:02X}'

rgb_to_hex(255, 87, 51)  # '#FF5733'

Go

hex := fmt.Sprintf("#%02X%02X%02X", 255, 87, 51) // "#FF5733"

Bash

printf '#%02X%02X%02X\n' 255 87 51   # #FF5733

In each case the 02 pads to two digits and X prints uppercase hex; use x for lowercase. CSS does not care about case.

FAQ

How do I convert RGB to HEX?+

Take each channel (0 to 255), divide it by 16, and write the quotient and the remainder as hex digits (10=A through 15=F). Join the three pairs after a #. For rgb(255, 87, 51): 255 = FF, 87 = 57, 51 = 33, so #FF5733.

What is rgb(255, 255, 255) in HEX?+

#FFFFFF, white. rgb(0, 0, 0) is #000000, black. Each 255 becomes FF because 255 ÷ 16 = 15 remainder 15, and 15 is F.

How do I convert RGBA to HEX?+

Convert red, green and blue as usual, then multiply the alpha (0 to 1) by 255, round it, and add it as a fourth pair. rgba(255, 87, 51, 0.5) becomes 0.5 × 255 = 127.5 ≈ 128 = 80, so #FF573380. All current browsers read 8-digit hex in CSS.

Why does my HEX code have only three digits?+

When every pair has two identical digits, the code can be shortened: #FF5533 is the same as #F53. The converter shows the short form only when it exists. #FF5733 has no short form because 57 is not a repeated digit.

What happens with RGB values above 255 or with decimals?+

CSS clamps out-of-range channels: rgb(300, 0, 0) is drawn as rgb(255, 0, 0). Decimals are allowed in CSS rgb(), but a hex code holds whole numbers only, so 127.5 is rounded to 128 (80). The tool warns you when it clamps.

How do I convert RGB to HEX in Excel?+

With red, green and blue in A1, B1 and C1: ="#"&DEC2HEX(A1,2)&DEC2HEX(B1,2)&DEC2HEX(C1,2). The 2 pads each channel to two digits, so 5 becomes 05 instead of 5.

Sources: CSS Color Module Level 4: rgb() · CSS Color Module Level 4: hex notation · MDN: rgb() · MDN: <hex-color> · Python format spec · Go fmt · Microsoft: DEC2HEX function. Checked 2026-10-30.