Skip to content
Test versionSearch

Developer tools

Hex to RGB and HSL colour converter

Convert a hex colour code to RGB and HSL or enter RGB or HSL values to get the hex code, including alpha, with rounded 8-bit sRGB values.

How it worksFAQRelated tools

Content reviewed:

The example values can be changed. Press Calculate to update the result; you can download it as TXT or CSV and collect scenarios in this tab. Nothing is saved or sent automatically.

Strict hex3/4/6/8 digits. Rounded 8-bit sRGB, no print/ICC or physical pigment matching. Press Calculate to update the result; you can download it as TXT or CSV. Own formulas, no external library, font or image. Swatch preview only; codes remain in the report. Hex and numeric modes only; no general CSS parser, names, HWB, Lab/LCH, OKLab/OKLCH or CMYK. Achromatic hue 0 convention. CSS strings retain six decimals regardless of numeric report precision. JSON and HTML contain inputs. Numeric values are original calculation values; existing report precision is retained. Optional live calculation is initially off. No automatic storage or transmission. Additional own CSS/SVG/PNG files show calculated CSS code or 240×60 result swatches over white. No gradient geometry, embedded font or external image.

Decimal results are approximate. Inputs stay in this browser tab.

How it works

Own bounded colour formulas: basic sRGB/HSL, alpha mixture, deterministic palettes and three-stop CSS. Own structured JSON/result-row TXT/printable HTML files retain original inputs, options and result values. Strict hex3/4/6/8 digits. Rounded 8-bit sRGB, no print/ICC or physical pigment matching. Press Calculate to update the result; you can download it as TXT or CSV. Own formulas, no external library, font or image. Swatch preview only; codes remain in the report. Hex and numeric modes only; no general CSS parser, names, HWB, Lab/LCH, OKLab/OKLCH or CMYK. Achromatic hue 0 convention. CSS strings retain six decimals regardless of numeric report precision. JSON and HTML contain inputs. Numeric values are original calculation values; existing report precision is retained. Optional live calculation is initially off. No automatic storage or transmission. Additional own CSS/SVG/PNG files show calculated CSS code or 240×60 result swatches over white. No gradient geometry, embedded font or external image.

Worked example

With these example values the calculator gives the result below. You can change any value in the form above.

Inputs

Input format
Hex
Hex colour
#2979FF
Alpha for numeric modes (ignored for hex)
1
Numeric report: 0–12 places
6

Result

RGB hex
#2979FF
RGBA hex
#2979FFFF
RGB CSS
rgba(41, 121, 255, 1)
HSL CSS
hsla(217.570093, 100%, 58.039216%, 1)
Red
41
Green
121
Blue
255
Alpha
1
Hue: degrees
217.570093458
Saturation: percent
100
Lightness: percent
58.0392156863

Frequently asked questions

How do I convert a hex colour to RGB and HSL?

Choose hex mode and enter the colour. For #2979FF the tool gives rgba(41, 121, 255, 1) and hsla(217.570093, 100%, 58.039216%, 1).

Which hex formats does the converter accept?

Strict hex with 3, 4, 6 or 8 digits. There is also a numeric mode for RGB and HSL values.

Does the colour converter support alpha?

Yes. You can enter an alpha value, and the result includes a hex alpha form such as #2979FFFF for alpha 1.

Which colour models are not supported?

There is no general CSS parser, colour names, HWB, Lab, LCH, OKLab, OKLCH or CMYK, and no print, ICC or pigment matching.

What happens to hue for grey colours?

For achromatic colours, a hue of 0 is used as a convention.

What can I download from the colour converter?

You can download JSON, printable HTML, a result row TXT, colour CSS, and a swatch as SVG or PNG. Swatches are 240×60, over white, and do not show gradient geometry.