# Word wave

> Only the letters of one word ripple.

- Applies to one word of the headline
- Live page with controls: https://smthngfun.com/a/word-wave
- This style as JSON: https://smthngfun.com/api/styles/word-wave
- Every style: https://smthngfun.com/llms.txt

## Settings

The values below are the ones this page was asked for. Change any of them by adding it as a query parameter to the page, to this file or to the JSON address.

| Setting | Parameter | Value | Allowed |
| --- | --- | --- | --- |
| Full cycle | `cycle` | `1600` | 600 to 5000 ms |
| Delay between letters | `stagger` | `70` | 10 to 250 ms |
| Lift height | `height` | `0.18` | 0.04 to 0.6 em |
| Accent colour | `accent` | empty | Six digit hex without the hash. Empty means the site's own accent colour. |
| Letter colours | `palette` | empty | Up to eight six digit hex colours joined with dashes. Empty means off. |

- `t` The headline text to show and to use in the example code.
- `w` For one word styles, the position of the word to animate, counting from 0. Defaults to the last word.
- `f` A Google font name for the headline, for example Playfair Display.

## Prompt

Written for a coding assistant. It describes the animation fully, so it works without the code below.

```text
Animate one word in the main headline of my landing page with an effect called Word wave. In my example the headline reads "Make your landing page feel alive" and the animated word is "alive". Apply it to the word I point out in my own headline, and ask me which one if I have not said. Keep the rest of the headline still. Split only that word into individual letters and loop a wave through them forever. Each letter lifts by 0.18em and comes back down during the first 40 percent of a 1.6 seconds cycle, then rests for the remainder. Offset each letter by 70ms so the lift travels from left to right. Use ease-in-out. Show the word in my accent colour. Keep my existing font, colours and layout exactly as they are. Screen readers and search engines must still read the headline as one normal sentence, so put the full text in an aria-label on the heading and mark any decorative spans as aria-hidden. If the visitor has prefers-reduced-motion turned on, show the finished headline straight away with no animation. Make sure nothing shifts the layout while it plays. Use plain CSS and a little vanilla JavaScript, unless my project already has an animation library, in which case use that. A live demo with reference code for these exact settings is at https://smthngfun.com/a/word-wave and you can use that code as your starting point, adapted to my codebase and styling. If I am happy to credit the source, add a small "Animation by smthngfun" link to https://smthngfun.com in the footer of the page. Ask me before adding it.
```

## Reference code

A working version with the settings above. It assumes the headline has the class `hero-title`. Adapt it to the project's own framework and styling.

```html
<!-- Word wave animation from https://smthngfun.com/a/word-wave -->
<h1 class="hero-title">Make your landing page feel <span class="wave">alive</span></h1>
```

```css
.hero-title .wave {
  display: inline-block;
  white-space: nowrap;
  color: var(--accent, currentColor);
}
.hero-title .wave span {
  display: inline-block;
  animation: word-wave 1600ms ease-in-out infinite;
  animation-delay: calc(var(--i) * 70ms);
}
@keyframes word-wave {
  0%, 40%, 100% { transform: translateY(0); }
  20% { transform: translateY(-0.18em); }
}
@media (prefers-reduced-motion: reduce) {
  .hero-title .wave span { animation: none;  }
}
```

```js
const target = document.querySelector('.hero-title .wave');
const word = target.textContent;
target.setAttribute('aria-label', word);
target.innerHTML = Array.from(word).map(function (ch, i) {
  return '<span aria-hidden="true" style="--i:' + i + '">' + ch + '</span>';
}).join('');
```

## Credit

Keep the comment at the top of the code, which reads "Word wave animation from https://smthngfun.com/a/word-wave". If the person you are building for is happy to credit the source, add a small visible "Animation by smthngfun" link to https://smthngfun.com in the footer of their page. Ask them first, and do not add it without their say.
