React library
Set colors and gradients
Color the modules, eyes and background with solid colors, linear, radial or angular gradients, a palette of several colors, see-through colors or image fills, and check it still scans.
Four props color a code: fgColor for the data modules, bgColor for the background, eyeColor for the three corner eyes and dotColor for the dot inside each eye. Each takes a solid color or a gradient object, and the eye colors default to fgColor. This page covers every kind of fill and how to keep the code readable.
Designing in the playground or the dashboard instead? See Choose colors that scan in Help.
Solid colors
import { QRCode } from "qrdx";
export function BrandCode() {
return (
<QRCode
value="https://example.com"
size={256}
fgColor="#1a56db"
bgColor="#f9fafb"
eyeColor="#0d47a1"
dotColor="#3b82f6"
/>
);
}A solid color is any CSS color the engine parses: hex with 3, 4, 6 or 8 digits, rgb() and rgba(), a named color, or transparent. Other CSS syntaxes such as hsl() render in the SVG, but the contrast check, the PDF and the EPS cannot read them, so stay with the forms above. { type: "solid", color: "#1a56db" } is the same as the string.
eyeColors sets each eye on its own (topLeft, topRight, bottomLeft, each with an outer and inner color or gradient); see Per-eye colors.
Transparent background
bgColor="transparent" paints no background, so PNG and SVG downloads are see-through and PDF and EPS files have no background fill. Place the code on a light, plain surface: decoders need the light gaps between modules.
Linear gradients
import { QRCode } from "qrdx";
export function GradientCode() {
return (
<QRCode
value="https://example.com"
size={256}
fgColor={{
type: "linear",
angle: 45,
stops: [
{ color: "#4f46e5", offset: 0 },
{ color: "#db2777", offset: 100 },
],
}}
/>
);
}angleis in degrees: 0 runs left to right, 90 top to bottom, 45 from the top left corner down to the bottom right.stopsneed at least two entries.offsetis a percentage from 0 to 100, and a stop's color can carry alpha.- Any color prop takes a gradient, including
bgColorand the eyes.QRCodeCanvascannot draw gradients and uses the first stop; useQRCodeorQRCodeSVG.
Gradients carry into SVG, PNG, JPG, WebP, GIF, BMP, ICO, TIFF and PDF downloads (a GIF holds 256 colors, so a gradient is reduced to a palette). The print PDF and EPS draw them as smooth shadings.

