Back to Blog

Hex to RGB: How to Convert Colors Correctly

How hex, RGB, and HSL color formats relate to each other, how to convert between them, and when each format actually makes sense to use.

September 6, 2026
Reading time: ~3 min
Hex to RGB: How to Convert Colors Correctly

Converting a color between formats — hex, RGB, and HSL — means expressing the exact same color using a different notation, since each format encodes color differently: hex uses a 6-digit code (#3B82F6), RGB specifies red, green, and blue intensity as numbers 0–255 (rgb(59, 130, 246)), and HSL describes hue, saturation, and lightness (hsl(217, 91%, 60%)). A color converter translates instantly between them so you're not doing the math by hand.

Why do the same color's values look so different across formats?

Hex, RGB, and HSL aren't different colors — they're different coordinate systems describing the same point in color space, similar to how a location can be described by street address or by GPS coordinates. Design tools, CSS, and different codebases favor different formats, which is why you constantly need to translate between them:

  • Hex is compact and common in CSS and design tools (#FF5733).
  • RGB maps directly to how screens mix red, green, and blue light, and is easier to reason about programmatically.
  • HSL is often the most intuitive for humans to adjust — increasing "lightness" or "saturation" makes visual sense in a way that tweaking raw RGB numbers doesn't.

How do I convert hex to RGB?

A hex code like #3B82F6 splits into three pairs: 3B, 82, F6. Each pair is a base-16 (hexadecimal) number that converts to a base-10 number 0–255:

  • 3B (hex) = 59 (decimal)
  • 82 (hex) = 130 (decimal)
  • F6 (hex) = 246 (decimal)

So #3B82F6 = rgb(59, 130, 246). Doing this conversion by hand for one color is easy enough; doing it for a whole design system's worth of colors is where a converter earns its keep.

What's the difference between RGB and HSL for actually working with color?

RGB tells you the light mixture but not how it "feels" — bumping the blue value doesn't intuitively tell you whether a color got lighter, more saturated, or just bluer. HSL separates those concerns: hue is the color itself (0–360° around a color wheel), saturation is how vivid vs. gray it is, and lightness is how close to black or white it is. This makes HSL the better format when you want to programmatically generate color variations — a lighter or darker shade of a brand color is just adjusting the lightness value, without touching the hue.

Quick reference: common conversions

ColorHexRGBHSL
Pure red#FF0000rgb(255, 0, 0)hsl(0, 100%, 50%)
White#FFFFFFrgb(255, 255, 255)hsl(0, 0%, 100%)
Black#000000rgb(0, 0, 0)hsl(0, 0%, 0%)
Sky blue#3B82F6rgb(59, 130, 246)hsl(217, 91%, 60%)

Does the color format affect transparency?

Hex and RGB both have variants that include an alpha (transparency) channel — 8-digit hex (#3B82F6CC) and rgba() (rgba(59, 130, 246, 0.8)) — while standard HSL has an hsla() equivalent too. The transparency value works the same way regardless of format: 0 is fully transparent, 1 (or FF/100% in hex/alpha terms) is fully opaque.

When would a developer need to convert between these formats?

  • Matching a design file's exact color when the design tool exports hex but the codebase uses RGB variables.
  • Programmatically generating a color palette — lighter/darker shades are easiest to calculate in HSL, then converted to hex for use in CSS.
  • Debugging a color that "looks off" — sometimes it's easier to spot an error (like a value out of range) in one format than another.

The takeaway

Hex, RGB, and HSL are three ways of writing down the exact same color — none is more "correct," just more convenient for a given task. Hex for compact CSS, RGB for direct light-mixture math, HSL for intuitive lightness/saturation adjustments. A converter removes the manual math so you can move between them without slowing down whatever you're actually trying to build.

  • #developer-tools
  • #guides
  • #design
0 comments

    Last updated

    September 6, 2026

    Back to Blog