Typography · 01 of 33

Variable Font Axes

Drag the sliders to change weight, width and slant live using font-variation-settings on a variable font. One font file, every style in between — no extra requests.

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<!-- Requires a variable font, e.g. Roboto Flex from Google Fonts:
<link href="https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,slnt,wdth,wght@8..144,-10..0,25..151,100..1000&display=swap" rel="stylesheet"> -->

<label>Weight <input type="range" id="weight" min="100" max="1000" value="400"></label>
<p class="variable-headline" id="variableHeadline">Morph Me</p>

CSS

.variable-headline {
  font-family: 'Roboto Flex', sans-serif;
  font-size: 3.5rem;
  font-variation-settings: 'wght' 400, 'wdth' 100, 'slnt' 0;
}

JavaScript

var slider = document.getElementById('weight');
var headline = document.getElementById('variableHeadline');

slider.addEventListener('input', function () {
  headline.style.fontVariationSettings =
    "'wght' " + slider.value + ", 'wdth' 100, 'slnt' 0";
});