QR Code

A QR code rendered as crisp, dependency-free SVG. The matrix is generated in-house, byte mode, ECC levels L through H, with automatic version and mask selection, and paints in the current text color.

QR code

Installation#

# One-time setup (tokens + lib helpers)npx koalaui-cli@latest init# Add this component (its dependencies come along)npx koalaui-cli@latest add qr-code

Usage#

usage.tsxTSX
import { QRCode } from "@/components/ui/qr-code"export function Example() {  return <QRCode value="https://koalaui.com" />}

Error correction#

level sets how much of the code can be damaged or covered while still scanning. Higher levels add redundancy, so the same data needs a denser grid. Use H when a logo sits on top or the code is printed small; M (the default) is right for screens.

QR codeL · ~7%
QR codeM · ~15%
QR codeQ · ~25%
QR codeH · ~30%

Sizing#

size sets the rendered width and height in pixels. The SVG is resolution-independent, so it stays sharp at any size; drive it per breakpoint with className if you need a responsive code.

QR codeQR codeQR code

Quiet zone#

margin is the light border around the code, measured in modules. The spec asks for at least 4 for reliable scanning; drop it lower only when the surrounding surface already supplies light padding (as the panel below does).

QR code
QR code

Color & theming#

Modules paint in currentColor over the component's background, so a code re-themes by default. You can recolor it with any text token, but keep the contrast high: scanners need the modules clearly darker (or clearly lighter) than the quiet zone. The brand-tinted example below still reads because text-brand stays well clear of the card background.

QR codeQR code

Module shape#

moduleRadius rounds each module, as a fraction of its size: 0 (the default) for sharp squares, 0.3 for a soft look, up to 0.5 for full dots. Keep it modest, heavy rounding eats into the modules and can hurt scanning.

QR code0 · default
QR code0.3 · soft
QR code0.5 · dots

In a dialog#

A QR code pairs naturally with a verification flow. See the two-factor (2FA) Dialog for a full example: a QRCode on a nested panel above an OTP Input.

API reference#

PropTypeDefault
valuestringrequired
level"L" | "M" | "Q" | "H""M"
sizenumber160
marginnumber4
moduleRadiusnumber0
titlestring"QR code"
classNamestring—

All other native svg props are forwarded to the root element.

FAQ#

No. The encoder is hand-rolled and dependency-free, matching the rest of Koala's hard primitives like Chart, Calendar, and the Command palette. It supports byte mode (UTF-8), which covers URLs, plain text, and otpauth:// URIs, and selects the smallest version and the lowest-penalty mask automatically.