On hover, each letter rolls over on a little 3D cube to reveal a fresh copy, one after another. Made for links and buttons.
A link or button whose letters roll up on hover, each replaced by a copy from below, one after another. Pure CSS.
Customize
Usage
import { LetterFlipHover } from "@/components/motionkit/letter-flip-hover";
<LetterFlipHover href="/contact">
Get in touch
</LetterFlipHover>Motion
The exact curves this component runs, plotted with Motion's own maths.
Letters roll
Hover or focus
Navigation links, footer links, buttons and calls to action across agency, portfolio and product sites.
Each letter sits in a clipped box with an identical copy directly below it. On hover or keyboard focus, both copies slide up by their own height with a CSS transition, each letter delayed a little more than the one before. It's all CSS, so nothing runs until you hover.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/letter-flip-hover.jsonnpm install motionSave as components/motionkit/letter-flip-hover.tsx.
"use client";
import type { CSSProperties, ReactNode } from "react";
type LetterFlipHoverProps = {
/** The label. Plain text only, since each letter is animated. */
children?: string;
/** Makes it a link; without it, it's a button. */
href?: string;
onClick?: () => void;
/** Milliseconds between one letter and the next. */
stagger?: number;
/** Milliseconds each letter takes to roll. */
duration?: number;
/** Colour of the letters that roll in. Leave unset to keep the same colour. */
hoverColor?: string;
/** Content shown after the text, such as an arrow icon. */
after?: ReactNode;
className?: string;
};
/**
* A link or button whose label rolls on hover: each letter slides up out of view while an identical copy rises
* from below, one letter after another, left to right. Pure CSS, so it costs nothing at rest. It also plays on
* keyboard focus, screen readers hear the label once, and with reduced motion it simply changes colour.
*/
export function LetterFlipHover({ children = "Get in touch", href, onClick, stagger = 22, duration = 420, hoverColor, after, className = "" }: LetterFlipHoverProps) {
const letters = [...children];
const style = { "--flip-duration": `${duration}ms`, "--flip-color": hoverColor ?? "currentColor" } as CSSProperties;
const body = (
<>
<span className="sr-only">{children}</span>
<span aria-hidden className="inline-flex overflow-hidden whitespace-pre leading-[1.15]">
{letters.map((letter, index) => (
<span key={index} className="relative inline-block">
<span
className="inline-block transition-transform ease-[cubic-bezier(0.16,1,0.3,1)] [transition-duration:var(--flip-duration)] group-hover:-translate-y-full group-focus-visible:-translate-y-full motion-reduce:transition-none motion-reduce:group-hover:translate-y-0"
style={{ transitionDelay: `${index * stagger}ms` }}
>
{letter}
</span>
<span
className="absolute left-0 top-full inline-block text-[var(--flip-color)] transition-transform ease-[cubic-bezier(0.16,1,0.3,1)] [transition-duration:var(--flip-duration)] group-hover:-translate-y-full group-focus-visible:-translate-y-full motion-reduce:hidden"
style={{ transitionDelay: `${index * stagger}ms` }}
>
{letter}
</span>
</span>
))}
</span>
{after}
</>
);
const classes = `group inline-flex items-center gap-2 font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-[#B9C7FF] focus-visible:ring-offset-4 focus-visible:ring-offset-[#0C1010] motion-reduce:hover:text-[var(--flip-color)] ${className}`;
return href ? (
<a href={href} className={classes} style={style} onClick={onClick}>
{body}
</a>
) : (
<button type="button" className={classes} style={style} onClick={onClick}>
{body}
</button>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| children | string | "Get in touch" | The label, as plain text. |
| href | string | — | Makes it a link; without it, it's a button. |
| onClick | () => void | — | Click handler. |
| stagger | number | 22 | Milliseconds between letters. |
| duration | number | 420 | Milliseconds each letter takes. |
| hoverColor | string | — | Colour of the letters that roll in. |
| after | ReactNode | — | Shown after the label, such as an arrow icon. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Nothing beyond React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/letter-flip-hover.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, letters don't move; the hover colour changes instead.
On hover, each letter rolls over on a little 3D cube to reveal a fresh copy, one after another. Made for links and buttons.
On hover or focus, the letters swap places a few times and slide home. Made for links and buttons.
Letters lift and settle one after another, like a wave running through the word: on hover, or as a gentle loop.