Web · Components
QRCode
Draws text or a URL as a QR code (SVG).
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
Draws text or a URL as a QR code (SVG). The encoder is the library's own; no external package. It is a server component: the code is generated on the server and only a single SVG path goes to the browser.
- Picks the smallest code for the text type (numeric, uppercase, UTF-8); non-ASCII characters are encoded correctly.
- Square, rounded or dotted look with
shape. - Logo in the center with
image; the level becomesHautomatically. - By default black modules on a white background; high contrast is kept whatever the theme (readers expect dark-on-light). On a transparent background modules take the text color. To download, serialize the SVG element to a string with
XMLSerializer.
Examples
encodeQR
functionConverts text into a QR code: picks the smallest fitting version and (when omitted) the most readable mask. Digits-only text uses numeric mode, uppercase plus $%*+-./: uses alphanumeric mode (smaller code); other text is encoded as UTF-8 (including non-ASCII characters).
Examples
QRErrorLevel
typeError correction level: how much of the code can be damaged and still be read.
L: ~7% (densest, smallest code)M: ~15% (general use)Q: ~25%H: ~30% (when a logo goes in the middle)
QRMatrix
interfaceEncoded QR matrix.
| Name | Type | Description |
|---|---|---|
size | number | Side length (modules). |
version | number | Version (1–40). |
level | QRErrorLevel | Error correction level used. |
mask | number | Chosen mask (0–7). |
modules | boolean[][] | Modules row by row: modules[y][x] is true when dark. |
EncodeQROptions
interfaceencodeQR options.
| Name | Type | Default | Description |
|---|---|---|---|
level? | QRErrorLevel | "M" | Error correction level. |
minVersion? | number | 1 | Minimum version (1–40). |
mask? | number | Mask (0–7). The most readable one is chosen when omitted. |
QRCodeStyle
typeShape of the modules (squares).
square: classic squares; the most compatible with every reader.rounded: squares with softened corners, finders with rounded corners.dots: dots and round finders.
QRCodeProps
interfaceProps of the QRCode component.
Extends: Omit<ComponentProps<"svg">, "children" | "style" | "color">
| Name | Type | Default | Description |
|---|---|---|---|
value | string | Text or URL to encode. | |
level? | QRErrorLevel | "M"`, `"H"` if `image` is given | Error correction level. See QRErrorLevel. |
size? | number | 160 | Width and height (px). Can also be given with a class (size-40). |
margin? | number | 2 | Quiet zone around the code (modules). At least 2–4 is recommended for readers. |
shape? | QRCodeStyle | "square" | Module shape. See QRCodeStyle. |
color? | string | "#000"`, `"currentColor"` if `background="transparent" | Color of dark modules (CSS). With a background the default is black; it isn't bound to the theme text color (light gray in dark theme), so the code reads in every theme. On a transparent background the text color (currentColor) is used. |
background? | string | "#fff" | Background color (CSS). "transparent" leaves it transparent. |
image? | string | Logo placed in the center (image URL). Modules behind it are cleared; the level becomes "H" automatically for readability. | |
imageSize? | number | 0.22 | Side length of the logo as a fraction of the code (0–0.3). |
label? | string | value | Screen reader name. |
minVersion? | EncodeQROptions["minVersion"] | Minimum version (1–40); to fix the size of the code. |