Make your landing page feel alive

Click any word to animate that one

The prompt

Written from your settings. Paste it into your AI tool.

Animate one word in the main headline of my landing page with an effect called Letter roll. In my example the headline reads "Make your landing page feel alive" and the animated word is "alive". Apply it to the word I point out in my own headline, and ask me which one if I have not said. Keep the rest of the headline still and swap only that word for the next one in a list, one letter at a time. Rotate it through bolder, faster and fun, then back to alive. Put every letter in its own small box with overflow clipped, so each letter has a private slot to roll through. Every 2 seconds the letters of the current word slide up out of their slots by 115 percent of their height while the letters of the next word slide up into place from 115 percent below, both at the same time. Each letter takes 320ms with the easing cubic-bezier(0.22, 1, 0.36, 1), and each one starts 30ms after the letter before it, so the change ripples from left to right. Tint the arriving letters with my accent colours, alternating between two of them from letter to letter, and fade each one to the normal text colour shortly after it lands. Stack the outgoing and incoming words in the same grid cell so they overlap during the swap, and animate the width of that cell so the words after it glide to their new position instead of jumping. Loop through the list forever. Keep my existing font, colours and layout exactly as they are. Screen readers and search engines must still read the headline as one normal sentence, so put the full text in an aria-label on the heading and mark any decorative spans as aria-hidden. If the visitor has prefers-reduced-motion turned on, show the finished headline straight away with no animation. Make sure nothing shifts the layout while it plays. Use plain CSS and a little vanilla JavaScript, unless my project already has an animation library, in which case use that. A live demo with reference code for these exact settings is at https://smthngfun.com/a/word-roll and you can use that code as your starting point, adapted to my codebase and styling. If I am happy to credit the source, add a small "Animation by smthngfun" link to https://smthngfun.com in the footer of the page. Ask me before adding it.

Reference code

A working version of Letter roll with your settings. It assumes the headline has the class hero-title.

<!-- HTML -->
<!-- Letter roll animation from https://smthngfun.com/a/word-roll -->
<h1 class="hero-title">Make your landing page feel <span class="roll">alive</span></h1>

/* CSS */
.hero-title .roll {
  display: inline-grid;
  vertical-align: baseline;
  white-space: nowrap;
  overflow: hidden;
  transition: width 400ms cubic-bezier(0.22, 1, 0.36, 1);
}
.hero-title .roll-word {
  grid-area: 1 / 1;
  display: inline-flex;
  justify-self: start;
}
.hero-title .roll-char {
  display: inline-block;
  overflow: clip;
  padding: 0.06em 0 0.14em;
  margin: -0.06em 0 -0.14em;
}
.hero-title .roll-char > span { display: inline-block; }

// JavaScript
const roll = document.querySelector('.hero-title .roll');
const words = ['alive', 'bolder', 'faster', 'fun'];
const flash = ['#7458c9', '#c3b3f3']; // the two tints for arriving letters, use your accent colours
const ease = 'cubic-bezier(0.22, 1, 0.36, 1)';

function build(word) {
  const layer = document.createElement('span');
  layer.className = 'roll-word';
  Array.from(word).forEach(function (ch) {
    const box = document.createElement('span');
    box.className = 'roll-char';
    const letter = document.createElement('span');
    letter.textContent = ch;
    box.append(letter);
    layer.append(box);
  });
  return layer;
}

let current = build(roll.textContent);
roll.textContent = '';
roll.append(current);
let i = 0;

if (!matchMedia('(prefers-reduced-motion: reduce)').matches) {
  setInterval(function () {
    i = (i + 1) % words.length;
    const leaving = current;
    const settled = getComputedStyle(roll).color;
    current = build(words[i]);
    roll.style.width = roll.offsetWidth + 'px';
    roll.append(current);
    roll.offsetWidth; // commit the old width before changing it
    roll.style.width = current.offsetWidth + 'px';

    Array.from(leaving.children).forEach(function (box, n) {
      box.firstChild.animate(
        [{ transform: 'translateY(0)' }, { transform: 'translateY(-115%)' }],
        { duration: 320, delay: n * 30, easing: ease, fill: 'forwards' }
      );
    });
    Array.from(current.children).forEach(function (box, n) {
      const tint = flash[n % flash.length];
      box.firstChild.animate(
        [{ transform: 'translateY(115%)' }, { transform: 'translateY(0)' }],
        { duration: 320, delay: n * 30, easing: ease, fill: 'backwards' }
      );
      box.firstChild.animate(
        [{ color: tint }, { color: tint, offset: 0.5 }, { color: settled }],
        { duration: 320 * 2.5, delay: n * 30, fill: 'backwards' }
      );
    });
    setTimeout(function () { leaving.remove(); }, 320 + leaving.children.length * 30 + 50);
  }, 2000);
}