Ballmac UI home

QR Code

A QR code drawn as accessible SVG: square, rounded or dotted modules that keep scannable corner markers, a logo slot, error-correction levels, a clear message when text is too long, and PNG and SVG downloads.

QR code for https://ui.ballmac.com/components/qr-code

Point a phone camera at it to open the page.

Installation

$ pnpm dlx shadcn@latest add @ballmac/qr-code

Usage

import { QRCode } from "@/components/ballmac/qr-code"

The full example is in the Code tab above.

Examples

Shapes

QR code for https://ui.ballmac.com
Square
QR code for https://ui.ballmac.com
Rounded
QR code for https://ui.ballmac.com
Dots
QR code for the Ballmac presets page

Wi-Fi code, live

Error correction
QR code to join Studio Guest

Nothing to encode

Nothing to encode yet

Too long

API reference

PropTypeDefault
value*

What the code holds: a web address, text, a Wi-Fi string or anything else.

string—
size

Pixel size of the whole code, quiet zone included.

number192
level

How much damage it survives: L 7%, M 15%, Q 25%, H 30%. More makes a denser code. A logo raises it to at least Q.

QRCodeLevel"M"
shape

Shape of the dark modules. The three corner squares keep their own style so scanners find them.

QRCodeShape"square"
quietZone

Empty modules around the code. Scanners need at least 4.

number4
foreground

Dark color. Codes scan best dark on light, so the defaults stay that way in dark mode. Any CSS color.

string"rgb(0, 0, 0)"
background

Light color.

string"rgb(255, 255, 255)"
logo

Something drawn in the middle, such as a logo. Its area is cleared.

React.ReactNode—
logoSize

Share of the width the logo takes, up to 0.3.

number0.22
label

Names the code for screen readers. Defaults to "QR code for {value}".

string—
onError

Called when the value cannot be encoded.

(error: Error) => void—
svgRef

The SVG element, for downloads.

React.Ref<SVGSVGElement>—

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
Screen readersThe code is an image named "QR code for …"; label replaces the name when the value is long or private
Always give a text alternativeShow the link or code as text near the picture, for people who cannot scan

Quality scorecard

8/8

Every applicable check passes

Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.0.0, across 6 examples.

How we measure
  • Passed: Accessibility scan

    No serious or critical issues in light and dark, on a phone and a desktop (axe-core 4.13.0, WCAG 2.1 AA and best-practice rules).

  • Passed: Small screens

    No sideways scrolling at 360, 390 or 1280 px wide.

  • Passed: Reduced motion

    No endless animation to begin with.

  • Passed: Right to left

    Mirrors correctly in Arabic, Hebrew, Persian and Urdu layouts (0% of elements off the mirror, limit 15%).

  • Passed: Clean console

    No console errors or React hydration errors while loading.

  • Passed: Keyboard

    8 tab stops, each showing a visible change when it takes focus. 2 documented keys.

  • Passed: Loading, empty and error

    Ships empty, error states, each with an example.

  • Passed: Automated tests

    Covered by qr-code.test.tsx.

  • For information: Footprint

    4.3 KB of source (gzip) in 1 file. Installs uqr.

Automated checks find a subset of problems and do not replace testing with a screen reader and a keyboard in your own app. What they miss.

Use with AI

<QRCode value="https://…" size={192} />. shape is square, rounded or dots; level is L, M, Q or H; logo is a node drawn in the middle. Use svgRef with downloadQRCode(svg, { format }) for a save button. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI QR Code (@ballmac/qr-code) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Sharing a link, a Wi-Fi network, a ticket or a pairing code to a phone
  • Download or print screens that need a crisp code at any size
  • A branded code with a logo in the middle

Not for

  • Reading or scanning codes; this only draws them
  • Very long text; shorten it first (a link shortener or an id)
  • A barcode of another kind; this is QR only

Registry JSON: https://ui.ballmac.com/r/qr-code.json

Credits

Based on uqr, adapted by Ballmac. Free to use in personal and commercial projects.

Ballmac UI Pro

Need the whole screen, not one piece?

150 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.

Not ready? Try three Pro blocks free

Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.