---
title: "QR Code"
description: "A rounded-dot QR code on canvas that builds itself piece by piece. Dots and finder eyes fly in on curved paths, pop in behind a spreading ring, drop in behind a bar sweeping down, or rise as smoke and condense into place. Hiding plays the build backwards, and a press mid-build turns it around in place."
category: "Components"
publishedAt: "2026-12-01"
updatedAt: "2026-12-01"
documentation: "https://beui.dev/components/motion/qr-code"
markdown: "https://beui.dev/components/motion/qr-code.md"
license: "MIT"
---

# QR Code

> A rounded-dot QR code on canvas that builds itself piece by piece. Dots and finder eyes fly in on curved paths, pop in behind a spreading ring, drop in behind a bar sweeping down, or rise as smoke and condense into place. Hiding plays the build backwards, and a press mid-build turns it around in place.

## Install

```bash
npx shadcn@latest add @beui/qr-code
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`
- `uqr`

## Usage

```tsx
"use client";

import { QrCode } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/motion/button";
import { AnimatedQrCode, type QrCodeVariant } from "@/components/motion/qr-code";
import { Tabs, TabsList, TabsTrigger } from "@/components/motion/tabs";

const VARIANTS: { value: QrCodeVariant; label: string }[] = [
  { value: "swarm", label: "Swarm" },
  { value: "ripple", label: "Ripple" },
  { value: "scan", label: "Scan" },
  { value: "smoke", label: "Smoke" },
];

export function QrCodePreview() {
  const [variant, setVariant] = useState<QrCodeVariant>("swarm");
  const [shown, setShown] = useState(false);

  return (
    <div className="flex w-full flex-col items-center gap-4">
      <Tabs value={variant} onValueChange={(v) => setVariant(v as QrCodeVariant)} variant="pill">
        <TabsList aria-label="Arrival style" wrapperClassName="w-auto">
          {VARIANTS.map((v) => (
            <TabsTrigger key={v.value} value={v.value} className="text-xs">
              {v.label}
            </TabsTrigger>
          ))}
        </TabsList>
      </Tabs>
      <AnimatedQrCode value="https://beui.dev" shown={shown} variant={variant} />
      <Button size="sm" onClick={() => setShown((s) => !s)} aria-pressed={shown}>
        <QrCode className="size-4" aria-hidden />
        {shown ? "Hide code" : "Show code"}
      </Button>
    </div>
  );
}
```

## API Reference

### AnimatedQrCode

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `value` | `string` |  | Yes | Text or URL the code encodes. |
| `shown` | `boolean` |  | Yes | Whether the code is drawn. Turning it on builds the code; turning it off plays the build backwards from wherever it is. |
| `variant` | `"ripple" \| "swarm" \| "scan" \| "smoke"` | `swarm` | No | How the code builds: every piece flies in on a curved path, pops in place behind a spreading ring, drops into place behind a bar sweeping down, or rises as smoke and condenses from the bottom row up. Default: "swarm" |
| `size` | `number` | `296` | No | Side of the square canvas, in px, quiet zone included. Default: 296 |
| `origin` | `QrCodeOrigin` |  | No | Where swarm pieces fly from and where the ripple ring starts. Scan and smoke ignore it. Default: bottom centre for swarm, centre for ripple |
| `ink` | `string` | `#0a0a0a` | No | Dot colour, any CSS colour. Default: "#0a0a0a" |
| `paper` | `string` | `#ffffff` | No | Background colour, any CSS colour. Keep it light so cameras can read the code. Default: "#ffffff" |
| `onSettled` | `((shown: boolean) => void)` |  | No | Called when a build or teardown finishes, with the `shown` value it ended on. |
| `labels` | `Partial<{ label: string; }>` |  | No | Translated strings, merged over the English defaults. |
| `className` | `string` |  | No | Classes merged onto the canvas. |

## Types

### QrCodeOrigin

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `x` | `number` | Yes | Horizontal position as a fraction of the canvas width, 0 is the left edge. |
| `y` | `number` | Yes | Vertical position as a fraction of the canvas height, 0 is the top edge. |

## About QR Code

QR Code is an animated React QR code drawn on canvas in a rounded-dot style, with finder eyes whose corners stay concentric. Instead of fading in, it builds itself, and the eyes move exactly like the dots. Swarm flies every piece in from the origin on a curved path, stretched along its flight, nearest first. Ripple keeps every piece in place and pops it from a round seed as a ring spreads out from the origin. Scan sweeps a soft bar down the code and drops each row into place behind it. Smoke sends up soft puffs from below that curl as they rise and condense into crisp dots, bottom row first. Hiding plays the build backwards, a little faster, and pressing again mid-build turns it around from where it is.

### When to use it

- A share, pay or invite sheet shows a QR code and the moment it appears should feel caused by the button that was pressed.
- A device pairing or sign-in screen reveals a code and a plain fade feels too quiet.
- You need a styled, scannable QR code in React with no image or server step.

### Accessibility

The canvas is an image labelled with the encoded value while the code is shown, and hidden from assistive technology while it is not. It never takes focus; the control that shows it is yours. With reduced motion nothing moves, turns or grows, and the code fades in over 200ms.

### FAQ

**Where do the dots come from?**

Swarm starts at the bottom centre and Ripple at the centre; Scan always sweeps from the top and Smoke always rises from below. Pass origin as fractions of the canvas, such as { x: 0.5, y: 1 }, to start from where your button sits.

**Can I change the size and colours?**

Set size in px; the dots snap to whole pixels at any size. ink and paper take any CSS colour. Keep the paper light and the ink dark so phone cameras can read it.

## Source

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