Color Converter

Convert a color between HEX, RGB and HSL with a live preview, then read how each value is calculated and where each format fits.

Accepted: #3b82f6, #38f, 3b82f6, rgb(59, 130, 246) and hsl(217, 91%, 60%). The result updates while you type.

Conversion result

The swatch and the three values below always describe the same color.

Format Value What the numbers mean
HEX #3b82f6 Three byte pairs written in base 16
RGB rgb(59, 130, 246) Red, green and blue channels from 0 to 255
HSL hsl(217, 91%, 60%) Hue in degrees, saturation and lightness in percent

Color format cheat sheet

Format Example Channel range Alpha support
HEX#3b82f600 to ff per pair8 digits: #3b82f680
RGBrgb(59, 130, 246)0 to 255 per channelrgba(59, 130, 246, 0.5)
HSLhsl(217, 91%, 60%)Hue 0-360, S and L 0-100%hsla(217, 91%, 60%, 0.5)
NamedtomatoFixed keyword listNo

Rate this Tool

0.0/5

Based on 0 user ratings.

Three notations, one color

HEX, RGB and HSL are different ways to write the same sRGB color. One is compact, one is literal, and one is easier to adjust by hand.

How HEX, RGB and HSL describe a color

A standard CSS color is built from three channels: red, green and blue. Each channel holds 256 possible values, from 0 to 255. Multiply the three channels and you get 16,777,216 combinations, which is why an 8-bit-per-channel color is treated as a full continuous palette.

HEX writes those three bytes in base 16, using two characters per channel. RGB writes the same three bytes in decimal. HSL rotates the model: it describes the color as a hue angle on a wheel, then how saturated that hue is and how light or dark it is. HSL does not add information that RGB lacks. It presents the same cube in a shape that is easier for a person to reason about.

QuestionHEXRGBHSL
Best forDesign tokens, CSS, compact configComputed values, canvas, image dataBuilding palettes by hand
Human readableLowMediumHigh for light and dark variants
Length in CSS4 or 7 charactersAbout 18 charactersAbout 20 characters
Easy to lightenNoNoYes, raise the L value

A practical workflow is to pick or sample a color in HEX, adjust it in HSL, and ship it in whichever format your codebase already uses. Mixing formats inside one stylesheet is allowed, but a consistent choice makes search and replace far safer.

Converting HEX to RGB

Split the six-digit code into three pairs. Each pair is a two-digit base-16 number, so the first character is multiplied by 16 and the second is added as-is. The letters a to f stand for 10 to 15.

channel = 16 × first digit + second digit

Take #3b82f6. The red pair 3b becomes 3 × 16 + 11 = 59. The green pair 82 becomes 8 × 16 + 2 = 130. The blue pair f6 becomes 15 × 16 + 6 = 246. The result is rgb(59, 130, 246).

3b red pair 82 green pair f6 blue pair 59 130 246

Shorthand HEX such as #38f repeats each character: it expands to #3388ff. That is a different color from #3b82f6, and the difference is visible when the two swatches sit side by side.

Converting RGB to HSL

HSL is derived from the same three channels. Normalize each channel to a 0-1 range, find the largest and smallest values, and work from there. The letter L below means lightness, not luminance; the two are related but not identical.

L = (max + min) ÷ 2 S = delta ÷ (1 − |2L − 1|), with delta = max − min H = 60 × sector value, then normalized to 0-360

For rgb(59, 130, 246) the normalized channels are 0.231, 0.510 and 0.965. The maximum is 0.965 and the minimum is 0.231, so delta is 0.733. Lightness is (0.965 + 0.231) ÷ 2 = 0.598, or about 60%. Saturation is 0.733 ÷ (1 − 0.196) = 0.912, or about 91%. Because blue is the largest channel, the hue uses the blue sector: (0.231 − 0.510) ÷ 0.733 + 4 = 3.620, and 3.620 × 60 = 217.2 degrees.

When delta is zero the color is a pure gray and hue is undefined, so the convention is to report hue as 0. Saturation is also 0 in that case. This is why #808080 comes back as hsl(0, 0%, 50%) rather than some arbitrary hue.

