# Underline draw

> A line draws itself under one word. Straight, hand drawn, sketched or wavy.

- Applies to one word of the headline
- Live page with controls: https://smthngfun.com/a/word-underline
- This style as JSON: https://smthngfun.com/api/styles/word-underline
- 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 |
| --- | --- | --- | --- |
| Line style | `variant` | `straight` | straight, hand-drawn, sketch, wavy |
| Position | `position` | `below` | below, through |
| Layer | `layer` | `behind` | behind, in-front |
| Draw duration | `duration` | `700` | 150 to 2500 ms |
| Pause before drawing | `delay` | `500` | 0 to 3000 ms |
| Line thickness | `thickness` | `0.09` | 0.03 to 0.22 em |
| Accent colour | `accent` | empty | Six digit hex without the hash. Empty means the site's own accent colour. |

- `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 Underline draw. 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 headline still and draw an underline beneath that word. The line is 0.09em thick with fully rounded ends, in my accent colour. The line sits just under the baseline without touching the next line of text. Layer it behind the letters, so the text always stays on top. It grows from left to right by scaling on the X axis over 700ms with the easing cubic-bezier(0.65, 0, 0.35, 1), starting 500ms after the page loads. Build it as a pseudo element on a span around the word so it adds no height to the line. Play it once and leave the line in place. 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-underline 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
<!-- Underline draw animation from https://smthngfun.com/a/word-underline -->
<h1 class="hero-title">Make your landing page feel <span class="underline">alive</span></h1>
```

```css
.hero-title .underline {
  position: relative;
  z-index: 0; /* keeps the line and the letters layered together */
  display: inline-block;
  white-space: nowrap;
}
.hero-title .underline::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.03em;
  z-index: -1; /* behind the letters */
  height: 0.09em;
  border-radius: 0.09em;
  background: var(--accent, currentColor);
  transform: scaleX(0);
  transform-origin: 0 50%;
  animation: underline-draw 700ms cubic-bezier(0.65, 0, 0.35, 1) 500ms forwards;
}
@keyframes underline-draw { to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .hero-title .underline::after { animation: none; transform: none; }
}
```

## Credit

Keep the comment at the top of the code, which reads "Underline draw animation from https://smthngfun.com/a/word-underline". 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.
