Color Converters
Comprehensive tools for converting between HEX, RGB, HSL, and their alpha-channel variants.
Overview
The color converter utilities provide tools for converting between various color formats including HEX, RGB, HSL, and their alpha-channel variants (HEX8, RGBA, HSLA).
HSL and RGB Conversion
convertHslToRgb
Converts HSL values to an RGB format string.
function convertHslToRgb(h: number, s: number, l: number): RGBplayground.ts
convertRgbToHsl
Converts RGB values to an HSL format string.
function convertRgbToHsl(r: number, g: number, b: number): HSLplayground.ts
HSL and HEX Conversion
convertHslToHex
Converts HSL values to a Hex6 format string.
function convertHslToHex(h: number, s: number, l: number): Hex6playground.ts
convertHexToHsl
Converts a Hex string to an HSL format string.
function convertHexToHsl(hex: Hex6 | Hex): HSLplayground.ts
RGB and HEX Conversion
convertRgbToHex
Converts RGB values to a Hex6 format string.
function convertRgbToHex(r: number, g: number, b: number): Hex6playground.ts
convertHexToRgb
Converts a Hex string to an RGB format string.
function convertHexToRgb(hex: Hex6 | Hex): RGBplayground.ts
Alpha-Channel Conversions
convertRgbToRgba
function convertRgbToRgba(r: number, g: number, b: number, a?: number): RGBAconvertRgbaToHex8
function convertRgbaToHex8(r: number, g: number, b: number, a?: number): Hex8convertHex8ToRgba
function convertHex8ToRgba(hex8: Hex8): RGBAconvertHslaToRgba
function convertHslaToRgba(h: number, s: number, l: number, a?: number): RGBAconvertRgbaToHsla
function convertRgbaToHsla(r: number, g: number, b: number, a?: number): HSLAconvertHslaToHex8
function convertHslaToHex8(h: number, s: number, l: number, a?: number): Hex8convertHex8ToHsla
function convertHex8ToHsla(hex8: Hex8): HSLAHelper Utilities
percentToHex
Converts a percentage value ($0 \dots 100$) to a 2-digit hex string.
function percentToHex(percent: Percent): stringapplyOpacityToHex
Applies an opacity value to a hex color string, returning a Hex8 format.
function applyOpacityToHex(color: Hex, opacity: Percent | string): Hex8playground.ts
Type Definitions
type Hex = `#${string}`;
type Hex6 = Branded<`#${string}`, 'Hex6'>;
type Hex8 = Branded<`#${string}`, 'Hex8'>;
type RGB = `rgb(${number}, ${number}, ${number})`;
type RGBA = `rgba(${number}, ${number}, ${number}, ${number})`;
type HSL = `hsl(${number}, ${number}%, ${number}%)`;
type HSLA = `hsla(${number}, ${number}%, ${number}%, ${number})`;Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
