# Qr Code

> React QR code component with its own encoder: versions 1 to 40, four error correction levels, crisp SVG in currentColor, a logo well and an SVG download.

- Kind: Component (Media)
- Docs: https://ui.minidev.pro/docs/qr-code
- Source (registry JSON with the full file): https://ui.minidev.pro/r/qr-code.json
- License: MIT. One file, yours to edit after install.

## Installation

### shadcn CLI (copies the source into your project)

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

Writes `components/ui/qr-code.tsx` plus the MiniDev files it is built from (button) and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/qr-code.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { QrCode, encodeQr } from "@/components/ui/qr-code"
```

From the npm package:

```tsx
import { QrCode } from "minidev-ui-kit/ui/qr-code"
```

## Usage

```tsx
import { QrCode } from "@/components/ui/qr-code"

export function Example() {
  return (
    <QrCode />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `value` | `string` | `"https://ui.minidev.pro"` | no | Text to encode, as UTF-8 bytes. URLs, Wi-Fi strings, payment payloads, anything. |
| `size` | `number` | `200` | no | Rendered width and height in px. The SVG scales without blur. |
| `level` | `QrLevel` | `"M"` | no | Error correction level. L 7%, M 15%, Q 25%, H 30% of codewords recoverable. The logo well needs H. |
| `fg` | `string` | `"currentColor"` | no | Module colour. Any CSS colour; defaults to the current text colour so it follows your tokens. |
| `bg` | `string` | `"transparent"` | no | Background colour behind the modules and quiet zone. |
| `margin` | `number` | `2` | no | Quiet zone in modules on each side. The spec asks for 4; 2 is fine on a plain surface. |
| `logoScale` | `number` | `0.24` | no | Width of the cleared centre well as a fraction of the symbol, used when a logo is passed. |
| `mask` | `number` | - | no | Force a mask pattern (0 to 7) instead of picking the lowest penalty one. |
| `caption` | `string` | - | no | Caption under the code. Defaults to the host of a URL value or the value itself. Pass an empty string to hide. |
| `download` | `boolean` | `true` | no | Show the Download SVG button. |
| `fileName` | `string` | `"qr-code.svg"` | no | File name for the download. |
| `bare` | `boolean` | `false` | no | Render the bare SVG with no card, caption or button. |
| `title` | `string` | - | no | Accessible name. Defaults to "QR code for <value>". |
| `children` | `React.ReactNode` | - | no | Logo or icon placed in a cleared centre well. Only rendered when `level` is "H". |
| `className` | `string` | - | no |  |

## Examples

### With a logo

Level H clears a well in the middle for whatever you pass as children; the code still scans because 30 percent of it is redundant.

```tsx
<QrCode value="https://lumen.app/pay/INV-2041" level="H" caption="Pay invoice INV-2041" fileName="inv-2041-qr.svg">
  <span className="grid size-full place-items-center rounded-md bg-ink text-sm font-semibold text-on-ink">L</span>
</QrCode>
```

### Error correction levels

L to H trade density for damage tolerance; the same URL needs more modules at each step.

```tsx
<QrCode value="https://ui.minidev.pro" level="L" size={112} caption="Level L, 7%" download={false} />
<QrCode value="https://ui.minidev.pro" level="M" size={112} caption="Level M, 15%" download={false} />
<QrCode value="https://ui.minidev.pro" level="Q" size={112} caption="Level Q, 25%" download={false} />
<QrCode value="https://ui.minidev.pro" level="H" size={112} caption="Level H, 30%" download={false} />
```

### Bare in your own card

bare drops the card, caption and button so the SVG can sit in a layout of yours, here a guest Wi-Fi string phones join on scan.

```tsx
<div className="flex items-center gap-5 rounded-xl border border-border bg-surface p-4 shadow-raised">
  <QrCode bare size={112} value="WIFI:T:WPA;S:Northwind Guest;P:welcome-2026;;" title="Join the Northwind Guest network" />
  <div className="min-w-0">
    <p className="flex items-center gap-1.5 text-sm font-medium text-fg"><WifiIcon className="size-4 text-fg-muted" /> Northwind Guest</p>
    <p className="mt-1 text-xs text-fg-muted">Scan with your phone camera to join. No password to type.</p>
    <p className="mt-2 font-mono text-xs text-fg-subtle">WPA2 · 2.4 and 5 GHz</p>
  </div>
</div>
```

## Accessibility

- The SVG is `role="img"` with `aria-label` from `title`, or "QR code for {value}" by default. Pass a shorter `title` when the value is a long URL or a token.
- The logo well is `aria-hidden`. The caption is truncated with the full value in its `title` tooltip.
- The download button is `aria-live="polite"`, so the change to "Saved" is announced.

## FAQ

### Will the code still scan with a logo in the middle?

Yes, if you set `level="H"`: the default is `"M"`, and children only render at H, which can recover 30% of the code. `logoScale` (default `0.24`) sets the cleared well, so keep the logo small and test with a phone. The downloaded SVG leaves the well empty and does not include the logo.

### Why does it say "Too long for level H"?

The value does not fit even the largest QR version at that error correction level. Higher levels store less data, so try `level="M"` or `"L"`, or shorten the value, for example with a short link.

### Does it scan in dark mode?

The modules use `currentColor`, so on a dark theme the code is light on dark, which many scanners read but not all. Pass `fg` and `bg` for dark modules on a light background. Download SVG always writes black on white unless you set them.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`
- Built from: [button](https://ui.minidev.pro/docs/button/md)

## Related

- [Two Factor Setup](https://ui.minidev.pro/docs/two-factor-setup/md): Two-factor setup card with a QR code area, a one-time code input and a Verify and enable button, guiding users through linking an authenticator app in React.
- [Audio Player](https://ui.minidev.pro/docs/audio-player/md): Minimal React audio player row with a play and pause toggle, title, subtitle and an accessible progress bar. Controlled, so it works with any audio source.
- [Avatar](https://ui.minidev.pro/docs/avatar/md): Shadcn compatible avatar on Base UI with image and initials fallback, three sizes, a status badge and an overlapping avatar group with a plus count.
- [Carousel](https://ui.minidev.pro/docs/carousel/md): Scroll snap React carousel with previous and next buttons, arrow key support and a labelled region. Shows one, two or three slides by breakpoint, no library.
- [File List](https://ui.minidev.pro/docs/file-list/md): A stacked list of file rows showing each name and metadata such as size or date, with an optional download button per item. Good for React attachment lists.
- [File Row](https://ui.minidev.pro/docs/file-row/md): A single file row with an icon, a truncated name, an optional meta line and a ghost download button with an accessible label. Styled with Tailwind.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
