QRdx
HelpGuidesDevelopersReact librarySelf-hosting

QR Code

A styled, accessible QR code with download buttons. Colors, gradients, patterns, logos and frame templates come from the qrdx library.

Scan to open qrdx.dev
Download QR code

Installation

pnpm dlx shadcn@latest add https://qrdx.dev/r/qr-code.json

Usage

import { QrCode } from "@/components/qr-code";
<QrCode value="https://qrdx.dev" />

The code renders as an SVG with an accessible name, so it stays sharp at any size and screen readers announce what it links to.

Examples

Sizes

size sets the on-screen width and height in pixels. Downloads use downloadSize, so a small code on the page still exports a print-ready file.

96px

128px

160px

Colors

fgColor and bgColor take any CSS color. eyeColor and dotColor color the three corner eyes separately. Keep the modules darker than the background so every scanner can read the code.

Solid

Accent eyes

Tinted background

Gradients

Pass a qrdx gradient instead of a color: linear with an angle, or radial. Gradients carry over into PNG, SVG and PDF downloads.

Linear gradient
Download QR code

Radial gradient
Download QR code

Patterns

bodyPattern shapes the data modules, cornerEyePattern the corner frames and cornerEyeDotPattern the dots inside them. See patterns for every shape.

square

circle

rounded

diamond

logo places an image in the center and clears the modules behind it. Use error correction level H so the code still scans with part of it covered. A data URL keeps the logo in downloads; a remote image needs CORS headers.

Use level H with a logo
Download QR code

Frame templates

templateId draws a qrdx template around the code. Pair it with caption for a call to action under the frame.

StandardBox

Arrow

SquareBorder

Download formats

downloadFormats picks the buttons: png, jpg, svg and pdf. PDF export needs the optional jspdf package (npm install jspdf). Pass [] to hide the buttons.

Download QR code

For a single menu with formats and sizes, use QR Code Download.

Dark mode

The default white background is the safest choice in dark themes: dark modules on a light tile scan with every reader. To follow the theme instead, set fgColor="currentColor" and a transparent background. The code then inverts in dark mode, which phone cameras read but some older scanners don't.

Light tile

Follows the theme

In a Next.js page

QrCode is a Client Component (its file starts with "use client" because of the download buttons), so a Server Component page can import it and pass server data as props:

app/menu/page.tsx
import { QrCode } from "@/components/qr-code";

export default function MenuPage() {
  return (
    <QrCode
      value="https://example.com/menu"
      caption="Scan to see the menu"
      filename="menu-qr"
    />
  );
}

The code itself is still rendered on the server, so it's in the page's HTML before the buttons become interactive. For more on rendering codes in the App Router, see QR codes in Next.js.

value is encoded exactly as you pass it, so any QR payload works: a Wi-Fi network, a contact card, mailto:, tel: or plain text. Set label so screen readers announce what the code does rather than the raw payload, which for Wi-Fi includes the password.

components/guest-wifi.tsx
import { QrCode } from "@/components/qr-code";

export function GuestWifi() {
  return (
    <QrCode
      value="WIFI:T:WPA;S:Cafe Guest;P:sunshine123;;"
      label="QR code to join the Cafe Guest Wi-Fi"
      caption="Cafe Guest Wi-Fi"
    />
  );
}

To build the payload from a form, use Wi-Fi QR Code or vCard QR Code, which escape special characters for you.

A value from an input

components/link-qr-code.tsx
"use client";

import { useState } from "react";
import { QrCode } from "@/components/qr-code";

export function LinkQrCode() {
  const [value, setValue] = useState("https://example.com");
  return (
    <div className="grid justify-items-center gap-4">
      <input
        aria-label="Link"
        className="w-full rounded-md border px-3 py-2"
        value={value}
        onChange={(event) => setValue(event.target.value)}
      />
      {value ? <QrCode value={value} downloadFormats={[]} /> : null}
    </div>
  );
}

downloadFormats={[]} hides the buttons while someone is still typing; show them once the value is final.

components/table-code.tsx
import { QrCode } from "@/components/qr-code";

export function TableCode() {
  return (
    <QrCode
      value="https://example.com/order?table=12"
      level="H"
      margin={4}
      downloadFormats={["svg", "png", "pdf"]}
      downloadSize={2048}
      filename="table-12"
    />
  );
}
  • SVG scales to any size without blurring, so it's the best file for a print shop or a design tool.
  • PNG at downloadSize={2048} prints sharply up to about 17 cm (6.8 inches) wide at 300 pixels per inch. downloadSize takes 50 to 5000 pixels.
  • PDF needs the optional jspdf package (npm install jspdf).
  • filename names the file without its extension: table-12.svg, table-12.png.

Make sure it scans

  • Contrast. Dark modules on a light background scan with every reader. A light code on a dark background works on most phone cameras but not on some older scanners.
  • Quiet zone. margin defaults to 2 modules. Use 4 when the code sits on a photo, a pattern or a dark page.
  • Logos. Use level="H" with a logo, so the code survives the modules the logo covers.
  • Print size. A short link scanned from about 25 cm needs a code about 2.5 cm wide; the print size calculator works it out for other distances.
  • Test it. Scan the finished code with a few phones, or upload an image to the scan checker.

API Reference

Prop

Type

Any other prop, such as className, is passed to the wrapping <figure>.

Last updated on

On this page