GSAP SplitText text animations

Split headings into lines, words or letters and animate them. Four text animations with code that runs as written, plus how to keep them accessible and responsive.

SplitText wraps each line, word or character of your text in its own element, so GSAP can animate them one by one. It used to be a paid plugin. Since GSAP 3.13 it's free, and it was rewritten with masking, automatic re-splitting and screen reader support built in. Every example below was tested with GSAP 3.15.

Set it up

Add GSAP, SplitText and ScrollTrigger from the CDN, then register both plugins.

example.html
<script src="https://cdn.jsdelivr.net/npm/gsap@3.15/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.15/dist/ScrollTrigger.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.15/dist/SplitText.min.js"></script>
<script>
  gsap.registerPlugin(SplitText, ScrollTrigger);
</script>

With npm, import { SplitText } from "gsap/SplitText" and register it the same way.

1. Lines rise out of a mask

The classic heading reveal: each line slides up from behind an invisible edge. mask: "lines" adds a clipping wrapper around every line, so you don't need extra markup.

example.css
.headline { visibility: hidden; }
example.js
SplitText.create(".headline", {
  type: "lines",
  mask: "lines",
  autoSplit: true,
  onSplit(self) {
    gsap.set(".headline", { visibility: "visible" });
    return gsap.from(self.lines, {
      yPercent: 100,
      duration: 0.9,
      stagger: 0.08,
      ease: "power4.out",
    });
  },
});

The heading starts hidden in CSS so the unsplit text never flashes before the animation. autoSplit: true re-splits the lines when fonts load or the width changes. Return the animation from onSplit and SplitText keeps it in step when that happens.

2. Words fade up on scroll

Split into words and start the stagger when the paragraph scrolls into view.

example.js
document.querySelectorAll(".split-words").forEach((el) => {
  SplitText.create(el, {
    type: "words",
    autoSplit: true,
    onSplit(self) {
      return gsap.from(self.words, {
        autoAlpha: 0,
        y: 20,
        duration: 0.6,
        stagger: 0.04,
        ease: "power2.out",
        scrollTrigger: { trigger: el, start: "top 80%", once: true },
      });
    },
  });
});

Looping over the elements gives each paragraph its own trigger, so they animate as each one arrives rather than all at once.

3. Letters bounce in

Split into characters for short words and headlines. back.out overshoots a little before settling, which reads as a bounce.

example.js
SplitText.create(".split-chars", {
  type: "chars",
  onSplit(self) {
    return gsap.from(self.chars, {
      yPercent: 120,
      autoAlpha: 0,
      duration: 0.6,
      stagger: 0.03,
      ease: "back.out(2)",
      scrollTrigger: { trigger: ".split-chars", start: "top 80%", once: true },
    });
  },
});

Keep character animations to short text. A long paragraph split into letters makes hundreds of elements and takes ages to finish.

4. Words light up as you scroll

Scrub the opacity of each word against the scroll, so the sentence fills in as you read it.

example.js
SplitText.create(".split-scrub", {
  type: "words",
  onSplit(self) {
    return gsap.from(self.words, {
      opacity: 0.15,
      stagger: 0.1,
      ease: "none",
      scrollTrigger: {
        trigger: ".split-scrub",
        start: "top 75%",
        end: "bottom 40%",
        scrub: true,
      },
    });
  },
});

Keep it accessible

  • Screen readers. SplitText puts the full text in an aria-label on the element you split and hides the pieces with aria-hidden, so the text is read as one sentence, not letter by letter. That's the default, so leave the aria option alone.
  • Reduced motion. Wrap your text animations in gsap.matchMedia() with (prefers-reduced-motion: no-preference), as in the ScrollTrigger examples. Remember to make text you hid in CSS visible again in the reduced-motion case.
  • Styling the pieces. The split elements have no classes by default. Pass linesClass, wordsClass or charsClass if you want to style them.

Using React

Create the split inside useGSAP. When the component unmounts, the hook reverts the split and its animation, so the original text comes back cleanly.

Example.tsx
"use client";
import { useRef } from "react";
import { gsap } from "gsap";
import { SplitText } from "gsap/SplitText";
import { useGSAP } from "@gsap/react";

gsap.registerPlugin(SplitText, useGSAP);

export function SplitHeading({ children }: { children: React.ReactNode }) {
  const ref = useRef<HTMLHeadingElement>(null);

  useGSAP(
    () => {
      SplitText.create(ref.current, {
        type: "lines",
        mask: "lines",
        autoSplit: true,
        onSplit: (self) =>
          gsap.from(self.lines, {
            yPercent: 100,
            duration: 0.9,
            stagger: 0.08,
            ease: "power4.out",
          }),
      });
    },
    { scope: ref },
  );

  return <h1 ref={ref}>{children}</h1>;
}

Skip the build.

Finished text components from the Vault, in HTML and React, with reduced motion and cleanup already in.

Start with 15 free.

Make a free account and take the code for 15 components. No card needed.