<div class="container range__opsz">


  <div class="paragraph">

    <div class="text">Optical Size</div>

  </div>
  <div id='demo-controls' class="controls">
    <div class="value-tag"></div>
    <div class="opsz-toggle">
      <input type="radio" id="opsz-toggle" name="opsz-toggle" value="auto" checked>Auto
      <input type="radio" id="opsz-toggle" name="opsz-toggle" value="none">None
      <label for="opsz-toggle">Optical Size</label>


  </div>

</div>
/* Amstelvar Variable Font */
@font-face {
  font-family: "Amstelvar VF";
  src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/57225/Amstelvar-Roman-VF_copy.woff2")
    format("woff2 supports variations"), url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/57225/Amstelvar-Roman-VF_copy.woff2")
    format("woff2-variations");
  font-display: swap;
  font-weight: 100 900;
  font-stretch: 75% 125%;
}
.range__opsz {
  --text-vf-wght: 400;  
  --text-vf-wdth: 95;
  --opsz-toggle: 'none';
  --font-size: 5;
  --value-tag: "'font-optical-sizing'";
  --low-value: 1;
  --current-value: var(--font-size);
  --high-value: 8;

  .paragraph {
    background-color: #ffffff;
    margin-left: auto;
    margin-right: auto;
    max-width: 95vw;
    width: 45em;
  }

  .paragraph .text {
    font-family: "Amstelvar VF", serif;
    font-size: calc( var(--font-size) * 1rem);
    font-weight: var(--text-vf-wght);
    font-stretch: calc( var(--text-vf-wdth) * 1% );
    font-optical-sizing: var(--opsz-toggle);
    line-height: 7rem;
    margin: 0 auto 0 auto;
    text-align: center;
  }


  /* Control buttons */
  .controls {
    display: grid;
    grid-template-columns: min-content 1fr min-content;
    margin: 2em auto;
    text-align: center;
    width: 20rem;

    h3 {
      display: inline;
      font-weight: normal;
      font-family: monospace;
    }
    label {
      float: left;
      height: 1px;
      text-indent: -999em;
      visibility: hidden;
    }
    .slider {
      grid-column: 2/3;
      input {
        width: 100%;
      }
    }
    .value-tag {
      grid-column: span 3;
      font-weight: bold;
      margin-bottom: 0.5rem;
      text-align: left;
      &::before {
        counter-reset: tag var(--value-tag);
        content: var(--value-tag);
        font-family: sans-serif;
      }
   }
    .low-value {
      grid-column: 1/2;
      text-align: left;
      width: 2.5rem;
      &::before {
        counter-reset: tag var(--low-value);
        content: counter(tag);
        font-family: sans-serif;
      }
    }
    .high-value{
      grid-column: 4/5;
      text-align: right;
      width: 2.5rem;
    &::before {
       counter-reset: tag var(--high-value);
       content: counter(tag);
       font-family: sans-serif;
      }
    }
    .current-value {
      grid-column: 2/3;
      &::before {
        counter-reset: tag var(--current-value);
        border: solid 1px black;
        content: counter(tag);
        display: inline-block;
        font-family: sans-serif;
        min-width: 3rem;
        margin: 0 auto;
        padding: 0.25rem 0.25rem 0.2rem 0.25rem;
      }
    }
    .opsz-toggle {
      font-family: sans-serif;
      grid-column: 2/3;
      margin-top: 1rem;
    }
  }
}

View Compiled
// get the inputs
const inputs = [].slice.call(document.querySelectorAll('.range__opsz .controls input'));

// listen for changes
inputs.forEach(input => input.addEventListener('change', handleUpdate));



function handleUpdate(e) {      document.querySelector('.range__opsz').style.setProperty(`--${this.id}`, this.value);
}


Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.