Converting HSL back to RGB

The reverse path builds a temporary chroma value from saturation and lightness, then places it in the correct 60-degree sector of the hue wheel.

C = (1 − |2L − 1|) × S X = C × (1 − |(H ÷ 60) mod 2 − 1|) m = L − C ÷ 2
Hue sectorChannel before adding mExample hue
0 to 60(C, X, 0)30
60 to 120(X, C, 0)90
120 to 180(0, C, X)150
180 to 240(0, X, C)217
240 to 300(X, 0, C)270
300 to 360(C, 0, X)330

Applying the formula to hsl(217, 91%, 60%) gives C = 0.728, X = 0.279 and m = 0.236. The hue falls in the 180-240 sector, so the channels become (0, 0.279, 0.728) before m is added and each is multiplied by 255. The rounded result is rgb(60, 131, 246). The original was rgb(59, 130, 246), so one unit per channel was lost to rounding.

Alpha channels: 8-digit HEX, rgba and hsla

CSS extends HEX with two extra digits for opacity. The order is #RRGGBBAA: alpha goes last. Android and some older tools write #AARRGGBB, so a color copied from one platform to the other can look completely wrong even though both codes are eight digits long.

Alpha is a fraction of 255, not a percentage. A value of 80 is 128 ÷ 255, which is about 50%. Full transparency is 00 and full opacity is ff. In rgba() and hsla() the fourth value is written as a decimal from 0 to 1.

Alpha HEXDecimalApproximate opacity
0000%
335120%
6610240%
8012850%
cc20480%
ff255100%

A transparent color is not a lighter color. The browser composites it over whatever is behind it, using result = alpha × foreground + (1 − alpha) × background per channel. The same 50% blue over white and over black produces two very different visible colors, which matters when a component can sit on more than one background.

Common color conversion mistakes

Most broken colors are not mathematical errors. They come from a value that is syntactically valid somewhere else but not in CSS, or from an alpha channel written in the wrong position.

MistakeWhat happensFix
Missing # in HEXThe browser cannot parse the valueUse #3b82f6, not 3b82f6
Four-digit HEX assumed to be RGB#38f6 is read as RGBA, not as a longer colorExpand shorthand first or write six digits
Percentage RGBrgb(50%, 20%, 10%) is valid; mixing percent and numbers is notUse one unit for all three channels
HSL without percent signshsl(217, 91, 60) is invalid in CSSWrite hsl(217, 91%, 60%)
Saturation in 0-1 rangeA near-black or near-gray color appearsMultiply by 100 for CSS
Alpha written firstARGB and RGBA produce different colorsKeep alpha as the last pair in CSS
Rounding every stepRound-trip drift of one or two units per channelKeep decimals until the final value

One more trap: CSS colors are interpreted in sRGB unless you use a wider-gamut function such as color(display-p3 ...) or oklch(). A HEX value copied from a wide-gamut design file is an sRGB approximation, so the browser and the design tool may disagree slightly.

Frequently Asked Questions

They store the same three channels. HEX writes each channel as a two-digit base-16 number, while RGB writes it as a decimal number from 0 to 255. #3b82f6 and rgb(59, 130, 246) are the same color.

HSL is a different coordinate system for the same sRGB cube. Hue selects an angle on the color wheel, saturation sets how far the color sits from gray, and lightness moves it toward black or white. It is easier to build a palette because only one value usually needs to change.

The output shows the three opaque channels. For transparency, append two HEX digits such as 80 for 50%, or use rgba() and hsla() with a fourth value between 0 and 1. Remember that CSS puts alpha last, not first.

HSL values are usually rounded to whole degrees and whole percentages so they stay readable. Rebuilding RGB from the rounded values can shift a channel by one or two units. Keep the original HEX if exact brand colors matter.

Only when each pair repeats the same character. #38f expands to #3388ff. It cannot represent #3b82f6 because the digits 3b, 82 and f6 are not repeated characters.

No. The conversion runs in JavaScript in your browser, so the value you type stays on your device and the page works without uploading anything.