HEX color converter

Convert a HEX color to RGB and HSL values.

Three-digit shorthand colors are expanded (for example, #3AF becomes #33AAFF). HSL values are rounded to two decimal places; RGB components remain exact integers.

Your inputs stay in your browser. Displayed results are rounded to a maximum of 12 significant digits.

Method and assumptions

Method version 1.0.0 · Updated

Convert a HEX color

Formula: Convert red, green and blue components to hue, saturation and lightness.

Three-digit shorthand colors are expanded (for example, #3AF becomes #33AAFF). HSL values are rounded to two decimal places; RGB components remain exact integers.

hex
Hexadecimal color

Accepts HEX #RGB and #RRGGBB notation, with or without #. Colors with an alpha channel are not supported. HSL is rounded to two decimal places.

Calculate with code

These short examples use the same inputs and core calculation as this tool. Adapt validation and formatting to your application.

JavaScript
const hex = "#3366CC";
const rgb = [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16));
console.log(rgb); // [51, 102, 204]
TypeScript
const hex = "#3366CC";
const rgb: number[] = [1,3,5].map(i => parseInt(hex.slice(i,i+2),16));
console.log(rgb); // [51,102,204]
Python
value = "3366CC"
print([int(value[i:i+2], 16) for i in (0,2,4)])  # [51, 102, 204]
Java
String hex = "3366CC";
int[] rgb = {Integer.parseInt(hex.substring(0,2),16), Integer.parseInt(hex.substring(2,4),16), Integer.parseInt(hex.substring(4,6),16)};
System.out.println(java.util.Arrays.toString(rgb));
C#
string hex = "3366CC";
int[] rgb = [Convert.ToInt32(hex[..2],16), Convert.ToInt32(hex[2..4],16), Convert.ToInt32(hex[4..6],16)];
Console.WriteLine(string.Join(", ", rgb));