Make your landing page feel alive
Click the headline to replay
The prompt
Written from your settings. Paste it into your AI tool.
Animate the main headline in the hero section of my landing page with an effect called Decode. Start with every letter of the headline replaced by random characters picked from a set of capital letters, digits and symbols. Swap the random characters every 50ms. Lock the letters into their real value one at a time from left to right, starting after 350ms with 35ms between letters. Show letters that are still scrambling in my accent colour and switch them to the normal text colour once they lock. Give each letter a fixed width equal to its real width so the headline does not jitter while it scrambles. 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/decode 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 Decode with your settings. It assumes the headline has the class hero-title.
<!-- HTML -->
<!-- Decode animation from https://smthngfun.com/a/decode -->
<h1 class="hero-title">Make your landing page feel alive</h1>
/* CSS */
.hero-title .word { display: inline-block; white-space: nowrap; }
.hero-title .char { display: inline-block; }
.hero-title .char { text-align: center; }
.hero-title .char.pending { color: var(--accent, currentColor); }
// JavaScript
const title = document.querySelector('.hero-title');
const text = title.textContent.trim();
title.setAttribute('aria-label', text);
let n = 0;
title.innerHTML = text.split(/\s+/).map(function (word) {
const chars = Array.from(word).map(function (ch) {
return '<span class="char" style="--i:' + (n++) + '">' + ch + '</span>';
}).join('');
return '<span class="word" aria-hidden="true">' + chars + '</span>';
}).join(' ');
const chars = Array.from(title.querySelectorAll('.char'));
const glyphs = 'ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&/<>*+=';
const size = parseFloat(getComputedStyle(title).fontSize);
if (!matchMedia('(prefers-reduced-motion: reduce)').matches) {
chars.forEach(function (c) {
c.dataset.ch = c.textContent;
c.style.width = c.getBoundingClientRect().width / size + 'em';
c.classList.add('pending');
});
const start = performance.now();
let last = 0;
requestAnimationFrame(function tick(now) {
const swap = now - last > 50;
if (swap) last = now;
let done = true;
chars.forEach(function (c, i) {
if (!c.classList.contains('pending')) return;
if (now - start >= 350 + i * 35) {
c.textContent = c.dataset.ch;
c.classList.remove('pending');
} else {
done = false;
if (swap) c.textContent = glyphs[Math.floor(Math.random() * glyphs.length)];
}
});
if (!done) requestAnimationFrame(tick);
});
}