Composables

useSplitText

Documentation for useSplitText composable.

The useSplitText composable wraps the splitText function from AnimeJS.

A lightweight, responsive and accessible text utility function to split, clone and wrap lines, words and characters of an HTML Element.

Arguments

target
MaybeRef<SplitTextTargets> required
The element or selector containing the text to split.
parameters
MaybeRefOrGetter<TextSplitterParams>
See AnimeJS Text documentation for split options like lines, words, chars.

Example

Hello World!
import { stagger } from '#nanime/utils'

const text = useTemplateRef('phrase')
const { chars } = useSplitText(text, {
  chars: true,
})

useAnimate(chars, {
  y: [{ to: '-30%' }, { to: 0 }],
  delay: stagger(50),
  duration: 600,
  ease: 'inOutCirc',
  loop: true,
})
View on GitHub

Return Value

Returns an object with reactive references to the split elements and computed accessors.

PropertyTypeDescription
linesRef<HTMLElement[]>Array containing line elements.
wordsRef<HTMLElement[]>Array containing word elements.
charsRef<HTMLElement[]>Array containing character elements.
properties`ComputedRef<NonFunctionPropertiesundefined>`{lang="ts-type"}
methods`ComputedRef<OnlyFunctionPropertiesundefined>`{lang="ts-type"}

API

Types

function useSplitText(
  target: MaybeRef<SplitTextTargets>,
  parameters?: MaybeRefOrGetter<TextSplitterParams>
): {
  lines: Ref<HTMLElement[]>,
  words: Ref<HTMLElement[]>,
  chars: Ref<HTMLElement[]>,
  properties: ComputedRef<NonFunctionProperties<TextSplitter> | undefined>,
  methods: ComputedRef<OnlyFunctionProperties<TextSplitter> | undefined>,
}
type SplitTargets = HTMLElement | string
type SplitTextTargets = SplitTargets | MaybeElementRef<HTMLElement> | null | undefined | MaybeElementRef<VueInstance>

See AnimeJS Text documentation for more details.

Copyright © 2026