NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
QR for Laravel

SVG output & styling

Output is SVG only: one even-odd <path> in module units with an exact viewBox, an accessible title and description, and no IDs or timestamps — so it is deterministic, yields a stable ETag, and duplicates safely on one page:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 29 29" width="256" height="256" role="img" aria-label="QR code" shape-rendering="crispEdges"><title>QR code</title><desc>…</desc><rect width="29" height="29" fill="#ffffff"/><path fill="#000000" fill-rule="evenodd" d="M4 4h7v7h-7z…"/></svg>

Styles

use RoundlyConsulting\Qr\Enums\{FinderStyle, ModuleStyle};

// Rounded modules read less reliably — pair them with Q or H
Qr::url($link)->moduleStyle(ModuleStyle::Rounded, 0.35)->errorCorrection('Q')->svg();

// Dots with rounded, coloured finders
Qr::url($link)
    ->moduleStyle(ModuleStyle::Dots)
    ->finderStyle(FinderStyle::Rounded, '#0a58ca')
    ->errorCorrection('H')
    ->svg();

// Responsive, inherits the text colour, no background rectangle
Qr::url($link)->size(null)->foreground('currentColor')->background('transparent')->svg();
  • ModuleStyle::Square — traced outlines with crisp edges (the default).
  • ModuleStyle::Rounded — convex corners become quarter arcs of the given radius (0 < r ≤ 0.5 modules).
  • ModuleStyle::Dots — one circle per dark module.
  • FinderStyle::Rounded — rounded finder rings and centres, optionally in their own colour.
  • Colours — hex, rgb()/rgba(), CSS named colours, currentColor; transparent omits the background rectangle.
  • size(null) — a responsive SVG with viewBox only, sized by your CSS.

Styling guidance

Keep strong contrast (dark on light), a quiet zone of 4 modules and an opaque background. Rounded modules, dots and coloured finders read less reliably; use error correction Q or H with them. Payment codes should stay square and black on white.

The Svg value object

use RoundlyConsulting\Qr\Enums\DataUriEncoding;

$svg = Qr::url($link)->svg();

$svg->toString();                                  // the markup
$svg->withXmlDeclaration()->toString();            // prefixed with <?xml …?>
$svg->withAttributes(['class' => 'qr', 'aria-hidden' => 'true']);
$svg->toImgTag('Scan me', ['class' => 'w-32']);    // HtmlString: <img src="data:…">
$svg->toDataUri();                                 // percent-encoded data URI
$svg->toDataUri(DataUriEncoding::Base64);          // base64 data URI
$svg->etag();                                      // quoted SHA-256 prefix
$svg->width();                                     // ?int — null when responsive
$svg->viewBoxSize();                               // modules, quiet zone included
$svg->matrix();                                    // QrMatrix
$svg->sensitivity();                               // Sensitivity

Extra attributes are allow-listed (class, style, id, data-*, aria-*) and escaped; an existing key such as aria-label is replaced. Text and colours pass through escaping and an allow-list, so page content can’t inject scripts into the image.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.