qr-code

QR code generator web component with progressive enhancement. Shows text content before JS, then renders a scannable QR code.

Overview

The <qr-code> component generates a QR code from text or a URL. It uses progressive enhancement: the text content is visible before JavaScript loads, then replaced with a scannable QR code canvas.

Attributes

Attribute Type Default Description
value string textContent Text or URL to encode. Falls back to element text content.
size number 200 Canvas size in pixels.
color CSS color currentColor Foreground (module) color.
background CSS color transparent Background color.
error-correction 0–3 1 (M) Error correction level: 0=L, 1=M, 2=Q, 3=H.

Custom Sizes

Small
100px
Medium
200px (default)
Large
300px

Custom Colors

Override the foreground and background colors to match your brand.

https://example.com

JavaScript API

Method Returns Description
toDataURL(type?) string Get the QR code as a data URL for download or embedding.

Progressive Enhancement

Without JavaScript, the text content inside the element remains visible as a readable fallback. This means the URL or text is always accessible, even if the QR code can’t render.

Accessibility

  • The canvas element gets role="img" with an aria-label describing the QR content.
  • The original text serves as a fallback for non-visual users.