Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p><span class="line1">Did someone say</span> <span class="line2" data-splitting>Variable Fonts?</span></p>
              
            
!

CSS

              
                @font-face {
  font-family: 'Roboto VF';
  src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/57225/Roboto-VF.woff2") format("woff2-variations");
  font-stretch: 75% 100%;
  font-style: oblique 0deg 12deg;
  font-weight: 100 900;
}
* {
  box-sizing: border-box;
}
:root {
  --text-weight: 500;
  --text-width: 100;
  --text-slant: 0;
}
body {
  font-family: "Roboto VF", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #262626;
  color: #fff;
  padding: 7vmin;
}
p {
  max-width: 45ch;
  text-align: center;
  font-size: 10vw;
}
.line1,
.line2 {
  display: block;
}
.line1 {
  font-size: 3vw;
  font-weight: 845;
  color: #ffffff2e;
}
.char {
  font-stretch: var(--text-width);
  font-style: oblique var(--text-slant);
  font-weight: var(--text-weight);
  font-variation-settings: "wght" var(--text-weight), "wdth" var(--text-width), "slnt" var(--text-slant);
  --glow-hue: 0;
  --glow-size: 10;
  text-shadow: 0 0 calc(var(--glow-size) * 1px) hsla(var(--glow-hue), 100%, 77%, 1);
}
              
            
!

JS

              
                console.log('hi.');
const WEIGHTS = {
  MIN: 100,
  MAX: 900,
};
const SLANT = {
  MIN: 1,
  MAX: 12,
}
const WIDTH = {
  MIN: 75,
  MAX: 100,
}
let offset = 0;
Splitting();

const letters = document.querySelectorAll('.char');
let numLetters = letters.length;

// letters.forEach((letter, index) => {
//   const indexNorm = index / letters.length;
//   const weight = map(indexNorm, 0, 1, WEIGHTS.MIN, WEIGHTS.MAX);
//   letter.style.setProperty('--text-weight', weight);
// });

window.requestAnimationFrame(loop);

function loop() {
  letters.forEach((letter, index) => {
    let offsetIndex = (index + offset) % numLetters;
    let indexNorm = offsetIndex / numLetters;
    indexNorm = mirror(indexNorm);
    const weight = map(indexNorm, 0, 1, WEIGHTS.MIN, WEIGHTS.MAX);
    const slant = map(indexNorm, 0, 1, SLANT.MIN, SLANT.MAX);
    const width = map(indexNorm, 0, 1, WIDTH.MIN, WIDTH.MAX);
    const hue = map(indexNorm, 0, 1, 0, 255);
    const glowSize = map(indexNorm, 0, 1, 0, 100);
    letter.style.setProperty('--text-weight', weight);
    letter.style.setProperty('--text-slant', slant);
    letter.style.setProperty('--text-width', width);
    letter.style.setProperty('--glow-hue', hue);
    letter.style.setProperty('--glow-size', glowSize);
  });
  offset += 0.125;
  requestAnimationFrame(loop);
}

// HELPERS
function map(value, min1, max1, min2, max2) {
  return (value - min1) * (max2 - min2) / (max1 - min1) + min2;
}
function mirror(val) {
  return Math.abs(val * 2 - 1) * -1 + 1;
}
              
            
!
999px

Console