Internative Logo

Color Converter: HEX, RGB and HSL in Your Browser

Color Converter: HEX, RGB and HSL in Your Browser

A color on a screen can be written in several ways. Designers hand over HEX values, CSS often wants RGB or HSL, and a design tool may show a different one again. The converter below turns a HEX or RGB value into the other formats and shows a swatch of the color. It runs in your browser, so nothing you enter is sent anywhere.

Color converter

Edit a color in HEX, RGB or HSL and the other two follow. Also reads shorthand such as #0af and CSS forms such as rgb(15 111 215).

What you enter never leaves your browser. Nothing is sent or stored.

How to use the converter

  1. Type a six-digit HEX value, with or without the #, such as #0f6fd7. Press Convert to get the RGB and HSL values.
  2. Or type an RGB value as three numbers from 0 to 255, such as 15, 111, 215, and use the second button to get the HEX and HSL values.
  3. Check the swatch to confirm it is the color you meant. An invalid value shows an error instead of a result.

The same color, #0f6fd7, reads as 15, 111, 215 in RGB and 211, 87%, 45% in HSL.

What the three formats mean

  • HEX is the red, green and blue amounts written in base 16, two digits each. It is the shortest form and the one most design handoffs use.
  • RGB gives the same three amounts as numbers from 0 to 255. It is easy to compute with and to adjust one channel at a time.
  • HSL describes a color by hue (an angle from 0 to 360 on the color wheel), saturation and lightness. It is the easiest format to reason about when you want a darker, lighter or less saturated version of the same color.

Things to watch

  • Six digits only. CSS accepts shorthand such as #fff and eight-digit values with transparency, but the converter reads six digits. Write #ffffff in full.
  • HSL is rounded. The converter rounds hue, saturation and lightness to whole numbers. Converting back from a rounded HSL value can land one step away from the original HEX, so keep the HEX as your source of truth.
  • Screens differ. HEX, RGB and HSL as used here describe the same color in the sRGB space that browsers use by default. The same value can still look different on screens that are calibrated differently, and print uses other color models altogether.
  • A format is not a palette. Converting one color tells you nothing about whether it works as text on a given background. Check contrast separately before you use it.

Where it comes up

The usual case is moving a brand color between a design file, a stylesheet and a UI library that each ask for a different format. Doing this once by hand is fine. When the same values are copied into many places, they drift. That is why we put them in a shared design system, which is part of our UI design and visual systems work, and keep it in step with code through design-to-code handoff.

Frequently asked questions

Does my color value leave my browser?

No. The conversion is plain arithmetic done in the page on your device. Nothing is sent or stored.

Can I enter an HSL value?

The converter starts from a HEX or an RGB value and gives you the other two formats. If you only have HSL, you can still paste it into your CSS directly, since browsers accept hsl() as it is.

Why is the HEX different after I convert back?

HSL is shown in whole numbers, so some precision is lost. Converting that rounded value back can give a HEX that is off by a step or two on one channel. HEX and RGB convert into each other exactly.

Does it support transparency?

No. The tool handles opaque colors: six-digit HEX and three-number RGB. Alpha values need to be added in your CSS.

Which format should I use in CSS?

All three work in every current browser. Pick one for the project and stay with it. HEX is compact, and HSL is convenient when you derive lighter and darker shades.

Related services

Where this topic becomes an engagement.

Keep reading

The articles that follow this one.