<x-qr-code> Blade component is the simplest way to display QR codes directly in your templates. Pass your content as the data prop, add any styling options you need, and the component takes care of the rest — including accessibility attributes, inline SVG rendering, and base64-encoded image embedding for PNG and WebP output.
Basic usage
size and margin, the component inherits its dimensions from config/qrcode.php (default size of 400 px and quiet zone margin of 4 modules). You do not need PHP imports or extra configuration because the package’s service provider registers the component automatically.
Available props
The payload to encode. This is the only required prop. Pass any string: a URL,
plain text, a phone number, etc.
Width and height of the QR code in pixels. When you omit
size or pass null, the component inherits size from config/qrcode.php (package default 400).Foreground color as a hex string (e.g.
#ff0000) or a comma-separated RGB
value (e.g. 255,0,0).Quiet-zone margin around the QR code in module units. When you omit
margin or pass null, the component inherits margin from config/qrcode.php (package default 4 quiet-zone modules).Error correction level:
L (7 %), M (15 %), Q (25 %), or H (30 %).
Defaults to the value in config/qrcode.php (package default M).A gradient color pair as two hex or RGB values separated by
; (e.g.
#0000ff;#ff0000). The component maps the pair to start and end colors.Absolute file path to an image (e.g. a logo) to overlay at the center.
Supported for
svg, png, and webp formats.Raw binary image content to overlay at the center, as an alternative to
merge when you have the image data in memory rather than on disk. Supported
for svg, png, and webp formats. Only one of merge or mergeString is
applied; merge takes precedence if both are set.The size of the merged image as a fraction of the total QR code size (e.g.
0.3 = 30 %). Applied when either merge or mergeString is set.Color(s) for finder eye 0. Accepts one or two hex/RGB values separated by
;
— the first for the inner eye, the second for the outer eye ring.Accessibility
The component automatically adds accessibility attributes to every QR code it renders — no extra work required on your part:- SVG output — injects a
<title>QR Code</title>element inside the<svg>tag and mergesrole="img"andaria-label="QR Code"onto the root element. - PNG / WebP output — renders an
<img>tag withalt="QR Code"and adata:image/…;base64,…src.
<title> text and aria-label value run through Laravel’s __() helper, so they are automatically translated if you provide a translation key in your language files.
Examples
Minimal default
Hex color (#0066cc)
Dot style & circle eyes
Vertical gradient
Custom eye colors
Logo overlay (Error correction H)
Passing extra HTML attributes
Because<x-qr-code> is a standard Blade component, you can pass arbitrary HTML attributes. They are merged onto the root <svg> or <img> element, so you can add CSS classes, id attributes, inline styles, and data attributes freely:
Format comparison
- SVG (recommended)
- PNG
- WebP
SVG is the default format and the best choice for most templates:
- Vector — scales to any size without pixellation
- Inline — no extra HTTP request; the markup lives inside the HTML
- Accessible —
<title>andaria-labelare injected automatically - Styleable — you can target the
<svg>with CSS
Using inside Livewire and Alpine
The<x-qr-code> component works inside Livewire and Alpine.js views with no extra setup. Because the QR code is rendered server-side on every Livewire render cycle, keep size values moderate to avoid unnecessary CPU usage on frequent re-renders.