RGB to HEX Converter
Convert three comma-separated sRGB channels (0–255) to a HEX code and relative luminance.
Last updated · View algorithm, constants and default inputs (JSON)
About this calculator
Enter three whole-number sRGB channels from 0 to 255, separated by commas. Relative luminance is reported on a 0–1 scale; it is not a contrast ratio.
Worked example
calculated with the default values below
RGB values (comma separated) 59,130,246 HEX #3B82F6 · HEX #3B82F6 · Red 59 · Green 130 · Blue 246 · Relative luminance 0.2355
General background references
Disclaimer
These calculators give general conversion results. Rounding and the precision of the value you enter both affect the output, so treat displayed decimals as indicative rather than exact.
Implementation source
This record describes the implementation used by this page. It is not independent validation. External references, when available, support only the stated formula or definition; estimates and custom rules retain their own assumptions.
Formula and variables
Y = 0.2126 R′ + 0.7152 G′ + 0.0722 B′; C′ → s ÷ 12.92 (s ≤ 0.03928) | ((s + 0.055) ÷ 1.055)^2.4 (s > 0.03928); s = C ÷ 255
- C
- channel value (0–255)
- s
- C ÷ 255
- C′
- linearised channel value
- R′,G′,B′
- linearised channels
- Y
- relative luminance
Inputs must be three comma-separated whole-number sRGB channels from 0 to 255. Relative luminance is not a contrast ratio.
Frequently asked questions
What does relative luminance mean?
Relative luminance converts the sRGB channels to linear light and combines them using the WCAG weights. The result is between 0 and 1. It is not a contrast ratio; compare two colours with a contrast-ratio calculation when checking text contrast.