axi0motion

Word cycle

A word cycles through a list, letter by letter, on a colored pill that fits each word.

  • enhancer
  • loop
  • words
  • pill
  • since 0.2

Background Studio: tune it below, then copy the code

Your system asks for reduced motion: the demo shows its final state and nothing moves.

Live demo

Word cycle example

Make it  gorgeous

Controls

2200 ms
22 ms

Code

It follows the controls above: change an option and the code changes with it.

<link rel="stylesheet" href="/axi0/motion/motion.css?v=6">
<script src="/axi0/motion/motion.js?v=10" defer></script>

<p class="demo-big">Make it&nbsp; <span data-motion="word-cycle" data-motion-words="gorgeous|smooth|tiny|yours">gorgeous</span></p>

The wrappers: WordCycle.tsx (React, TypeScript) and WordCycle.vue (Vue). Both render the same attributes as the HTML; the loader does the rest.

Options

AttributeDefaultWhat it does
data-motion-wordsautoThe other words, separated by |
data-motion-interval2200Time per word
data-motion-stagger22Delay between letters
data-motion-frombelowLetters arrive
data-motion-alignstartWord inside its slot
data-motion-pilltrueColored pill
data-motion-color#f6a04dPill color
data-motion-ink#111111Text color on the pill

Accessibility

The slot is as wide as the longest word from the start, so the sentence never reflows; write the longest word in the page (it is what readers see without scripts). The pill sits a little outside the word, so give the element some margin. Screen readers hear every word once. Reduced motion keeps the first word still. The loop stops off screen and in hidden tabs.

Size

word-cycle.js is 1.6 KB gzip, with text-kit.js 2.6 KB it needs. A page loads the loader (2.7 KB) and core.js (1.4 KB) once, whatever it uses.