Skip to content

Hero with Rotating Words

Dark hero section whose headline cycles through words with a slide-and-fade animation, a pause button and decorative stat cards.

Live preview

Open in new tab

Code

A dark hero section in pure CSS and a little vanilla JavaScript, where the last word of the headline cycles through several options with a slide-and-fade animation. It fits SaaS landing pages, product launches and portfolio intros that want one headline to carry several value propositions.

How it works

The root section.rw-hero contains .rw-inner, a grid with the text column .rw-copy and the decorative .rw-visual cards. The headline h1.rw-title has a fixed part in .rw-static and a .rw-rotator that holds one .rw-word per option. The rotator is a CSS grid and every word sits in the same cell (grid-area: 1 / 1), so the line always has the height of a single word and the layout never jumps.

Only the word with .is-active is visible. Hidden words wait below the line (translateY(0.7em), opacity: 0) and the word with .is-leaving slides out above it. On DOMContentLoaded the script initializes every .rw-hero, then a setInterval timer moves .is-active to the next word and marks the previous one as .is-leaving; CSS transitions do the animation. The timer stops on visibilitychange when the tab is hidden. Without JavaScript the first word simply stays visible.

The .rw-toggle button is hidden in the markup and revealed by the script. It pauses and resumes the rotation and adds .is-paused to the root. Below 900px the text and the cards stack; from 900px they sit side by side.

Customization

  • Edit, add or remove .rw-word elements inside .rw-rotator to change the rotating words, and update the matching text in .rw-sr.
  • data-interval="2600" on .rw-hero: time in milliseconds each word stays on screen.
  • --rw-speed in style.css: duration of the slide and fade, e.g. 0.3s for a snappier swap.
  • --rw-accent and --rw-accent-2: the gradient of the rotating word, the primary button and the progress bar.
  • --rw-bg and --rw-bg-2: the two stops of the dark background gradient.
  • Remove .rw-visual and set grid-template-columns: 1fr on .rw-inner in the 900px media query to get a single-column text hero.
  • Change translateY(0.7em) on .rw-word to a larger value for a longer vertical travel.

Accessibility

The visual rotator is aria-hidden="true", and the visually hidden .rw-sr span gives screen readers one stable sentence: "Build products that feel fast, friendly, accessible and effortless." The heading is never re-announced while words change. The pause button uses aria-pressed with a fixed label, so its state is announced, and it meets the requirement that auto-updating content can be stopped. When prefers-reduced-motion: reduce is set, rotation starts paused and transitions and transforms are removed. Buttons and links show a clear amber :focus-visible outline, and the decorative cards are hidden from assistive technology.

Usage notes

Several heroes can share a page; each has its own timer and toggle. Keep the rotating words at the end of the headline so different word lengths do not shift the text around them.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Hero with Rotating Words – Pure CSS hero sections component screenshot
Hero with Rotating Words · Pure CSS Hero Sections

More Hero Sections

Hero with Background Overlay – Bootstrap 5 hero sections preview

Hero with Background Overlay

Full-width Bootstrap 5 hero section with a cover background image, dark gradient overlay, fluid headline, two call-to-action buttons and a stats row.

Centered Hero with Announcement Badge – Tailwind CSS hero sections preview

Centered Hero with Announcement Badge

Dark Tailwind CSS hero section with an announcement pill, gradient headline, two CTA buttons, glowing grid background and a row of trust logos.

Hero with Signup Form – Bootstrap 5 hero sections preview

Hero with Signup Form

Bootstrap 5 two-column hero with value points, social proof and a validated signup card that shows a loading state and a success message.

Split Hero with App Screenshot – Tailwind CSS hero sections preview

Split Hero with App Screenshot

Dark Tailwind CSS split hero with gradient headline, two CTA buttons and an animated mock app dashboard built entirely from divs.