Skip to main content
Urbicon UI

QRCode

Renders any text or URL as a scannable QR code. The output is a self-contained SVG with no runtime dependency, whether you encode a URL, a short text string, or a 2FA enrolment URI.

Playground

Error correction
Size
Frame
<QRCode
  frame="card"
  value="https://ui.urbicon.de"
/>

01 Examples

Basic — encode a URL

Pass any string to value. The card frame keeps the code on a light background so it scans reliably in any theme.
<QRCode value="https://ui.urbicon.de" frame="card" />

Error-correction levels

L≈7%, M≈15%, Q≈25%, H≈30% of the code can be damaged or occluded and still decode. Higher recovery uses more modules, so the pattern grows denser from L to H.
L
M
Q
H
{#each ['L', 'M', 'Q', 'H'] as level}
  <QRCode value="https://ui.urbicon.de" errorCorrection={level} size={120} frame="card" />
{/each}

Sizes

size is the rendered edge length in pixels. The code is a single SVG path, so it stays crisp at any size.
120px
160px
220px
{#each [120, 160, 220] as px}
  <QRCode value="https://ui.urbicon.de" size={px} frame="card" />
{/each}

Custom colours

foreground and background accept any CSS colour string. Keep a high-contrast dark-on-light pairing so scanners stay reliable.
<QRCode
  value="https://ui.urbicon.de"
  foreground="#1e3a5f"
  background="#f8fafc"
  frame="card"
/>

02 2FA & auth

Pass a TOTP enrolment URI straight to <QRCode> and an authenticator app (Google Authenticator, 1Password, …) scans it to register the shared secret. This replaces an external QR library in TwoFactorManager's qr snippet.

Use errorCorrection="H" here: the extra recovery data keeps the code readable when it is scanned at an angle or across a second device. Never echo the secret into aria-label: the visible code already contains it, and the label is read aloud and exposed in the accessibility tree.

Encode an otpauth:// enrolment URI

High error correction and the card frame keep this reliable to scan from a second device during setup.
<QRCode
  value="otpauth://totp/Urbicon:alice@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Urbicon&period=30"
  errorCorrection="H"
  size={200}
  frame="card"
/>

03 Encoding capacity & errors

The smallest QR version (1–40) that fits your data is chosen automatically, along with the most efficient mode for it (numeric, alphanumeric, or UTF-8 byte). You do not pick a version yourself.

Bound the size with maxVersion when a code has to stay physically small. Data that overflows that bound calls onError and renders a visible fallback in place of the code, so the surrounding page keeps rendering. Type past the maxVersion=4 capacity below to see the fallback.

Live capacity demo

The bound value is encoded on every change. When it overflows maxVersion=4, onError fires and the fallback shows in place of the code.
<script>
  let payload = $state('https://ui.urbicon.de/docs');
</script>

<Textarea label="Payload" bind:value={payload} />
<QRCode value={payload} maxVersion={4} frame="card" onError={(e) => console.warn(e.message)} />

04 Accessibility

One named image

Renders as role="img" with an aria-label that defaults to a localized "QR code" and is overridable per instance.

Never echo a sensitive payload

Never echo sensitive payloads (a 2FA secret, a signed token) into aria-label: it is announced aloud and exposed in the accessibility tree.

Contrast and scannability

For guaranteed scannability keep high-contrast dark-on-light modules. frame="card" supplies the light ground; the default foreground is currentColor, so an unframed code inherits the surrounding text colour.

The failure state stays labelled

When encoding fails, the visible fallback also carries role="img" with the same label, so assistive tech is never left with an empty region.

05 API Reference

16 props
16 props 1 required
Prop
Type
Default
Description

06 Types

Local type definitions used by this component.

5 types
Name
Kind
Category
Used by
Description

07 Installation

Import

import { QRCode } from '@urbicon-ui/blocks';