# Strikethrough Swap

> 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.

Category: Text · Free · Updated 2026-11-14 · Live demo: https://www.motionkitui.com/components/strikethrough-swap

## When to use it

Hero headlines and positioning statements: before-and-after messaging, product repositioning and copywriting with a point of view.

## How it works

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.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/strikethrough-swap.json
```

Or copy `components/motionkit/strikethrough-swap.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| 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. |

## Accessibility

- **Keyboard: Not applicable.** Text, nothing to operate.
- **Screen readers: Pass.** Screen readers hear the finished sentence once (with the first replacement); the cycling words are hidden.
- **Reduced motion: Pass.** With reduced motion on, the first correction shows, struck through, without cycling.
- **Colour contrast: Pass.** The new word uses the accent at 7.5:1 by default; the struck word dims to 3.5:1, which passes at heading sizes.

## Source

```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>
  );
}
```
