Skip to content
Focsd homeFocsd homeFocsd
Forms

QR code

A QR code for a link or short text, drawn as an SVG image that stays sharp at any size.

  • Tag: focsd-qr-code
  • Pattern: SVG image (role=img)
  • Category: Display

Example

HTML
<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>

API

Attributes

AttributePropertyTypeDefault
valuevaluestring—
labellabelstring—
sizesizenumberDEFAULT_SIZE
error-correctionerrorCorrectionQrErrorCorrectionM

CSS parts

Style the inside of the component with ::part(), for example focsd-qr-code::part(svg).

PartDescription
svgThe SVG image.
surfaceThe background square, quiet zone included.
modulesThe 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 when label is 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-ink and --focsd-qr-code-surface in a stylesheet rather than a style attribute.
  • 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-error with detail.reason too-long.