# Flip in

> Letters swing down into place in 3D.

- Applies to the whole headline
- Live page with controls: https://smthngfun.com/a/flip-in
- This style as JSON: https://smthngfun.com/api/styles/flip-in
- 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 |
| --- | --- | --- | --- |
| Duration | `duration` | `700` | 200 to 1800 ms |
| Delay between letters | `stagger` | `30` | 0 to 120 ms |
| Perspective | `perspective` | `600` | 150 to 1500 px |
| Easing | `ease` | `snappy` | smooth, snappy, springy, gentle, linear |

- `t` The headline text to show and to use in the example code.
- `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 the main headline in the hero section of my landing page with an effect called Flip in. Split the headline into individual letters, keeping each word in its own no-wrap span. Each letter starts invisible and rotated 90 degrees backwards on the X axis, hinged at its top edge, with a perspective of 600px. It then swings down to flat while fading in. Use a duration of 700ms, the easing cubic-bezier(0.2, 0.8, 0.2, 1) and a 30ms delay between letters. Play it once when the page loads. 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/flip-in 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
<!-- Flip in animation from https://smthngfun.com/a/flip-in -->
<h1 class="hero-title">Make your landing page feel alive</h1>
```

```css
.hero-title .word { display: inline-block; white-space: nowrap; }
.hero-title .char { display: inline-block; }
.hero-title .char {
  opacity: 0;
  transform: perspective(600px) rotateX(-90deg);
  transform-origin: 50% 0;
  animation: flip-in 700ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  animation-delay: calc(var(--i) * 30ms);
}
@keyframes flip-in { to { opacity: 1; transform: perspective(600px) rotateX(0); } }
@media (prefers-reduced-motion: reduce) {
  .hero-title .char { animation: none; opacity: 1; transform: none; }
}
```

```js
const title = document.querySelector('.hero-title');
const text = title.textContent.trim();
title.setAttribute('aria-label', text);
let n = 0;
title.innerHTML = text.split(/\s+/).map(function (word) {
  const chars = Array.from(word).map(function (ch) {
    return '<span class="char" style="--i:' + (n++) + '">' + ch + '</span>';
  }).join('');
  return '<span class="word" aria-hidden="true">' + chars + '</span>';
}).join(' ');
```

## Credit

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