cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              
<div>
  <label for="h">Hue<span>(0 - 360)</span></label>
  <input type="number" id="h" value="0" />
</div>
<div>
  <label for="h">Saturation<span>(0 - 100%)</span></label>
  <input type="number" id="s" value="50" />
</div>
<div>
  <label for="h">Lightness<span>(0 - 100%)</span></label>
  <input type="number" id="l" value="50" />
</div>

<footer>hsl(<span id="hdisplay"></span>, <span id="sdisplay"></span>, <span id="ldisplay"></span>)
            
          
!
            
              :root {
  --h: 0;
  --s: 50;
  --l: 50;
}

body {
  background: hsl(var(--h), calc(var(--s) * 1%), calc(var(--l) * 1%));
}

#hdisplay::after {
  counter-reset: hcount var(--h);
  content: counter(hcount);
}
#sdisplay::after {
  counter-reset: scount var(--s);
  content: counter(scount) '%';
}
#ldisplay::after {
  counter-reset: lcount var(--l);
  content: counter(lcount) '%';
}




/* Structure */
body {
  min-height: 100vh;
  overflow: hidden;
  
  display: flex;
  justify-content: center;
  align-items: flex-end;
  font-family: -apple-system, system-ui;
  font-size: 82.5%;
}

div {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  background: hsla(0, 0%, 0%, .6);
  color: hsl(0, 100%, 100%);
  padding: 1rem .5rem 3rem;
}
input {
  height: 3rem;
  font-size: 2rem;
  width: 99%;
  text-align: center;
  position: relative;
  display: block;
  
  appearance: none;
  border-radius: 0;
  border: 0;
  background: transparent;
  color: hsl(0, 100%, 100%);
  border-bottom: .1rem solid currentColor; 
}
label {
  display: block;
  text-align: center;
}
label span {
  display: block;
  padding: .25rem 0;
}

footer {
  position: absolute;
  color: hsl(0, 0%, 100%);
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 1rem;
}
            
          
!
            
              //match the initial values of the CSS Variables
var hsl = {
  h: 0,
  s: 50,
  l: 50
};

var hinput = document.getElementById('h');
var sinput = document.getElementById('s');
var linput = document.getElementById('l');

Array.from(document.querySelectorAll('input')).forEach(function(item) {
  item.addEventListener('input', onNewValue);
});

function onNewValue(element) {
  if (element.tagName !== 'INPUT') {
    element = element.currentTarget;
  }
  
  //input for h, s, or l?
  var which = element.id;
  //current number value
  hsl[which] = element.value;
  //update CSS Variable value, which in turn updates the background color as well as the displayed hsl value at the bottom of the screen
  document.documentElement.style.setProperty('--' + which, hsl[which]);
}



// When focused on Body
// Q/A to +/- Hue
// W/S to +/- Saturation
// E/D to +/- Lightness
document.body.addEventListener('keydown', function(e) {
  if (e.key === 'Q' || e.key === 'q') {
    hsl.h++;
    updateValue(hinput, hsl.h);
  } else if (e.key === 'A' || e.key === 'a') {
    hsl.h--;
    updateValue(hinput, hsl.h);
  } else if (e.key === 'W' || e.key === 'w') {
    hsl.s++;
    updateValue(sinput, hsl.s);
  } else if (e.key === 'S' || e.key === 's') {
    hsl.s--;
    updateValue(sinput, hsl.s);
  } else if (e.key === 'E' || e.key === 'e') {
    hsl.l++;
    updateValue(linput, hsl.l);
  } else if (e.key === 'D' || e.key === 'd') {
    hsl.l--;
    updateValue(linput, hsl.l);
  }
});
function updateValue(el, val) {
  el.value = val;
  onNewValue(el);
}
            
          
!
999px
Loading ..................

Console