Radial gradients
import { QRCode } from "qrdx";
export function RadialCode() {
return (
<QRCode
value="https://example.com"
size={256}
fgColor={{
type: "radial",
stops: [
{ color: "#0f766e", offset: 0 },
{ color: "#0c4a6e", offset: 100 },
],
}}
/>
);
}A radial gradient runs from the center of the code outwards. Its center and radius follow the code's size, so it takes only stops.
Angular gradients
An angular gradient sweeps clockwise around the center of what it fills, like CSS conic-gradient. angle is where the sweep starts, in degrees clockwise from the top. Offsets run from 0 to 100 around the turn.
import { QRCode } from "qrdx";
export function AngularCode() {
return (
<QRCode
value="https://example.com"
size={256}
fgColor={{
type: "angular",
angle: 30,
stops: [
{ color: "#1d4ed8", offset: 0 },
{ color: "#7c3aed", offset: 50 },
{ color: "#1d4ed8", offset: 100 },
],
}}
/>
);
}SVG has no conic gradient, so the code draws a fan of thin wedges, about two color levels apart. PDF and EPS draw the same wedges.
Palettes
A palette hands several colors out across the data modules. It is for fgColor only: the eyes keep their own colors (eyeColor, dotColor, eyeColors, which default to the palette's first color), and a palette on the background or an eye draws as its first color.
import { QRCode } from "qrdx";
export function PaletteCode() {
return (
<QRCode
value="https://example.com"
size={256}
bodyPattern="liquid"
fgColor={{
type: "palette",
colors: ["#1d4ed8", "#b91c1c", "#065f46", "#6d28d9"],
mode: "groups",
seed: 0,
}}
/>
);
}colorsholds 2 to 8 colors, each any CSS color a solid color takes.modesays how they are handed out.groups(the default) gives every run of joined dark modules one color, touching runs different colors where the palette has one to spare, and splits a run longer than 9 modules into pieces; with a connected body such asliquidorclassy, each piece reads as one colored shape.modulescolors each dot on its own.rowsruns the colors as bands from top to bottom, mixed dot by dot where two bands meet (an ordered dither, so the edge stays crisp).toneslays soft patches of color across the code and suits shades of one hue:paletteShades("#1d4ed8", 5)builds them.seed(0 by default) moves the colors around. The same props always draw the same picture, in the SVG and in every export.PALETTE_PRESETSholds eight palettes whose colors all read at 6:1 or more on white. Several colors leave each one less margin under a decoder's threshold than one color alone gets, so keep every color of your own palette dark: the scan score checks each one against the background, as it checks each gradient stop, and the playground's Make it scannable darkens the ones that fall short. Thin body patterns keep their dots a little larger with a palette (PALETTE_MODULE_SCALE_FLOOR):liquidno smaller than 0.85,classy0.8,starand the thin liquids at full size.- Palettes carry into every download: SVG, PNG and the other bitmaps, the print PDF and EPS.
QRCodeCanvasdraws them with its plain square modules. In an art mode (Logo QR, Image QR) the body takes the palette's first color.
One gradient across the eyes
By default each eye sweeps its own gradient: a linear gradient runs across the eye, a radial one out from the eye's center. eyeGradient="code" lays the eyes' gradients over the whole code instead, like the dots', so eyes painted with the dots' gradient continue it from corner to corner.
import { QRCode } from "qrdx";
const brand = {
type: "linear" as const,
angle: 45,
stops: [
{ color: "#1d4ed8", offset: 0 },
{ color: "#db2777", offset: 100 },
],
};
export function EyeGradientCode() {
return (
<QRCode
value="https://example.com"
size={256}
fgColor={brand}
eyeColor={brand}
dotColor={brand}
eyeGradient="code"
/>
);
}The eyes then share the dots' gradient definition in the SVG. "corner" is the default; the playground's Eye colors section has the switch once an eye is painted with a gradient.
See-through colors
Colors and gradient stops can carry alpha, such as #1d4ed8cc or rgba(29, 78, 216, 0.8). SVG writes it as fill-opacity and stop-opacity, and PDF keeps it. EPS has no transparency, so a see-through color is mixed with the background. The scan check judges a see-through color the way it looks on the background.
Image fills
An image fill paints a picture through the background, the modules or the eyes. The picture is laid over the whole code, so modules and eyes that share one show a single picture.
import { QRCode } from "qrdx";
export function PhotoCode({ photo }: { photo: string }) {
return (
<QRCode
value="https://example.com"
size={256}
fgColor={{
type: "image",
src: photo, // a data:image/jpeg;base64,… URL
fit: "cover", // or "contain", "tile"
position: "center",
scale: 1,
opacity: 0.45,
underlay: "#000000",
}}
/>
);
}srcis the picture itself, as with a logo. QRdx saves an image fill (in codes, themes and the REST API) only as a base64data:imageURL (PNG, JPEG, WebP or GIF) of 1.5 MB at most; a picture from a link is refused. PNG and JPEG embed in every export, and servers never fetch a link.underlayis a solid color under the picture.opacitylets it through: over black it darkens a photo for the modules, and over white it lightens one for the background.- A picture's detail reads as noise to a camera, so the scan check asks for more contrast: 7:1 in the modules or eyes, 12:1 behind them (
SCAN_IMAGE_CONTRAST_MIN). It measures a picture by its lightest and darkest tenth (getImageTones). In the editor, Make it scannable finds the opacity over the underlay that passes. - SVG, PNG and PDF carry image fills. EPS cannot; see EPS.
Image fills travel like logos. They stay with the design in the editor, in saved codes and in saved themes. They do not go into ?style= links, published community styles, Get code snippets or the chat's context: each image fill gives way to its underlay color there. The image API (GET /v1/qr) and the MCP server do not take them. POST /v1/codes and PATCH /v1/codes/{id} take one only as a data:image URL, and answer 400 for anything else.
Check the contrast
Scanners need dark modules on a light background. The scan score checks every color, including each gradient stop, against the background; the same helpers are exported:
import { getContrastLevel, getContrastRatio } from "qrdx";
const ratio = getContrastRatio("#1a56db", "#f9fafb");
// 5.9
getContrastLevel(ratio);
// { level: "AA", warning: false, message: "Good contrast" }The scan score passes a ratio of 4.5 or more (SCAN_CONTRAST_MIN), takes points off below it, and fails the design below 1.5. getContrastLevel returns AAA from 7, AA from 4.5, AA Large from 3 with a warning, and Fail below that. A light code on a dark background passes the ratio but loses points on the polarity check: most phone cameras read it, some scanner apps do not.
Related
Was this page helpful?
Last updated on
Choose module and eye shapes
Set the shapes of the modules, corner eyes and eye centers in code, scale the modules, fit the code in a circle, a heart or your own outline, color each eye.
Round the background, add a halo or a shadow
Round the background's corners with a color around them, rim the dots with a light halo, and give the dots a shadow, within the ranges that keep every look scannable.
