Text reveal animations for words and letters
A cascade does not split text. To reveal the words or the letters of a text, wrap each part in an element, and put the elements in a cascade. For the cascade APIs and the interval option, see Animate a list.
Reveal each word
Section titled “Reveal each word”Wrap each word in an element:
import { Cascade } from "@awesome-reveal/react";
export function HeadingWords() { return ( <Cascade as="h2" className="words" interval={60}> <span>Reveal</span> <span>each</span> <span>word</span> </Cascade> );}<script setup>import { Cascade } from "@awesome-reveal/vue";</script>
<template> <Cascade as="h2" class="words" :interval="60"> <span>Reveal</span> <span>each</span> <span>word</span> </Cascade></template>---import { Cascade } from "@awesome-reveal/astro";---
<Cascade as="h2" class="words" interval={60}> <span>Reveal</span> <span>each</span> <span>word</span></Cascade>import { cascade } from "@awesome-reveal/core";
cascade("h2.words", { interval: 60 });The entrance moves the element with a transform, and an inline element cannot have a transform. So give the words display: inline-block. Select inline to see the words fade in with no movement:
Reveal each word
Reveal each word
Your device asks for reduced motion, so the content shows with no animation.
.words span { display: inline-block;}.words span { display: inline;}Reveal each letter
Section titled “Reveal each letter”Split the text with Array.from(text), and put each letter in an element.
import { Cascade } from "@awesome-reveal/react";
export function HeadingLetters({ text }) { return ( <Cascade as="h2" aria-label={text} from={{ opacity: 0 }} interval={40}> {Array.from(text, (letter, index) => ( <span key={index} aria-hidden="true"> {letter} </span> ))} </Cascade> );}<script setup>import { Cascade } from "@awesome-reveal/vue";
defineProps({ text: { type: String, required: true } });</script>
<template> <Cascade as="h2" :aria-label="text" :from="{ opacity: 0 }" :interval="40"> <span v-for="(letter, index) in Array.from(text)" :key="index" aria-hidden="true" v-text="letter" /> </Cascade></template>---import { Cascade } from "@awesome-reveal/astro";
const text = "Reveal each letter";---
<Cascade as="h2" aria-label={text} from={{ opacity: 0 }} interval={40}> {Array.from(text).map((letter) => ( <span aria-hidden="true">{letter}</span> ))}</Cascade>import { cascade } from "@awesome-reveal/core";
for (const heading of document.querySelectorAll("h2.letters")) { const text = heading.textContent.trim(); const letters = Array.from(text, (character) => { const letter = document.createElement("span"); letter.setAttribute("aria-hidden", "true"); letter.textContent = character; return letter; }); heading.setAttribute("aria-label", text); heading.textContent = ""; heading.append(...letters);}
cascade("h2.letters", { from: { opacity: 0 }, interval: 40 });Keep the letters inline. The browser can break a line before and after each inline-block element, so a word of inline-block letters can break between two letters. An inline element cannot move, so give the letters a start state with only opacity, as in the example, or with opacity and blur.
Reveal each letter
Your device asks for reduced motion, so the content shows with no animation.
Keep the text readable for screen readers
Section titled “Keep the text readable for screen readers”A screen reader can read each letter element as a separate word. Give the full text to screen readers one time:
- On an element that can have a name, such as a heading, set
aria-labelto the full text. Setaria-hidden="true"on each letter. The examples above do this. - On an element that cannot have a name, such as a paragraph or a
div, put the full text in a visually hidden element. Put the letters in an element witharia-hidden="true", and make it the cascade.
The words need no change. Screen readers read a word in its own element as one word.
Things to know
Section titled “Things to know”Array.fromsplits the text into code points. Use the letter examples only when each character that a reader sees has one code point. Other characters break into pieces, such as some emoji and the Hindiकि.- Each letter adds one interval. The last letter starts
(count - 1) * intervalmilliseconds after the first. Split only short text, such as a heading.