CKTIS / CSS
hsl() — hue, saturation, and lightness
`hsl()` and alias `hsla()` describe an sRGB color by hue angle, saturation, lightness, and optional alpha.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
hsl( [ <hue> | none ] [ <percentage> | <number> | none ]{2} [ / [ <alpha-value> | none ] ]? )hsl() and alias hsla() describe an sRGB color by hue angle, saturation, lightness, and optional alpha.
The example paints hsl(120deg 100% 50% / 50%) over white and obtains 127,255,127; hsl(480deg 100% 50%) wraps its angle to green 0,255,0. hsl(0deg 0% 50%) and hsla(240deg 0% 50% / 100%) both produce 128,128,128 because hue is powerless at zero saturation. Mixed hsl(120deg 100%, 50%) returns false.
Grammar: hsl( [ <hue> | none ] [ <percentage> | <number> | none ]{2} [ / [ <alpha-value> | none ] ]? ).
Modern syntax uses spaces and a slash before alpha, while legacy syntax uses commas; they cannot be mixed. Hue angles wrap around a full turn, omitted alpha is 100%, and negative saturation is historically clamped to zero. The result resolves to sRGB; HSL lightness is not perceptually uniform, so equal numbers across hues do not guarantee equal visual brightness.
Examples
const sample=async color=>{const svg='<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4"><rect width="4" height="4" fill="white"/><rect width="4" height="4" fill="'+color+'"/></svg>';const image=new Image();image.src='data:image/svg+xml;charset=utf-8,'+encodeURIComponent(svg);await image.decode();const canvas=document.createElement('canvas');canvas.width=canvas.height=4;const context=canvas.getContext('2d');context.drawImage(image,0,0);return [...context.getImageData(2,2,1,1).data].slice(0,3).join(',')};
const alpha=await sample('hsl(120deg 100% 50% / 50%)');
const wrapped=await sample('hsl(480deg 100% 50%)');
const grayA=await sample('hsl(0deg 0% 50%)');
const grayB=await sample('hsla(240deg 0% 50% / 100%)');
const mixedSyntax=CSS.supports('color','hsl(120deg 100%, 50%)');
console.log('alpha-over-white='+alpha+'; wrapped='+wrapped+'; powerless-hues='+grayA+'/'+grayB+'; mixed-syntax='+mixedSyntax);Result
alpha-over-white=127,255,127; wrapped=0,255,0; powerless-hues=128,128,128/128,128,128; mixed-syntax=false
`hsl()` and alias `hsla()` describe an sRGB color by hue angle, saturation, lightness, and optional alpha.