Skip to content
Haze UI

QR code

A scannable QR code drawn as one server-rendered SVG path, with error correction levels and a readable value.

pnpm dlx shadcn@latest add @haze/qr-code
Open preview in a new tab
Liveno JavaScript

When to use

  • A phone should open a link, invoice or pairing URL by scanning the screen
  • The code must render without client JavaScript or an image service
  • The encoded text must also stay readable for people who cannot scan

When not to use

  • The payload is longer than a few hundred characters. Link to a short URL instead.
  • Users need to copy a link on the same device. Use a plain link or copy-button.

Installation

Add the Haze registry to components.json once, then install QR code with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/qr-code
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
valuestring"https://pay.northwind.example/inv/2048"Text to encode as UTF-8 bytes. The smallest version from 1 to 40 that fits is chosen. Over capacity (2953 bytes at L, 1273 at H) throws a build error.
level"L" | "M" | "Q" | "H""M"Error correction: about 7, 15, 25 or 30 percent of the codewords can be damaged. Higher levels make denser codes.
sizenumber160Width and height in px, including the quiet zone. The SVG shrinks to fit narrow containers.
labelstring–Accessible name. Defaults to "QR code" while the value is printed below, and to "QR code for <value>" when showValue is false.
captionstring–Instruction shown under the code, such as what scanning does.
showValuebooleantrueShow the encoded text under the code so it can be read and copied.
classstring–Additional classes on the figure.

Accessibility

  • The SVG has role img and a label. A QR code is not readable by screen readers, so the encoded value is printed as selectable text by default.
  • Modules are always dark on a light panel, in both themes, because many scanners fail on inverted codes. The panel includes the 4-module quiet zone.
  • Keep the code at least 120 px wide for phone cameras; raise the level only when the code may be partly covered or worn.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "QR code" with `npx shadcn@latest add @haze/qr-code`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import QrCode from "@/components/haze/ui/qr-code.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/qr-code.md

  • Customize with real content

    Adapt the Haze qr-code ui for our product. Replace the demo values of these props with our real content: value, level, size, label, caption, showValue, class. Keep the layout, the heading level rules and these accessibility details: The SVG has role img and a label. A QR code is not readable by screen readers, so the encoded value is printed as selectable text by default. Modules are always dark on a light panel, in both themes, because many scanners fail on inverted codes. The panel includes the 4-module quiet zone. Keep the code at least 120 px wide for phone cameras; raise the level only when the code may be partly covered or worn. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using qr-code, check it fits: use it when a phone should open a link, invoice or pairing url by scanning the screen; the code must render without client javascript or an image service; the encoded text must also stay readable for people who cannot scan. Avoid it when the payload is longer than a few hundred characters. link to a short url instead.; users need to copy a link on the same device. use a plain link or copy-button.. Alternatives: @haze/copy-button.

Dependencies

  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog