Skip to content
Thrum

QR code

A QR code drawn as SVG from a string: a link to open on a phone, a code to join a workspace, Wi-Fi details. The encoder is in the file, with no package. The code is black on white in both themes, because many scanners do not read a light code on a dark ground. For a value people type, show it as text next to the code as well.

Install

npx shadcn@latest add @thrum-pro/qr-code

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Props

PropTypeDefaultDescription
valuestringRequiredThe text to encode, as UTF-8 bytes. Up to 271 bytes at level L and 119 at H; past that the error state shows.
titlestringRequiredThe accessible name: what scanning the code does, such as "Open Acme invoice 2041".
sizenumberDefault 160Width and height in pixels, quiet zone included.
level"L" | "M" | "Q" | "H"Default "M"How much damage the code survives: about 7%, 15%, 25% or 30% of it. Higher levels need more modules for the same value.
marginnumberDefault 4The quiet zone around the code, in modules. Scanners expect 4; less works on a plain background.
childrenReactNode–A mark in the centre, such as a logo. The level becomes H and the modules under it are cleared: about 20% of the width.
tooLongLabelstringDefault "Too long to show as a QR code"What the error state says when the value does not fit in version 10.
classNamestring–Extra classes, merged last. A text colour class changes the module colour and a background class the ground; keep it dark on light.
...propsComponentProps<"div">–Every other div attribute is passed through.
qrMatrix()(text: string, level?: QrLevel, mask?: number) => QrMatrix | null–A second export: the encoder. It returns the version, the mask and modules[y][x], or null when the text is too long.

Motion and sound

Motion

  • The code does not move.

Sound

Silent. This component makes no sound.

Accessibility

  • The code is an image named by title, so a screen reader says what scanning it does, not the modules.
  • Modules are black on white in the light and the dark theme. A light code on a dark ground is one many scanners do not read.
  • Modules are plain squares joined into one shape, which scans best. Only the frame around the quiet zone follows the theme's radius.
  • A value that is too long shows a dashed box of the same size with the reason in words, also in the image's name.
  • Show a short value as text as well, for people who cannot scan.

Source

SourcePro

The source comes with Pro

TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies

Files and dependencies

Adds
components/ui/qr-code.tsx
Packages
None
Brings along
Nothing

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor