The conversion
A hex color packs three numbers — red, green and blue — into six hexadecimal digits, two per channel. Converting to RGB just means reading each pair as a base-16 number from 0 to 255:
Going the other way, each RGB value (0–255) becomes a two-digit hex pair, padded with a leading zero if needed. The two notations are exactly equivalent — hex is compact for stylesheets, RGB is easy to compute with.
Worked example
Converting #1D4ED8 to RGB:
Shorthand and alpha
CSS also allows 3-digit shorthand like #1d8, which expands by doubling each digit to #11dd88. An optional fourth pair (or fourth digit) sets the alpha channel for transparency — #1d4ed880 is the same blue at ~50% opacity. This converter accepts 3- or 6-digit hex with or without the leading # and shows the equivalent RGB and HSL.