Convert a wavelength of light in nm to its approximate RGB and hex color, or find the dominant wavelength of any RGB color.

Gives the closest screen color for a single wavelength of visible light.

Visible light runs from 380 nm (violet) to 780 nm (red).

Optional settings

Calculator Functions

The calculator converts between a wavelength of visible light and an sRGB screen color, with the hex code, a color preview and the CIE 1931 chromaticity. Select a function to open it in the calculator.

FunctionUse it whenYou enter
Wavelength to RGBYou know the wavelength of a laser, LED or spectral line and want its color on a screenWavelength from 380 to 780 nm, in nm, µm or Å
RGB to wavelengthYou have a screen color and want the single wavelength with the same hueRed, green and blue values from 0 to 255

Wavelength to RGB also gives the frequency of the light. RGB to wavelength also gives the excitation purity, which says how close the color is to pure spectral light, and shows the screen color of the wavelength it finds.

Wavelength to RGB Formulas

c = M × XYZ [2]
cLinear red, green and blue values, before the sRGB encoding
MThe matrix that converts CIE XYZ to linear sRGB for a D65 white point [2]
XYZThe CIE 1931 color-matching values at the wavelength, read from the CIE table at 1 nm steps [1]

Wavelength to RGB

A single wavelength is more saturated than any screen color, so at least one of the three linear values comes out negative. The calculator sets negative values to 0, divides by the largest value so the color is at full brightness, and then applies the sRGB encoding to each value:

C = 1.055 × c1/2.4 − 0.055 [2]

For c at or below 0.0031308 the encoding is C = 12.92 × c instead. Each C is multiplied by 255 and rounded to give the RGB value, and the hex code is the same three numbers in base 16. Frequency is the speed of light divided by the wavelength, so f in THz = 299,792.458 ÷ λ in nm.

RGB to wavelength

x = X ÷ (X + Y + Z)
y = Y ÷ (X + Y + Z)

The RGB values are decoded to linear values and converted to XYZ with the inverse of M, which gives the chromaticity (x, y) of the color [2]. The calculator then draws a line on the CIE 1931 chromaticity diagram from the D65 white point (0.3127, 0.3290) through the color. The wavelength where that line meets the curve of pure spectral colors is the dominant wavelength: light of that wavelength mixed with white matches the color [3].

Purples and magentas are mixes of red and blue light, so their line never reaches the spectral curve. For those colors the calculator extends the line the other way and reports the complementary wavelength, the wavelength that mixes with the color to make white [3]. Grey, white and black sit on the white point and have no wavelength at all.

p = dc ÷ ds [4]

Excitation purity p compares two distances along that line: dc from the white point to the color, and ds from the white point to the spectral curve, or to the purple boundary for a purple. A purity of 100% is pure spectral light and 0% is white.

Limits of This Estimate

  • No screen can show pure spectral light. Setting the negative values to 0 picks a nearby color the screen can show, and it shifts the hue slightly [2]. Wavelengths from 515 to 552 nm all give pure green, and 608 nm and longer all give pure red, because those are the closest colors sRGB has.
  • The color is shown at full brightness. The eye is much less sensitive below about 420 nm and above about 680 nm, so real light at those wavelengths looks far dimmer than the preview.
  • RGB to wavelength treats the values as sRGB with a D65 white point. A color in another color space, or a screen that is not calibrated, gives a different wavelength.
  • A dominant wavelength describes hue only. Most screen colors are broad mixes of light, so the result does not mean the screen emits that wavelength.

Sources

  1. International Commission on Illumination (CIE), CIE 1931 colour-matching functions, 2 degree observer: the X, Y and Z values at each wavelength
  2. W3C, CSS Color Module Level 4: the XYZ and sRGB matrices, the sRGB encoding, the D65 white point and the hue shift from clipping
  3. CIE, International Lighting Vocabulary, 17-23-062 dominant wavelength: dominant wavelength, and the complementary wavelength used for purples
  4. CIE, International Lighting Vocabulary, 17-23-066 excitation purity: excitation purity as a ratio of two distances on the chromaticity diagram