# Basic usage

URL: https://qrdx.dev/docs/usage
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/usage.mdx

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](https://qrdx.dev/docs/api-reference).

> This page describes qrdx 0.0.65. Run `npm view qrdx version` to see the version npm installs.

## Choose a component [#choose-a-component]

| Component | What it draws | Use it when |
| --- | --- | --- |
| `QRCode` | An `<svg>` with every style option, plus `logo`, `logoOptions`, `hideLogo` and `scale`. Any other prop (`aria-label`, `className`, `role`) goes on the `<svg>` | Almost always |
| `QRCodeSVG` | The same `<svg>`, with the logo given as raw `imageSettings` in pixels. Any other prop goes on the `<svg>` too | You lay the logo out yourself, or you port code from another renderer |
| `QRCodeCanvas` | A `<canvas>` with plain square modules and solid colors | You need a canvas element. Patterns, eye colors and gradients are ignored |

`QRCode` and `QRCodeSVG` use no browser-only hooks, so they render in React Server Components and in static HTML. `QRCodeCanvas` ships with `"use client"`.

```tsx title="components/menu-code.tsx"
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. The wrapper gives the code an accessible name. From qrdx 0.0.56, `QRCode` also puts `aria-label`, `className`, `role` and any other attribute on the `<svg>` itself, as `QRCodeSVG` always has, so you can label the code without a wrapper. Older versions of `QRCode` drop those props.

## Size and quiet zone [#size-and-quiet-zone]

- `size` is the width and height in pixels (default 128). Below about 128 px a dense code gets hard to scan from a screen.
- `margin` is 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.
- `scale` multiplies `size` on `QRCode`.

A frame changes the output size. See [Frame](#frame).

## Colors [#colors]

```tsx title="components/brand-code.tsx"
import { QRCode } from "qrdx";

export function BrandCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      fgColor="#1d4ed8"
      bgColor="#f8fafc"
      eyeColor="#0f172a"
      dotColor="#1d4ed8"
    />
  );
}
```

- `fgColor` colors the data modules, `bgColor` the background, `eyeColor` the three corner eyes and `dotColor` the dot inside each eye. The eye colors default to `fgColor`.
- Each takes any CSS color (`#1d4ed8`, `rgb(29 78 216)`, a named color), or a gradient object. [Set colors and gradients](https://qrdx.dev/docs/features/colors-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 [#shapes]

```tsx title="components/rounded-code.tsx"
import { QRCode } from "qrdx";

export function RoundedCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      bodyPattern="rounded"
      cornerEyePattern="extra-rounded"
      cornerEyeDotPattern="rounded"
    />
  );
}
```

- `bodyPattern` shapes the data modules (default `circle`). There are 23 to choose from.
- `cornerEyePattern` shapes the three corner eyes (default `gear`), one of 22.
- `cornerEyeDotPattern` shapes the dot inside each eye (default `circle`), one of 22.

[Shapes, eyes and frames](https://qrdx.dev/docs/styles) draws every value live. [Choose module and eye shapes](https://qrdx.dev/docs/features/patterns) explains module scale, shaped codes and the few pairs that scan badly together.

## Logo [#logo]

```tsx title="components/logo-code.tsx"
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](https://qrdx.dev/docs/features/logos) has the details.

## Frame [#frame]

```tsx title="components/framed-code.tsx"
import { QRCode } from "qrdx";

export function FramedCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      frame={{ style: "banner-bottom", text: "Scan me", color: "#0f172a" }}
    />
  );
}
```

`frame` draws a call-to-action frame around the code. The code stays `size` wide and the output grows to fit the frame. There are 25 built-in styles, from banners and bubbles to artwork such as `arrow` and `dot-ring`, plus the official frame library and your own frame specs. See [Frames, scan score and print files](https://qrdx.dev/docs/features/frames).

## Error correction [#error-correction]

| `level` | Can be damaged | Use it for |
| --- | --- | --- |
| `L` | about 7% | Clean screens, short links, the smallest code |
| `M` | about 15% | Long payloads such as vCards, where a smaller code matters more |
| `Q` | about 25% | The default. General use |
| `H` | about 30% | Logos, art, print that gets scratched or folded |

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.

The level is a minimum: when the data still fits the same version at a higher level, the encoder uses the higher one, which costs nothing in size. `exactLevel` turns that off, so the code is encoded at exactly the level it is drawn at. A Swiss QR-bill needs this: SIX's guidelines ask for error correction `M` (Swiss Implementation Guidelines for the QR-bill, section 6.1), and QRdx's editor, API and MCP server set `exactLevel` for every Swiss QR-bill payload.

```tsx title="components/bill-code.tsx"
<QRCode value={swissQrBillPayload} level="M" exactLevel />
```

## Related [#related]

- [Set colors and gradients](https://qrdx.dev/docs/features/colors-gradients): Solid colors, linear, radial and angular gradients, see-through colors and image fills.
- [Add a logo in code](https://qrdx.dev/docs/features/logos): Size, clear space, position, crop and the error-correction budget.
- [Export and download](https://qrdx.dev/docs/features/downloads): PNG, JPG, WebP, GIF, BMP, ICO, TIFF, SVG, PDF and EPS, the clipboard and PNG in Node.
- [Library API reference](https://qrdx.dev/docs/api-reference): Every prop, with its type and default.
