Words come into focus one after another, sharpening from a soft blur as the text scrolls into view.
A sentence that corrects itself: a word is struck through with a clean line and a better one fades in beside it, cycling through pairs.
Customize
Usage
import { StrikethroughSwap } from "@/components/motionkit/strikethrough-swap";
<StrikethroughSwap
as="h1"
before="We don't build"
pairs={[
["websites", "products"],
["features", "experiences"],
]}
className="text-5xl font-semibold"
/>Motion
The exact curves this component runs, plotted with Motion's own maths.
Line strikes
Each pair
New word arrives
After the strike
Hero headlines and positioning statements: before-and-after messaging, product repositioning and copywriting with a point of view.
Each pair is one keyed element inside AnimatePresence. On arrival, a line scales across the old word from the left, the word dims, and the replacement fades up from a slight blur; after the interval the whole pair fades out and the next one takes its place. It waits until the sentence is on screen to start.
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/strikethrough-swap.jsonnpm install motionSave as components/motionkit/strikethrough-swap.tsx.
"use client";
import { useEffect, useRef, useState } from "react";
import { AnimatePresence, motion, useInView, useReducedMotion } from "motion/react";
type StrikethroughSwapProps = {
/** Text before the swapped words. */
before?: string;
/** Each pair is crossed out, then replaced: [the word you strike, the word that replaces it]. */
pairs?: [string, string][];
/** Text after the swapped words. */
after?: string;
/** Seconds each pair stays before the next one. */
interval?: number;
/** Colour of the strike line and the new word. */
accent?: string;
/** The element to render, for the right heading level. */
as?: "h1" | "h2" | "h3" | "p";
className?: string;
};
/**
* A sentence that corrects itself: a word is crossed out with a clean drawn line, dims, and a better word fades in
* beside it, then the next pair takes over. It waits until it's on screen to start. Screen readers hear the
* finished sentence, and with reduced motion the first correction simply shows, struck through.
*/
export function StrikethroughSwap({
before = "We don't build",
pairs = [
["websites", "products"],
["features", "experiences"],
["pages", "systems"],
],
after = ".",
interval = 3.2,
accent = "#5FAEB4",
as = "h2",
className = "",
}: StrikethroughSwapProps) {
const reduceMotion = useReducedMotion();
const ref = useRef<HTMLHeadingElement>(null);
const inView = useInView(ref, { amount: 0.6 });
// the first correction waits until the sentence is on screen; until then the word stands uncorrected
const started = useInView(ref, { amount: 0.6, once: true });
const [index, setIndex] = useState(0);
const Tag = as;
useEffect(() => {
if (reduceMotion || !inView || pairs.length < 2) return;
const timer = window.setInterval(() => setIndex((current) => (current + 1) % pairs.length), interval * 1000);
return () => window.clearInterval(timer);
}, [reduceMotion, inView, pairs.length, interval]);
const [struck, replacement] = pairs[index] ?? pairs[0];
const ease = [0.16, 1, 0.3, 1] as const;
return (
<Tag ref={ref} className={className}>
<span className="sr-only">{`${before} ${pairs[0][1]}${after}`}</span>
<span aria-hidden>
{before}{" "}
{!started && !reduceMotion ? (
<span>{struck}</span>
) : (
<AnimatePresence mode="wait">
<motion.span key={index} className="inline-flex flex-wrap items-baseline gap-x-[0.3em]" exit={reduceMotion ? undefined : { opacity: 0, transition: { duration: 0.25 } }}>
<motion.span
className="relative inline-block"
initial={{ opacity: 1 }}
animate={{ opacity: 0.4 }}
transition={{ delay: reduceMotion ? 0 : 0.55, duration: 0.4 }}
>
{struck}
<motion.span
className="absolute left-[-0.04em] right-[-0.04em] top-[55%] h-[0.075em] origin-left rounded-full"
style={{ background: accent }}
initial={{ scaleX: reduceMotion ? 1 : 0 }}
animate={{ scaleX: 1 }}
transition={{ delay: 0.2, duration: 0.45, ease }}
/>
</motion.span>
<motion.span
className="inline-block"
style={{ color: accent }}
initial={reduceMotion ? false : { opacity: 0, y: "0.3em", filter: "blur(6px)" }}
animate={{ opacity: 1, y: "0em", filter: "blur(0px)" }}
transition={{ delay: 0.75, duration: 0.6, ease }}
>
{replacement}
</motion.span>
</motion.span>
</AnimatePresence>
)}
{after}
</span>
</Tag>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| before | string | "We don't build" | Text before the swapped words. |
| pairs | [string, string][] | — | Each pair: the word struck through, then its replacement. |
| after | string | "." | Text after the swapped words. |
| interval | number | 3.2 | Seconds each pair stays. |
| accent | string | "#5FAEB4" | Colour of the line and the new word. |
| as | "h1" | "h2" | "h3" | "p" | "h2" | The element to render. |
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.
Only the motion package, beside 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/strikethrough-swap.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the first correction shows, struck through, without cycling.
Words come into focus one after another, sharpening from a soft blur as the text scrolls into view.
Rotates through a list of words, letters rising in and drifting out.
Headlines that rise letter by letter, slide up line by line, blur into focus or light up as you scroll.