---
title: "Digit Swap"
description: "Free React digit swap: fixed-slot digits and mask glyphs roll on change, with direction, stagger, replay and suffix emphasis. Framer Motion, shadcn install."
category: "Components"
parent: "https://beui.dev/components/motion/number"
publishedAt: "2026-05-17"
updatedAt: "2026-11-10"
documentation: "https://beui.dev/components/motion/number/digit-swap"
markdown: "https://beui.dev/components/motion/number/digit-swap.md"
license: "MIT"
---

# Digit Swap

> Free React digit swap: fixed-slot digits and mask glyphs roll on change, with direction, stagger, replay and suffix emphasis. Framer Motion, shadcn install.

## Install

```bash
npx shadcn@latest add @beui/digit-swap
```

## Dependencies

- `clsx`
- `motion`
- `react`
- `tailwind-merge`

## Usage

### Digit Swap usage

Fixed-slot digits and mask glyphs that roll on change with controllable direction, stagger, replay, and suffix emphasis.

```tsx
"use client";

import { useState } from "react";
import { DigitSwap } from "@/components/motion/digit-swap";

const CARD_NUMBER = "4242 4242 4242 0806";
const MASKED_NUMBER = "•••• •••• •••• 0806";

export function DigitSwapPreview() {
  const [revealed, setRevealed] = useState(false);

  return (
    <div className="flex w-80 flex-col gap-5">
      <div className="flex flex-col gap-2">
        <span className="text-xs font-medium text-muted-foreground">
          Card number
        </span>
        <DigitSwap
          value={revealed ? CARD_NUMBER : MASKED_NUMBER}
          animationKey={revealed ? "revealed" : "masked"}
          direction={revealed ? "up" : "down"}
          suffixLength={4}
          glyphClassName={
            revealed ? "text-foreground" : "text-muted-foreground"
          }
          suffixClassName="text-foreground"
          className="font-mono text-lg tracking-[0.08em] tabular-nums"
        />
      </div>

      <button
        type="button"
        aria-label={revealed ? "Animate masked number" : "Animate card number"}
        aria-pressed={revealed}
        onClick={() => setRevealed((current) => !current)}
        className="h-10 self-start rounded-full border border-border px-5 text-sm font-medium text-foreground outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring"
      >
        Animate
      </button>
    </div>
  );
}
```

## API Reference

### DigitSwap

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `value` | `string \| number` | — | Yes | Numeric or masked value rendered in fixed character slots. |
| `animationKey` | `string \| number` | — | No | Replays every glyph when the value itself contains unchanged characters. |
| `direction` | `"up" \| "down"` | `up` | No | Direction the next glyph enters from. |
| `duration` | `number` | `0.18` | No | Per-glyph transition duration in seconds. |
| `stagger` | `number` | `0.006` | No | Delay in seconds between neighboring glyphs. |
| `suffixLength` | `number` | `0` | No | Number of final characters that receive `suffixClassName`. |
| `className` | `string` | — | No | Classes merged onto the root element. |
| `glyphClassName` | `string` | — | No | Classes merged onto every animated character. |
| `suffixClassName` | `string` | — | No | Classes added to the last `suffixLength` characters. |

## More in Number Animation

- [Number Ticker](https://beui.dev/components/motion/number/ticker.md)
- [Animated Number](https://beui.dev/components/motion/number/animated.md)

## Source

- Registry detail: https://beui.dev/r/digit-swap
- Raw source: https://beui.dev/r/digit-swap/raw
- GitHub: https://github.com/starc007/ui-components
