How to read hex, RGB, and HSL color codes

What each color format actually says, when to reach for which, and how to convert without losing the exact shade

Three ways to write the same color

A screen makes every color by mixing three lights: red, green, and blue. Hex, RGB, and HSL are three notations for describing that same mix. None is more correct than the others, and a given color can be written in all three. They differ in what is easy to see at a glance and what is easy to adjust, which is why a designer often keeps more than one on hand.

Knowing how each one is built means you can read a code without guessing and edit it deliberately. The color converter moves a value between the three formats exactly, but understanding the structure tells you which knob to turn when a color is close but not quite right.

Hex: compact and made for code

A hex code looks like #1a2634. After the hash sign come three pairs of characters, one pair each for red, green, and blue, in that order. Each pair runs from 00 up to ff, which is a way of writing zero to 255 using base sixteen. So #ff0000 is full red with no green or blue, and #000000 is all three off, which reads as black.

  • The first pair is red, the second is green, the third is blue.
  • 00 means none of that light, and ff means the most of it.
  • A shorthand like #1a2 expands by doubling each character to #11aa22.

Hex is the default in CSS and design files because it is short and unambiguous to copy and paste. The trade-off is that it is hard to eyeball: nudging a color a little lighter by hand means doing base sixteen arithmetic in your head, which almost no one wants to do.

RGB: the same channels in plain numbers

RGB writes the identical three channels as ordinary decimal numbers from 0 to 255, like rgb(26, 38, 52). It carries exactly the same information as hex, just in base ten, so #1a2634 and rgb(26, 38, 52) are the same color. Many people find RGB easier to reason about because the numbers are the ones we count with every day.

RGB also has a four-value form, rgba, where the fourth number is opacity from 0 to 1. An alpha of 1 is fully solid and 0 is fully transparent, which is how you fade a color without changing its hue. Hex can carry opacity too, as a fourth pair, but the rgba form spells it out more clearly.

HSL: built for adjusting, not just storing

HSL describes a color the way a person tends to think about one. Hue is an angle from 0 to 360 degrees around a color wheel, where 0 is red, 120 is green, and 240 is blue. Saturation is how vivid the color is, from a flat gray at 0 percent to fully intense at 100. Lightness runs from black at 0 percent through the pure color at 50 to white at 100.

  1. To shift the color family, change the hue angle and leave the other two alone.
  2. To mute or intensify, move the saturation up or down.
  3. To make a tint or shade, raise or lower the lightness.

This is why HSL is the format to reach for when you want a set of colors that belong together. Hold the hue and saturation steady and step the lightness to build a light and dark pair from one base, which is much harder to do by hand in hex.

HSL also makes a common design need straightforward: finding a color's opposite. Add or subtract 180 degrees from the hue and you land on the color across the wheel, a complementary pair that tends to look balanced together. Doing the same thing in hex would mean recomputing all three channels, whereas in HSL it is one small change to a single number, which is the whole reason the format exists.

Converting without losing the shade

Hex and RGB are two spellings of the same numbers, so converting between them is exact and reversible. HSL is a different way of slicing the same space, and the math can land on long decimals, so rounding to whole numbers can move a color by a barely visible amount. For most screen work that rounding is invisible, but if a brand color must match precisely, keep the original hex or RGB as the source of truth and treat HSL as a working copy for adjustments.

A practical routine: store the canonical color in hex, paste it into the color converter to read it as HSL, make your lighter or more muted variant there, then convert that result back to hex to save. When you are placing colored text on an image, the Image Text Overlay tool takes the hex value, so finishing in hex keeps everything consistent.

Common questions about color codes

Is hex better than RGB? No. They hold the same information, so the choice is about convenience. Hex is shorter to paste, RGB reads in familiar decimal, and rgba spells out transparency clearly.

Why does my converted color look slightly off? Almost always rounding when passing through HSL. Keep your master value in hex or RGB and convert from that each time rather than converting a converted value.