HSL Colour Picker Sliders
Three sliders for hue, saturation and lightness whose tracks show the colours you will get, with hex, RGB and contrast.
AI prompt
Clean UI mockup of a colour picker panel with a large rounded swatch on top, three horizontal sliders labelled Hue, Saturation and Lightness whose tracks show a rainbow, a grey to colour ramp and a dark to light ramp with round handles, beside it hex and RGB values and two small badges White text 4.8 Pass and Black text 4.4 Fail, light theme, flat modern style. Negative: heavy shadows, clutter, text errors, device frames. Reduced motion: static design.About this pattern
Definition
HSL describes a colour the way people think about it: which hue, how vivid, how light. Sliders whose tracks show the resulting colour make adjusting predictable. Showing hex, RGB and the contrast ratio against white and black lets designers pick a colour and know whether text on it is readable.
When to use it
- Paint each slider track with a gradient that shows what moving that slider does while the other two stay fixed.
- Convert HSL to RGB and hex; show all three.
- Compute contrast with relative luminance and show the ratio for white and black text.
- Mark ratios below 4.5 as failing for normal text.
What the controls do
- Hue, saturation and lightness sliders and a result card.
Motion & timing
- Updates are immediate.
- Reduced motion: nothing animates.
Tips & variations
- Label the sliders and expose current values as text.
- Do not rely on colour alone to show pass or fail.
Code of this live preview
<div class="bx"><div class="sw2" id="sw2"><b id="hx"></b><span id="cr"></span></div><label class="rw">Hue <b id="hv"></b><input class="sl" id="h" type="range" min="0" max="360" value="220"></label><label class="rw">Saturation <b id="sv"></b><input class="sl" id="s" type="range" min="0" max="100" value="70"></label><label class="rw">Lightness <b id="lv"></b><input class="sl" id="l" type="range" min="0" max="100" value="50"></label></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sw2{height:72px;border-radius:12px;display:flex;flex-direction:column;justify-content:center;gap:2px;padding:0 14px;border:1px solid rgba(0,0,0,.1)}.sw2 b{font:700 18px ui-monospace,Menlo,monospace}.sw2 span{font-size:11.5px}.sl{-webkit-appearance:none;appearance:none;height:12px;border-radius:6px;background:var(--tr);outline:none}.sl::-webkit-slider-thumb{-webkit-appearance:none;width:18px;height:18px;border-radius:50%;background:#fff;border:2px solid #171717}.sl::-moz-range-thumb{width:14px;height:14px;border-radius:50%;background:#fff;border:2px solid #171717}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const g=id=>document.getElementById(id);
function rgb(h,s,l){s/=100;l/=100;const k=n=>(n+h/30)%12,a=s*Math.min(l,1-l),f=n=>l-a*Math.max(-1,Math.min(k(n)-3,Math.min(9-k(n),1)));return[0,8,4].map(n=>Math.round(f(n)*255));}
function lum(c){return c.map(v=>{v/=255;return v<=.03928?v/12.92:Math.pow((v+.055)/1.055,2.4);}).reduce((a,v,i)=>a+v*[.2126,.7152,.0722][i],0);}
function up(){const h=+g('h').value,s=+g('s').value,l=+g('l').value,c=rgb(h,s,l),hex='#'+c.map(v=>v.toString(16).padStart(2,'0')).join(''),L=lum(c),cw=(1.05)/(L+.05),cb=(L+.05)/.05;
g('sw2').style.background=hex;g('sw2').style.color=cw>=cb?'#fff':'#000';g('hx').textContent=hex.toUpperCase();g('cr').textContent='rgb('+c.join(', ')+') \u00b7 White text '+cw.toFixed(1)+(cw>=4.5?' Pass':' Fail')+' \u00b7 Black text '+cb.toFixed(1)+(cb>=4.5?' Pass':' Fail');
g('hv').textContent=h+'\u00b0';g('sv').textContent=s+'%';g('lv').textContent=l+'%';
g('h').style.setProperty('--tr','linear-gradient(90deg,'+[0,60,120,180,240,300,360].map(x=>'hsl('+x+','+s+'%,'+l+'%)').join(',')+')');g('s').style.setProperty('--tr','linear-gradient(90deg,hsl('+h+',0%,'+l+'%),hsl('+h+',100%,'+l+'%))');g('l').style.setProperty('--tr','linear-gradient(90deg,#000,hsl('+h+','+s+'%,50%),#fff)');}
['h','s','l'].forEach(k=>g(k).addEventListener('input',up));up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>HSL Colour Picker Sliders — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sw2{height:72px;border-radius:12px;display:flex;flex-direction:column;justify-content:center;gap:2px;padding:0 14px;border:1px solid rgba(0,0,0,.1)}.sw2 b{font:700 18px ui-monospace,Menlo,monospace}.sw2 span{font-size:11.5px}.sl{-webkit-appearance:none;appearance:none;height:12px;border-radius:6px;background:var(--tr);outline:none}.sl::-webkit-slider-thumb{-webkit-appearance:none;width:18px;height:18px;border-radius:50%;background:#fff;border:2px solid #171717}.sl::-moz-range-thumb{width:14px;height:14px;border-radius:50%;background:#fff;border:2px solid #171717}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="sw2" id="sw2"><b id="hx"></b><span id="cr"></span></div><label class="rw">Hue <b id="hv"></b><input class="sl" id="h" type="range" min="0" max="360" value="220"></label><label class="rw">Saturation <b id="sv"></b><input class="sl" id="s" type="range" min="0" max="100" value="70"></label><label class="rw">Lightness <b id="lv"></b><input class="sl" id="l" type="range" min="0" max="100" value="50"></label></div>
</div>
<script>
const g=id=>document.getElementById(id);
function rgb(h,s,l){s/=100;l/=100;const k=n=>(n+h/30)%12,a=s*Math.min(l,1-l),f=n=>l-a*Math.max(-1,Math.min(k(n)-3,Math.min(9-k(n),1)));return[0,8,4].map(n=>Math.round(f(n)*255));}
function lum(c){return c.map(v=>{v/=255;return v<=.03928?v/12.92:Math.pow((v+.055)/1.055,2.4);}).reduce((a,v,i)=>a+v*[.2126,.7152,.0722][i],0);}
function up(){const h=+g('h').value,s=+g('s').value,l=+g('l').value,c=rgb(h,s,l),hex='#'+c.map(v=>v.toString(16).padStart(2,'0')).join(''),L=lum(c),cw=(1.05)/(L+.05),cb=(L+.05)/.05;
g('sw2').style.background=hex;g('sw2').style.color=cw>=cb?'#fff':'#000';g('hx').textContent=hex.toUpperCase();g('cr').textContent='rgb('+c.join(', ')+') \u00b7 White text '+cw.toFixed(1)+(cw>=4.5?' Pass':' Fail')+' \u00b7 Black text '+cb.toFixed(1)+(cb>=4.5?' Pass':' Fail');
g('hv').textContent=h+'\u00b0';g('sv').textContent=s+'%';g('lv').textContent=l+'%';
g('h').style.setProperty('--tr','linear-gradient(90deg,'+[0,60,120,180,240,300,360].map(x=>'hsl('+x+','+s+'%,'+l+'%)').join(',')+')');g('s').style.setProperty('--tr','linear-gradient(90deg,hsl('+h+',0%,'+l+'%),hsl('+h+',100%,'+l+'%))');g('l').style.setProperty('--tr','linear-gradient(90deg,#000,hsl('+h+','+s+'%,50%),#fff)');}
['h','s','l'].forEach(k=>g(k).addEventListener('input',up));up();
</script>
</body></html>