<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
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.
Output format:
svg, png, or webp. EPS is not supported in the Blade
component.Foreground color as a hex string (e.g.
#ff0000) or a comma-separated RGB
value (e.g. 255,0,0).Background color. Accepts the same formats as
color.Quiet-zone margin around the QR code.
Module (dot) shape:
square, dot, or round.Error correction level:
L (7 %), M (15 %), Q (25 %), or H (30 %).
Defaults to the value in config/qrcode.php (package default M).Character encoding for the payload, e.g.
UTF-8.Finder-pattern eye style:
square, circle, or pointy.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.Direction of the gradient:
vertical or horizontal. Only applied when
gradient is also set.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.Color(s) for finder eye 1. Same format as
eyeColor0.Color(s) for finder eye 2. Same format as
eyeColor0.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
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.
Comparing the component to the facade
<x-qr-code> component | QrCode facade | |
|---|---|---|
| Ideal for | Blade templates | Controllers, jobs, services |
| Escaping | Handled automatically | Use {!! !!} for SVG |
| Accessibility | Automatic aria-label / role | Manual |
| PNG/WebP in HTML | Inline base64 <img> | Raw binary — handle manually |
| EPS support | ❌ Not supported | ✅ Supported |