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 Word swap. 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 rotate only that word through a short list of alternatives. Rotate it through bolder, faster and fun, then back to alive. Every 2.2 seconds the current word slides up and fades out over 280ms, then the next word slides up from below and fades in over 420ms with the easing cubic-bezier(0.22, 1, 0.36, 1). Show the rotating word in my accent colour. Clip it with overflow hidden so it appears from behind an invisible edge, and animate the width of its container so the surrounding words 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-swap 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 Word swap with your settings. It assumes the headline has the class hero-title.
<!-- HTML -->
<!-- Word swap animation from https://smthngfun.com/a/word-swap -->
<h1 class="hero-title">Make your landing page feel <span class="swap"><span>alive</span></span></h1>
/* CSS */
.hero-title .swap {
display: inline-block;
overflow: hidden;
vertical-align: bottom;
white-space: nowrap;
padding-bottom: 0.14em;
margin-bottom: -0.14em;
transition: width 450ms cubic-bezier(0.22, 1, 0.36, 1);
}
.hero-title .swap > span {
display: inline-block;
color: var(--accent, currentColor);
}
// JavaScript
const slot = document.querySelector('.hero-title .swap');
const word = slot.firstElementChild;
const words = ['alive', 'bolder', 'faster', 'fun'];
let i = 0;
if (!matchMedia('(prefers-reduced-motion: reduce)').matches) {
setInterval(async function () {
await word.animate(
[{ transform: 'translateY(0)', opacity: 1 }, { transform: 'translateY(-70%)', opacity: 0 }],
{ duration: 280, easing: 'ease-in', fill: 'forwards' }
).finished;
i = (i + 1) % words.length;
slot.style.width = slot.offsetWidth + 'px';
word.textContent = words[i];
slot.offsetWidth; // commit the old width before changing it
slot.style.width = word.offsetWidth + 'px';
word.animate(
[{ transform: 'translateY(70%)', opacity: 0 }, { transform: 'translateY(0)', opacity: 1 }],
{ duration: 420, easing: 'cubic-bezier(0.22, 1, 0.36, 1)', fill: 'forwards' }
);
}, 2200);
}