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.
Installation
npx shadcn@latest add @minidev/qr-code
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/qr-code.json
Usage
import { QrCode } from "@/components/ui/qr-code"
export function Example() {
return (
<QrCode />
)
}
Exports QrCode encodeQr
API reference
| Prop | Type | Default |
|---|---|---|
| valueText to encode, as UTF-8 bytes. URLs, Wi-Fi strings, payment payloads, anything. | string | "https://ui.minidev.pro" |
| sizeRendered width and height in px. The SVG scales without blur. | number | 200 |
| levelError correction level. L 7%, M 15%, Q 25%, H 30% of codewords recoverable. The logo well needs H. | QrLevel | "M" |
| fgModule colour. Any CSS colour; defaults to the current text colour so it follows your tokens. | string | "currentColor" |
| bgBackground colour behind the modules and quiet zone. | string | "transparent" |
| marginQuiet zone in modules on each side. The spec asks for 4; 2 is fine on a plain surface. | number | 2 |
| logoScaleWidth of the cleared centre well as a fraction of the symbol, used when a logo is passed. | number | 0.24 |
| maskForce a mask pattern (0 to 7) instead of picking the lowest penalty one. | number | - |
| captionCaption under the code. Defaults to the host of a URL value or the value itself. Pass an empty string to hide. | string | - |
| downloadShow the Download SVG button. | boolean | true |
| fileNameFile name for the download. | string | "qr-code.svg" |
| bareRender the bare SVG with no card, caption or button. | boolean | false |
| titleAccessible name. Defaults to "QR code for <value>". | string | - |
| childrenLogo or icon placed in a cleared centre well. Only rendered when `level` is "H". | React.ReactNode | - |
| className | string | - |
Accessibility
- The SVG is
role="img"witharia-labelfromtitle, or "QR code for {value}" by default. Pass a shortertitlewhen the value is a long URL or a token. - The logo well is
aria-hidden. The caption is truncated with the full value in itstitletooltip. - The download button is
aria-live="polite", so the change to "Saved" is announced.
Frequently asked questions
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.
Dependencies
npm
Built from
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.
Error correction levels
L to H trade density for damage tolerance; the same URL needs more modules at each step.
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.