QR code
A QR code for a link or short text, drawn as an SVG image that stays sharp at any size.
Example
<focsd-qr-code value="https://focsd.dev" label="QR code for focsd.dev"></focsd-qr-code><focsd-qr-code value="https://focsd.dev/docs" label="QR code for the Focsd docs" size="160" error-correction="H" style="--focsd-qr-code-ink: #000; --focsd-qr-code-surface: #fff"></focsd-qr-code>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-qr-code.js';</script>
<focsd-qr-code value="https://focsd.dev" label="QR code for focsd.dev"></focsd-qr-code>import { QrCode } from '@focsd-dev/react';
export function Example() { return <QrCode value="https://focsd.dev" label="QR code for focsd.dev"></QrCode>;}<script setup>import '@focsd-dev/components/focsd-qr-code.js';</script>
<template> <focsd-qr-code value="https://focsd.dev" label="QR code for focsd.dev"></focsd-qr-code></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-qr-code.js';
// template<focsd-qr-code value="https://focsd.dev" label="QR code for focsd.dev"></focsd-qr-code><script> import '@focsd-dev/components/focsd-qr-code.js';</script>
<focsd-qr-code value="https://focsd.dev" label="QR code for focsd.dev"></focsd-qr-code>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
value | value | string | — |
label | label | string | — |
size | size | number | DEFAULT_SIZE |
error-correction | errorCorrection | QrErrorCorrection | M |
CSS parts
Style the inside of the component with ::part(), for example focsd-qr-code::part(svg).
| Part | Description |
|---|---|
svg | The SVG image. |
surface | The background square, quiet zone included. |
modules | The dark modules, drawn as one path. |
Accessibility
- The code is one image named by
label. Say where the code leads ("QR code for focsd.dev") rather than "QR code"; the element warns once in the console whenlabelis missing. - Show the link or text next to the code too: not everyone can scan one.
- Colors follow the theme, so dark themes draw a light-on-dark (reversed) code, which some scanners refuse. For print or scanning set
--focsd-qr-code-ink: #000; --focsd-qr-code-surface: #fff. - Pages with a strict style policy (no inline styles) set
--focsd-qr-code-inkand--focsd-qr-code-surfacein a stylesheet rather than astyleattribute. - In forced colors the code stays black on white, since a code drawn in system colors may not scan.
- A value too long for any QR code draws an empty image that keeps its name and fires
focsd-errorwithdetail.reasontoo-long.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.