API reference
Every prop, type, helper, and HTTP API param, in one place.
QRCodeProps
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Data to encode (required) |
size | number | 256 | Width and height of the SVG in pixels |
margin | number | 4 | Quiet zone in modules |
dotStyle | DotStyle | 'square' | Style of data modules |
dotColor | string | '#000000' | Color of data modules |
backgroundColor | string | '#ffffff' | Background — 'transparent' accepted |
corner | CornerOptions | — | Finder pattern corner styles |
logo | LogoOptions | — | Logo in center |
qr | QROptions | — | QR encoding options |
className | string | — | CSS class on <svg> |
style | CSSProperties | — | Inline style on <svg> |
ariaLabel | string | — | Accessible label for the SVG; defaults to 'QR code: {value}' |
DotStyle
| Value | Description |
|---|---|
'square' | Full square (default) |
'circle' | Full circle |
'rounded' | Rounded; adjacent modules connect smoothly (fluid/snake effect) |
CornerOptions
interface CornerOptions {
dot?: {
style?: 'square' | 'rounded' | 'circle'; // inner 3×3 block
color?: string;
};
square?: {
style?: 'square' | 'rounded' | 'extra-rounded' | 'circle'; // outer 7×7 ring
color?: string;
};
}When corner.square.style is 'extra-rounded' and corner.dot.style is unset, the dot defaults to 'rounded'. When corner.square.style is 'circle', the dot defaults to 'circle'.
LogoOptions
interface LogoOptions {
src?: string; // https, relative path, blob:, or data:image/… URI
element?: ReactNode; // takes priority over src when both provided
size?: number; // 0–1 relative to max safe area; ECL auto-picked; default 0.4
margin?: number; // space between logo and edge of cleared area; default 0
hideDots?: boolean; // clear dots behind logo area; default true
}ECL is auto-picked based on size: ≤ 0.25 → L (≤ 15% width), ≤ 0.44 → M (≤ 20%), ≤ 0.69 → Q (≤ 25%), ≤ 1.0 → H (≤ 30%). If errorCorrectionLevel is set explicitly, the size is clamped to that ECL's safe limit. Aspect ratio is auto-detected — landscape logos get a proportionally reduced height so they never overflow the QR.hideDots uses an SVG mask, so transparent backgrounds are fully supported.
Security: javascript: and non-image data: URIs in src are silently rejected. Never pass unsanitised user input as element — it renders verbatim inside <foreignObject>.
QROptions
interface QROptions {
errorCorrectionLevel?: 'L' | 'M' | 'Q' | 'H'; // default: 'M'
version?: number; // 1–40, auto by default
}| Level | Recovery | Use when |
|---|---|---|
L | ~7% | Clean environments, minimal data |
M | ~15% | General purpose (default) |
Q | ~25% | Industrial / harsh conditions |
H | ~30% | QR codes with a center logo |
Export Helpers
import { toSVGString, toDataURL } from '@ttsalpha/qrcode';
// Server-side SVG string — no DOM needed
const svg = toSVGString({ value: 'https://example.com', size: 512 });
// PNG data URL via Canvas (browser-only)
const png = await toDataURL({ value: 'https://example.com', size: 512 });
// JPEG with quality
const jpg = await toDataURL(
{ value: 'https://example.com', size: 512 },
{ format: 'jpeg', quality: 0.9 },
);
// Download link
const link = document.createElement('a');
link.href = await toDataURL({ value: 'https://example.com' });
link.download = 'qrcode.png';
link.click();toSVGString accepts the same props as <QRCode> and returns a static SVG markup string — useful for SSR, saving to a database, or copying to clipboard.toDataURL is browser-only (requires the Canvas API). JPEG automatically fills a white background when backgroundColor is 'transparent'.
| Option | Type | Default | Description |
|---|---|---|---|
format | 'png' | 'jpeg' | 'png' | Output image format |
quality | number (0–1) | browser default | JPEG quality. Ignored for PNG |
HTTP API — /qr
Render a QR straight from a URL, no install needed. Paste the link into any <img> tag, email, or doc. Pick the format with format=svg|png|jpg and pass colors as plain hex (color=14b8a6). The quickest way to build one: configure it in the playground and hit “Copy link”. Output is deterministic per URL and cached on the CDN.
<!-- SVG (default) -->
<img src="https://qrcode.ttsalpha.com/qr?data=https://example.com" alt="QR code" />
<!-- PNG output -->
<img src="https://qrcode.ttsalpha.com/qr?data=Hello&dot=rounded&color=14b8a6&format=png" />
<!-- With a center logo -->
<img src="https://qrcode.ttsalpha.com/qr?data=https://example.com&logo=https://example.com/logo.png" />| Param | Type | Default | Description |
|---|---|---|---|
data | string | — | Content to encode (required) |
format | 'svg' | 'png' | 'jpg' | 'svg' | Output image format |
size | number (64–2048) | 256 | Image size in px |
margin | number (0–20) | 4 | Quiet zone in modules |
dot | 'square' | 'circle' | 'rounded' | 'square' | Data module style |
color | rrggbb | 000000 | Data module color |
bg | rrggbb | 'transparent' | ffffff | Background color |
frame | 'square' | 'rounded' | 'extra-rounded' | 'circle' | 'square' | Finder frame style |
frameColor | rrggbb | color | Finder frame color |
eye | 'square' | 'rounded' | 'circle' | derived | Finder center style |
eyeColor | rrggbb | color | Finder center color |
ecl | 'L' | 'M' | 'Q' | 'H' | M * | Error correction level (* raised automatically when a logo is set) |
version | number (1–40) | auto | QR version |
logo | url | — | Center logo image URL |
logoSize | number (0–1) | 0.4 | Logo size relative to QR |
logoMargin | number | 0 | Space around the logo |
logoClear | boolean | true | Clear QR dots behind the logo |