React library
Basic usage
Which qrdx component to render, and the props that set a code's size, quiet zone, colors, shapes, logo, frame and error correction.
QRCode is the component to reach for: it takes every styling option and a simple logo prop, and it renders on the server. This page goes through the props you set most often. For every prop, see the library API reference.
Choose a component
QRCode and QRCodeSVG use no browser-only hooks, so they render in React Server Components and in static HTML. QRCodeCanvas ships with "use client".
import { QRCode } from "qrdx";
export function MenuCode() {
return (
<div role="img" aria-label="QR code for the menu">
<QRCode value="https://example.com/menu" size={256} margin={4} />
</div>
);
}value is encoded exactly as you pass it, so a Wi-Fi payload, a vCard, mailto: or plain text all work. QRCode takes the code's own props and style, nothing else: give it an accessible name by wrapping it, as above. QRCodeSVG puts aria-label, className, role and any other attribute on the <svg> itself.
Size and quiet zone
sizeis the width and height in pixels (default 128). Below about 128 px a dense code gets hard to scan from a screen.marginis the quiet zone around the code, in modules (default 0). The QR standard asks for 4. Set it when the code sits on a photo, a pattern or a dark page; a code inside a white card with its own padding can keep 0.scalemultipliessizeonQRCode.
A frame or a template changes the output size. See Frame or template.
Colors
import { QRCode } from "qrdx";
export function BrandCode() {
return (
<QRCode
value="https://example.com"
size={256}
fgColor="#1d4ed8"
bgColor="#f8fafc"
eyeColor="#0f172a"
dotColor="#1d4ed8"
/>
);
}fgColorcolors the data modules,bgColorthe background,eyeColorthe three corner eyes anddotColorthe dot inside each eye. The eye colors default tofgColor.- Each takes any CSS color (
#1d4ed8,rgb(29 78 216), a named color), or a gradient object. Set colors and gradients covers gradients, see-through colors and image fills. - Keep the modules darker than the background. Scanners read dark on light; a light code on a dark background works in most phone cameras but not in some older apps.
Shapes
import { QRCode } from "qrdx";
export function RoundedCode() {
return (
<QRCode
value="https://example.com"
size={256}
bodyPattern="rounded"
cornerEyePattern="extra-rounded"
cornerEyeDotPattern="rounded"
/>
);
}bodyPatternshapes the data modules (defaultcircle). There are 23 to choose from.cornerEyePatternshapes the three corner eyes (defaultgear), one of 17.cornerEyeDotPatternshapes the dot inside each eye (defaultcircle), one of 21.
Shapes, eyes and frames draws every value live. Choose module and eye shapes explains module scale, shaped codes and the few pairs that scan badly together.
Logo
import { QRCode } from "qrdx";
export function LogoCode() {
return (
<QRCode
value="https://example.com"
size={256}
level="H"
logo="/logo.png"
logoOptions={{ size: 0.2, padding: 1 }}
/>
);
}logo takes a path in your app, a URL or a data URL. The modules behind it are cleared, so the code relies on error correction to scan: use level="H". logoOptions sets the logo's width as a share of the code (0.1 to 0.3, default 0.25), its clear space in modules, its position and its crop. The component never draws a logo bigger than the code can repair. Add a logo in code has the details.
Frame or template
import { QRCode } from "qrdx";
export function FramedCode() {
return (
<QRCode
value="https://example.com"
size={256}
frame={{ style: "banner-bottom", text: "Scan me", color: "#0f172a" }}
/>
);
}framedraws a call-to-action frame around the code. The code stayssizewide and the output grows to fit the frame. There are 19 built-in styles, plus the official frame library and your own frame specs. See Frames, scan score and print files.templateIddraws a template such asArroworStandardBoxinstead. A template draws its whole artwork atsize, with the code smaller inside it. See Use a frame template.
With both set, the frame is drawn around the template's artwork.
Error correction
A higher level adds modules, so the code gets denser at the same size. autoLevel raises the level to H on its own when a logo covers more than 7% of the code; it is off by default so existing codes keep their look.
Related
Was this page helpful?
Last updated on
Get started with the React library
Install qrdx, render a styled QR code in a React component and save it as a file, in a few minutes.
QR codes in Next.js
Render QR codes in the Next.js App Router with qrdx, in Server Components with no client JavaScript, from route params, in Client Components for live input, with a logo, and as an SVG download.