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 Typewriter. Reveal the headline one character at a time as if someone is typing it, at 60ms per character with a random variation of up to 20ms either way so it feels human. Wait 350ms after the page loads before the first character. Show a thin vertical caret in my accent colour right after the last typed character. The caret blinks once per second and keeps blinking after the typing ends. Reserve the full space of the headline from the start by rendering every character hidden and revealing them in place, so the text never reflows while typing. 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/typewriter 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 Typewriter with your settings. It assumes the headline has the class hero-title.
<!-- HTML -->
<!-- Typewriter animation from https://smthngfun.com/a/typewriter -->
<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 { visibility: hidden; }
.hero-title .char.on { visibility: visible; }
.hero-title .caret {
display: inline-block;
position: relative;
width: 0;
height: 0.82em;
}
.hero-title .caret::after {
content: "";
position: absolute;
left: 0.04em;
bottom: -0.08em;
width: 0.07em;
height: 100%;
background: var(--accent, currentColor);
animation: caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }
// 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'));
if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
chars.forEach(function (c) { c.classList.add('on'); });
} else {
const caret = document.createElement('span');
caret.className = 'caret';
caret.setAttribute('aria-hidden', 'true');
chars[0].before(caret);
let i = 0;
setTimeout(function type() {
chars[i].classList.add('on');
chars[i].after(caret);
i += 1;
if (i < chars.length) setTimeout(type, 60 + (Math.random() * 2 - 1) * 20);
}, 350);
}