QR Code
Encodes a string as a QR code in the browser and draws it as inline SVG. Follows your text color, with an optional white card for dark backgrounds.
<arc-qr-code>Overview
QRCode encodes a URL, a Wi-Fi string, a 2FA provisioning URI or any other string in the browser and renders it as inline SVG, with no canvas, image request or server call. All the dark modules are joined into one <path> drawn with shape-rendering="crispEdges", so the DOM stays small and the code scales to any size.
The modules use --qr-fg if you set it and currentColor otherwise, which defaults to --text-primary. The background is --qr-bg, transparent by default. Set either custom property to change them.
The QR standard draws dark modules on a light background, and not every scanner reads the reverse. On ARC's dark theme the default rendering is light modules on a dark surface, an inverted code. contrast draws black modules on a white rounded card in both themes and ignores --qr-fg and --qr-bg. Set it when the code has to scan on the dark theme.
The code re-encodes whenever value or level changes, and renders nothing when value is empty or too long for a QR code at that level. The SVG has role="img" and takes its accessible name from label, or "QR code" without one. The value itself is never exposed to assistive technology, because it may be a secret like a 2FA URI or a token.
Guidelines
Do
- Write a `label` that says what the code does ("Scan to open the event page"), not the value. Assistive technology reads the label, and the value may be a secret
- Use level M (the default) for most content. Step up to Q or H only when part of the code may be covered or worn, as with a logo overlay or a printed code
- Keep values short. Shorter strings make fewer modules, which scan faster and from further away
- Keep codes at the default 160px or larger when another device has to scan them
- Show the same link as text or with a copy button for people who can't scan
Don't
- Don't encode long strings. Level M holds about 2.3KB at most, and a code gets hard to scan at usual sizes well before that
- Don't set `--qr-fg` and `--qr-bg` to colors of similar lightness. Scanners need strong dark-on-light contrast
- Don't set `quiet-zone` below 2 when the code is next to busy content
Features
- Encoding by the qrcode-generator library (MIT, no dependencies of its own)
- Four error-correction levels (L, M, Q, H) and automatic version (size) selection
- `quiet-zone` sets the width of the empty border around the code, in modules
- Parts: `base`, `svg`, `card`
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<script type="module" src="@arclux/arc-ui"></script>
<!-- Themed code (inherits currentColor) -->
<arc-qr-code value="https://arcui.dev" label="ARC UI website"></arc-qr-code>
<!-- Guaranteed scanability in both themes -->
<arc-qr-code
value="https://arcui.dev"
label="ARC UI website"
contrast
></arc-qr-code>
<!-- High error correction + custom colors -->
<arc-qr-code
value="WIFI:T:WPA;S:Arclight;P:hunter2;;"
label="Wi-Fi network credentials"
level="H"
size="200"
style="--qr-fg: var(--accent-primary); --qr-bg: var(--surface-raised);"
></arc-qr-code>import { QrCode } from '@arclux/arc-ui-react';
export function SharePanel({ url }: { url: string }) {
return (
<QrCode value={url} label="Scan to open this page" size={200} contrast />
);
}<script setup>
import { QrCode } from '@arclux/arc-ui-vue';
</script>
<template>
<QrCode value="https://arcui.dev" label="ARC UI website" :size="200" contrast />
</template><script>
import { QrCode } from '@arclux/arc-ui-svelte';
</script>
<QrCode value="https://arcui.dev" label="ARC UI website" size={200} contrast />import { Component } from '@angular/core';
import { QrCode } from '@arclux/arc-ui-angular';
@Component({
imports: [QrCode],
template: `
<arc-qr-code value="https://arcui.dev" label="ARC UI website" size="200" contrast />
`,
})
export class SharePanelComponent {}import { QrCode } from '@arclux/arc-ui-solid';
export function SharePanel() {
return (
<QrCode value="https://arcui.dev" label="ARC UI website" size={200} contrast />
);
}import { QrCode } from '@arclux/arc-ui-preact';
export function SharePanel() {
return (
<QrCode value="https://arcui.dev" label="ARC UI website" size={200} contrast />
);
}API
valuestring''- The content to encode (URL, text, Wi-Fi string, 2FA URI, …). Empty values render nothing. Values exceeding QR capacity for the chosen level also render nothing.
sizenumber160- Rendered width and height of the SVG in pixels. The code is vector-based and stays crisp at any size.
labelstring''- Accessible description announced to screen readers (falls back to "QR code"). Describe the purpose, not the encoded value. The value is never exposed by default since it may be a secret.
level'L' | 'M' | 'Q' | 'H''M'- Error-correction level: L (~7% recovery), M (~15%), Q (~25%), H (~30%). Higher levels tolerate more damage/occlusion but produce denser codes.
quietZonenumber2- Width of the empty border around the code, measured in modules. Scanners rely on this margin to find the code; keep at least 2 against busy backgrounds.
contrastbooleanfalse- Renders the code on a white rounded card with forced dark modules, guaranteeing dark-on-light scanability in both themes. Overrides --qr-fg/--qr-bg. Recommended for scan-critical codes.