Skip to content
Developer Tool

QR API Playground

Interactive API docs: build a QR-generation request from parameters, copy the fetch snippet, and learn what each parameter does.

Request snippet

// Generate a QR code with the public QR Server API (api.qrserver.com)
// This is a request template: adapt the base URL to your own service
// if you self-host QR generation.
const params = new URLSearchParams({
  data: "https://example.com",
  size: "512x512",
  margin: String(2),
  ecc: "M",
  format: "png",
  color: "000000",
  bgcolor: "ffffff",
});
const res = await fetch('https://api.qrserver.com/v1/create-qr-code/?' + params);
if (!res.ok) throw new Error('QR request failed: ' + res.status);
const blob = await res.blob(); // PNG image of the QR code

Live preview (generated locally with these parameters)

Preview will appear here.

content — The text or URL encoded in the code. Shorter content makes a sparser, easier-to-scan code. Keep URLs short: every extra character adds modules.

size — Output width and height in pixels. For print, multiply the printed width in inches by 300. Never enlarge a small raster output.

margin — Quiet-zone width in modules. The QR standard requires at least 4; many APIs use a smaller default, so set it explicitly.

errorCorrection — How much damage the code tolerates: L (~7%), M (~15%), Q (~25%), H (~30%). Higher levels help with logos and wear, but add modules.

format — png returns a fixed-pixel raster image; svg returns scalable vector shapes. Use svg for print and png for quick web use.

colors — Foreground (modules) and background colors. Keep dark modules on a light background with at least 3:1 contrast.

How QR Generation APIs Work, Parameter by Parameter

A QR generation API takes a handful of parameters and returns an image. That simplicity is deceptive, because each parameter carries a trade-off that shows up later as a code that scans slowly, prints blurry, or fails on a damaged label. The playground above builds a real request from your parameters, explains each one, and shows a live preview generated with the same values, so you can see the effect of every choice before you wire the API into your product. The snippet targets the public QR Server API as an example endpoint; if you self-host generation, the same parameter names map onto the same concepts in your own service.

Content comes first, because it decides the density of the whole code. Every character you encode adds modules to the grid, and every module makes each square smaller at a fixed print size. A short URL produces a sparse, forgiving code; a long URL with tracking parameters produces a dense, fragile one. When the content is a URL, keep it short with a redirect or a short domain rather than pasting a full address with five query parameters. When the content is text, ask whether the scanner needs all of it, because trimming a sentence can drop the code an entire version level.

Error correction and margin are the two parameters developers most often leave at defaults they have never read. Error correction decides how much of the code can be damaged or covered before it stops scanning, from about 7 percent at level L to about 30 percent at level H. Level M is a sensible default for clean digital use; level H is the right choice when the code will carry a logo, live outdoors, or be printed on a surface that scuffs. Margin is the quiet zone in modules, and the standard requires at least four. Many APIs default to a smaller margin or none at all, so set it explicitly, or the code will arrive cropped and unreliable.

Size and format decide what you can do with the returned image. Size is the pixel width for raster output, and it must be chosen from the final print size: printed inches times 300 DPI. Requesting a small image and enlarging it later is the most common API mistake, because the blur cannot be undone. Format is the other half: SVG returns vector shapes that scale cleanly to any size and are the right choice for print, while PNG returns fixed pixels that are convenient for web pages and app screens. Colors follow the same rule as everywhere else in QR work: dark modules, light background, strong contrast, and no inverted codes.

Finally, treat any QR API as an external dependency with failure modes. Validate the response status before using the image, handle network failures with a retry or a cached fallback, and never build a checkout, ticket, or boarding flow that cannot function when the QR service is unreachable. Cache generated codes when the content is stable instead of calling the API on every page load, and keep the generation parameters next to the code in your own records so a reprint reproduces the same code exactly. A QR API is a small piece of infrastructure, and it deserves the same care as any other.

Frequently Asked Questions

Which error-correction level should I use?

M (~15%) is a good default for clean use. Use H (~30%) when the code carries a logo, lives outdoors, or may get scuffed. Higher levels add modules, so keep content short.

What margin should I request from a QR API?

At least 4 modules, the QR standard minimum. Many APIs default to less, so set margin explicitly rather than trusting the default.

Should I request SVG or PNG from the API?

SVG for print and anything that may be resized; PNG for web and app screens where a fixed pixel size is fine. Never enlarge a small PNG for a large print.

Can I rely on a public QR API in production?

For prototypes and low-stakes use, yes. For checkout, tickets, or anything critical, self-host generation or cache results, and handle API failures with a fallback so your flow still works.