Recipe: An Animated Hero Section in 20 Lines of HTML
The hero is the most animated section of almost every landing page, and the pattern barely varies: the headline reveals itself, the supporting copy fades in just after, and the call-to-action buttons arrive last with a little life on hover. This recipe builds exactly that with motion-components. The entire animation layer is HTML attributes.
Here’s the finished markup. Everything else in this article is explanation:
Setup
One import, npm or CDN:
The stylesheet stops the headline and buttons from flashing fully visible before their entrance animation is ready. That mechanism gets its own article. If you bundle instead, run
The headline: motion-headline
by="words" : the unit of animation."chars" gives a finer cascade, and"lines" reads calmer and more editorial. Words is the safe default for heroes: readable at a glance, animated enough to notice.interval="0.06" : seconds between each word starting. This knob controls perceived speed more thanduration does. At0.03 the headline pours in; at0.12 it becomes deliberate.duration="1" : the spring duration hint for each word’s individual rise.
The
If the slide-up mask is too subtle for your brand,
The subcopy: motion-reveal
The headline takes about a second to finish. The reveal starts at the same time but resolves faster, so the eye reads them as a sequence without any explicit delay coordination. That is a general principle worth stealing: overlapping animations with different durations read as choreography; sequential animations with gaps read as loading.
The buttons: motion-stagger + motion-hover
Two components composed, one responsibility each:
motion-stagger handles the entrance: each direct child fades and lifts in,interval seconds apart. With two buttons the 0.08s offset is barely conscious, which is the point. It also takesfrom="last" orfrom="center" to change where the cascade starts. With a row of feature cards,from="center" is a nice trick.motion-hover handles the response: a spring toscale: 1.04 , lifted 2px, fully interruptible mid-flight (why that matters).
Composition over configuration is the library’s core pattern. There is no
Taste adjustments
The recipe as written is deliberately restrained. Depending on the product’s personality:
- Calmer: use
by="lines" on the headline, drop the stagger, and let the buttons simply appear with the reveal. - Bouncier: add
bounce="0.4" to themotion-hover wrappers. Read the bounce guide before going higher. - Terminal-flavored: replace
motion-headline withmotion-typewriter for character-by-character typing with a blinking cursor. Different genre, same drop-in usage.
Accessibility, included
Every component here respects
Related