HEX to RGB

Convert a hex color code into RGB, RGBA, and HSL values, with a live swatch so you can see the color. It supports 3, 6, and 8 digit hex, including alpha.

RGBrgb(59, 130, 246)
RGBArgba(59, 130, 246, 1)
HSLhsl(217, 91%, 60%)

About HEX to RGB

This tool provides a high-precision conversion from a hexadecimal color code to its equivalent representations in the RGB, RGBA, and HSL color models. Hexadecimal color codes, formally known as hex triplets[12], are a cornerstone of web design[13] and digital imaging[4], providing a compact, text-based method for specifying colors within documents like HTML and CSS. The converter parses the hex input and calculates the corresponding integer values for the Red, Green, and Blue channels, as well as the cylindrical-coordinate values for Hue, Saturation, and Lightness, offering immediate utility for developers, designers, and digital artists who need to translate colors between different systems and specifications.

The hexadecimal color syntax is a direct representation of 24-bit color, where each color is defined by three 8-bit components. The format is typically `#RRGGBB`, where RR, GG, and BB are two-digit hexadecimal[7] numbers representing the intensity of the Red, Green, and Blue channels, respectively. Each hexadecimal pair can represent a decimal value from 0 (00 in hex) to 255 (FF in hex). This allows for 256 possible values per channel, resulting in a total of 256^3 or 16,777,216 unique colors. A common shorthand syntax also exists, using three digits like `#RGB`, which is expanded by duplicating each digit. For example, `#F0C` is equivalent to `#FF00CC`.

The RGB color model[9] is an additive color[1] system where red, green, and blue light are combined in various ways to reproduce a broad array of colors. The output of this tool conforms to the sRGB[10] color space, which is the standard defined by IEC 61966-2-1 for monitors, printers, and the Internet. The conversion from a hex triplet is a straightforward base conversion. For each RR, GG, or BB pair, the decimal value is calculated as (first digit * 16) + (second digit), where the hexadecimal digits A to F correspond to decimal values 10 to 15. The resulting `rgb(R, G, B)` values are therefore integers from 0 to 255.

The RGBA color model extends RGB by adding an alpha channel[2], which specifies the transparency[11] or opacity of a color. This was formally specified in the World Wide Web Consortium's CSS Color Module Level 3[14] recommendation. The alpha value is represented as a decimal number between 0.0 (fully transparent) and 1.0 (fully opaque). While some systems use an 8-digit hex format (#RRGGBBAA), as defined in CSS Color Module Level 4[15], the `rgba(R, G, B, A)` functional notation is more common and is the primary output of this tool for colors with an alpha component.

The HSL color model[8] represents colors using three different parameters: Hue, Saturation, and Lightness. This model is often considered more intuitive for human interaction, as it aligns better with how people perceive color. Hue is the type of color, represented as an angle from 0 to 360 degrees on a color wheel[3] (e.g., 0 is red, 120 is green, 240 is blue). Saturation is the intensity or purity of the color, expressed as a percentage from 0% (a shade of gray) to 100% (fully saturated). Lightness is the perceived brightness, also a percentage, from 0% (black) to 100% (white). The mathematical conversion from the sRGB space to HSL is non-linear and involves several steps to correctly map the RGB cube onto the HSL cylinder.

How to Use

  1. Enter a 3-digit or 6-digit hexadecimal color code into the designated input field.
  2. The hash symbol (#) prefix is optional and will be handled automatically.
  3. The tool instantly converts the input and displays the corresponding RGB, RGBA, and HSL values.
  4. If you require transparency, use the alpha slider to adjust the opacity level from 0% to 100%.
  5. The RGBA value will update in real-time as you adjust the alpha channel.
  6. Click the copy icon next to any value to copy it directly to your clipboard.

Frequently Asked Questions

What is the difference between RGB and sRGB?

RGB is a generic additive color[1] model, while sRGB[10] is a specific, standardized RGB color space. sRGB defines a precise gamut[6] (the range of colors that can be represented) and a specific gamma correction[5] curve. It was standardized as IEC 61966-2-1 and is the default color space for the web to ensure colors look consistent across different devices.

How is a 3-digit hex code converted to a 6-digit one?

A 3-digit hex code is a shorthand notation where each digit is duplicated to form a 6-digit code. For example, the code `#F7C` is expanded to `#FF77CC`. This means the red channel is `FF`, the green is `77`, and the blue is `CC`.

How is the alpha channel represented in hexadecimal?

The alpha channel can be represented using an 8-digit hex code in the format `#RRGGBBAA`, as specified in CSS Color Module Level 4[15]. The final pair of digits, AA, represents the alpha channel, where `00` is fully transparent and `FF` is fully opaque. This tool converts to the more common `rgba()` notation.

What is the mathematical formula for converting a hex pair to a decimal value?

To convert a two-digit hexadecimal number like `D9` to decimal, you use base-16 arithmetic. The formula is `(d1 * 16^1) + (d0 * 16^0)`, where d1 is the first digit and d0 is the second. For `D9`, where D is 13, the calculation is `(13 * 16) + (9 * 1)`, which equals 217.

Why would I use HSL instead of RGB?

HSL[8] (Hue, Saturation, Lightness) is often more intuitive for humans. To make a color lighter, you just increase the Lightness value. To make it more or less vibrant, you adjust Saturation. In RGB, you would need to adjust all three R, G, and B values in a non-obvious way to achieve the same effect.

Are all colors representable in both RGB and HSL?

Yes, within a defined color space like sRGB, the transformation between RGB and HSL is bijective. This means for every unique RGB color, there is a unique HSL equivalent, and vice versa. The only exceptions are achromatic colors (grays), where the Hue is undefined and Saturation is zero.

What does gamma correction mean for sRGB?

Gamma correction[5] in sRGB is a nonlinear function applied to the color values to compensate for the nonlinear response of the human eye to light intensity. Our eyes perceive changes in dark tones more sensitively than in bright tones. Gamma encoding ensures that the steps in brightness (e.g., from 50 to 60) appear visually uniform across the entire brightness range.

What is the range of values for HSL?

In the HSL model, Hue is an angle on the color wheel[3], with a range from 0 to 360 degrees. Saturation and Lightness are both percentages, with ranges from 0% to 100%.

Sources (15)
  1. Wikipedia: Additive color
  2. Wikipedia: Alpha compositing
  3. Wikipedia: Color wheel
  4. Wikipedia: Digital imaging
  5. Wikipedia: Gamma correction
  6. Wikipedia: Gamut
  7. Wikipedia: Hexadecimal
  8. Wikipedia: HSL and HSV
  9. Wikipedia: RGB color model
  10. Wikipedia: sRGB color space
  11. Wikipedia: Transparency (graphic)
  12. Wikipedia: Web colors#Hex triplet
  13. Wikipedia: Web design
  14. W3C: CSS Color Module Level 3
  15. W3C: CSS Color Module Level 4

About Matt George

I'm Matt George, a software engineer in the startup space. I run my own shop building software for early-stage founders, and I love making free tools and experiences that people actually use. Enjoy using HEX to RGB!

More Free Tools