# Text reveal animations for words and letters

> Reveal the words or the letters of a heading one after the other with Cascade. Split the text into elements, and keep it readable for screen readers.

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](/guides/lists/).

## Reveal each word

Wrap each word in an element:

* React

  ```jsx
  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>
    );
  }
  ```

* Vue

  ```vue
  <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>
  ```

* Astro

  ```astro
  ---
  import { Cascade } from "@awesome-reveal/astro";
  ---

  <Cascade as="h2" class="words" interval={60}>
    <span>Reveal</span> <span>each</span> <span>word</span>
  </Cascade>
  ```

* JavaScript

  ```js
  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](https://www.w3.org/TR/css-transforms-1/#transformable-element). So give the words `display: inline-block`. Select `inline` to see the words fade in with no movement:

## Reveal each letter

Split the text with `Array.from(text)`, and put each letter in an element.

* React

  ```jsx
  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>
    );
  }
  ```

* Vue

  ```vue
  <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>
  ```

* Astro

  ```astro
  ---
  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>
  ```

* JavaScript

  ```js
  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](https://www.w3.org/TR/css-text-3/#line-break-details), 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`.

## 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-label` to the full text. Set `aria-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 with `aria-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

* **`Array.from` splits 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) * interval` milliseconds after the first. Split only short text, such as a heading.
