Skip to content

SVG string renderer

Use QRCodeSVGRenderer for scalable output in web pages, email, print, generated assets, or HTTP responses. It is the recommended default when the consumer accepts SVG text.

import {QRCodeSVGRenderer, qrcode} from '@qrcodesdk/core';
const svg = qrcode('https://qrcodesdk.dev').render(QRCodeSVGRenderer());

Learn here more about using the SVG string in the browser.

The renderer returns a complete SVG string with an explicit width, height, and viewBox. A non-empty accessible name adds role="img"; decorative output has no image role. Output with only square shapes uses shape-rendering="crispEdges"; curved styles omit that hint.

QRCodeSVGRendererOptions accepts style, accessibility, and centerImage. It rejects every other key.

Option Type Default Effect
style QRCodeVisualStyle shared defaults Applies graphical dimensions, colors, and shapes
accessibility.ariaLabel string undefined Sets aria-label and meaningful image semantics
accessibility.title string undefined Adds a child <title> element
centerImage.source QRCodeDataImageURL required with centerImage Embeds a prepared data:image/... URL
centerImage.size number 0.4 Image box as a fraction of matrix width
centerImage.padding number 1 Clear padding measured in modules
centerImage.clearBackground boolean true Clears modules behind the image and padding
  • centerImage.source must be a non-empty embedded image data URL. The renderer does not read paths or fetch remote URLs.
  • SVG does not accept accessibility.alt; use ariaLabel and optionally title.
  • Image size must be finite, greater than 0, and at most 1; padding must be finite and non-negative.
  • Options are validated and copied when QRCodeSVGRenderer() is called.
  • The renderer is runtime-neutral under the Core compatibility contract.