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.

Also known as: animated headline, text rotator, rotating text animation, changing words hero

Hero with Rotating Words live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

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.

Use cases

  • SaaS landing pages: one headline that names several audiences or benefits
  • Product launches: rotate the key words of a launch message
  • Portfolio intros: cycle through the roles or skills you offer

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.

Hero with Rotating Words at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile, dark design
Category
Hero Sections
License
Free for personal and commercial use

Questions about this template

Can I use the Hero with Rotating Words code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Hero with Rotating Words – free Pure CSS hero section template
Hero with Rotating Words · free Pure CSS hero section template

More Hero Sections

Split Hero with Diagonal Photo Clip – free Pure CSS hero section template

Split Hero with Diagonal Photo Clip

Pure CSS split hero with headline, buttons and stats beside a full-height photo cut on a diagonal with clip-path, plus an accent stripe and rating badge.

Split Hero with App Screenshot – free Tailwind CSS hero section template

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.

Hero with Search Bar – free Bootstrap 6 hero section template

Hero with Search Bar

Bootstrap 6 directory hero on a photo background with a large pill search bar, a searchable area Combobox, popular search chips and category tiles.

Hero with Background Video Overlay – free Bootstrap 6 hero section template

Hero with Background Video Overlay

Full-width Bootstrap 6 hero with a muted background video or slow-zoom poster photo, dark gradient overlay, headline, two buttons, stats and a pause control.

Centered Hero with Announcement Badge – free Tailwind CSS hero section template

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.

Dark Gradient Hero – free Bootstrap 6 hero section template

Dark Gradient Hero

Dark Bootstrap 6 hero with a blurred gradient mesh, gradient headline, glowing CTA, copyable install command, decorative orb with stats and a row of trust logos.