QR Code

A QR code drawn as one SVG path, named for where it leads — and, from the same value, a file to download or print.

MediaExperimental

Installation

It has its own entry point, @semantic-components/ui/qr-code, built on uqr — an optional peer of ui: install it where you use the component.

ts
import { ScQrCode, qrCodeToSvg, qrCodeToBlob } from '@semantic-components/ui/qr-code';

Usage

Usage

Or open angular.dev
import { Component, ViewEncapsulation } from '@angular/core';import { ScLink } from '@semantic-components/ui';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** A code, named for where it leads — and the same link beside it, for whoever can’t scan. */@Component({  selector: 'app-qr-code-usage-demo',  imports: [ScLink, ScQrCode],  template: `    <figure class="flex flex-col items-center gap-2">

Anatomy

One part, on your svg. A file comes from the value, with a function: no component needed — an email or a printed page can have one too.

import { ScQrCode, qrCodeToBlob, qrCodeToSvg } from '@semantic-components/ui/qr-code';
<svg scQrCode value="https://angular.dev" aria-label="QR code for angular.dev"></svg>

Colours

Dark on white, in both themes: many scanners can't read a code inverted, so it doesn't follow dark mode. Recolour it with classes — the text colour for the dark modules, the background for the rest — keeping dark on light and strong contrast. A file is black on white unless you pass color and background.

Accessibility

  • It is an image: name it (aria-label) for where it leads — "QR code for angular.dev".
  • Put the same link or text beside it, for whoever can't scan.
  • A value too long to encode draws nothing; say so from error().
  • It is never mirrored right to left.

Examples

Sizes

size-24
size-36
size-52 (default)
import { Component, ViewEncapsulation } from '@angular/core';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** Sized with size-* (size-52 by default): one path, sharp at any size. */@Component({  selector: 'app-sizes-qr-code-demo',  imports: [ScQrCode],  template: `    <div class="flex flex-wrap items-end gap-6">      @for (item of sizes; track item.label) {

Colours

Blue
Green
Purple
Rose
import { Component, ViewEncapsulation } from '@angular/core';import { ScFrame } from '@semantic-components/ui';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** Its colours are classes: the text colour for the dark modules, the background for the rest — dark on light, strong contrast, in both themes. */@Component({  selector: 'app-colors-qr-code-demo',  imports: [ScFrame, ScQrCode],  template: `    <div class="flex flex-wrap gap-6">

Error correction

L — 7 %
M — 15 %
Q — 25 %
H — 30 %
import { Component, ViewEncapsulation } from '@angular/core';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** How much can be damaged and still read: L 7 %, M 15 % (the default), Q 25 %, H 30 % — more, and the code grows denser. */@Component({  selector: 'app-error-correction-qr-code-demo',  imports: [ScQrCode],  template: `    <div class="flex flex-wrap gap-6">      @for (item of levels; track item.level) {

Margin

margin 0
margin 2
margin 4 (default)
import { Component, ViewEncapsulation } from '@angular/core';import { ScFrame } from '@semantic-components/ui';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** The quiet zone round the code, in modules: 4 by default, as the QR spec asks — less, and some scanners miss it. */@Component({  selector: 'app-margin-qr-code-demo',  imports: [ScFrame, ScQrCode],  template: `    <div class="flex flex-wrap items-end gap-6">

Live

import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScButton, ScField, ScInput, ScLabel } from '@semantic-components/ui';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** Drawn as you type. A value too long to encode draws nothing and sets error(). */@Component({  selector: 'app-live-qr-code-demo',  imports: [FormField, ScField, ScLabel, ScInput, ScButton, ScQrCode],  template: `

Download

import { DOCUMENT } from '@angular/common';import { Component, ViewEncapsulation, inject } from '@angular/core';import { ScButton } from '@semantic-components/ui';import {  ScQrCode,  qrCodeToBlob,  qrCodeToSvg,} from '@semantic-components/ui/qr-code';import { SiDownloadIcon } from '@semantic-icons/lucide-icons';

Use cases

Website
Phone
Email
Wi-Fi
import { Component, ViewEncapsulation } from '@angular/core';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** What a phone opens from a code: a link, a call, an email, a Wi-Fi network — each by its URI scheme. */@Component({  selector: 'app-use-cases-qr-code-demo',  imports: [ScQrCode],  template: `    <div class="grid grid-cols-2 gap-6 md:grid-cols-4">      @for (item of useCases; track item.label) {

RTL

أو افتح angular.dev
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScLink } from '@semantic-components/ui';import { ScQrCode } from '@semantic-components/ui/qr-code';
/** In a right-to-left page: the code is never mirrored (scanners read it one way); its caption follows the page. */@Component({  selector: 'app-rtl-qr-code-demo',  imports: [Dir, ScLink, ScQrCode],  template: `

API reference

The code takes class, merged over its own (cn: a later class wins).

PartSelectorDescription
ScQrCodesvg[scQrCode] The code as one SVG path, role img: name it. Dark on white (bg-white text-black), size-52; recoloured and sized by class. exportAs scQrCode: error().
InputTypeDefaultDescription
valuestringrequired What it encodes: a URL, mailto:, tel:, WIFI:…
errorCorrection'L' | 'M' | 'Q' | 'H''M' How much can be damaged and still read: 7, 15, 25, 30 %.
marginnumber4 The quiet zone round it, in modules.
InputTypeDefaultDescription
errorCorrection, marginas the code’s'M', 4 qrCodeToSvg and qrCodeToBlob.
color, backgroundstring'#000000', '#ffffff' The dark modules’ colour, and the rest’s.
sizenumber1024 Its width in pixels, whole pixels a module.
type, qualitystring, number'image/png' qrCodeToBlob: the image type, and JPEG or WebP quality.