# Set colors and gradients (Features)

URL: https://qrdx.dev/docs/features/colors-gradients
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/features/colors-gradients.mdx

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](https://qrdx.dev/docs/help/designing/colors-and-contrast) in Help.

## Solid colors [#solid-colors]

```tsx title="components/brand-code.tsx"
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](https://qrdx.dev/docs/features/patterns#per-eye-colors).

### Transparent background [#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 [#linear-gradients]

```tsx title="components/gradient-code.tsx"
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 },
        ],
      }}
    />
  );
}
```

- `angle` is in degrees: 0 runs left to right, 90 top to bottom, 45 from the top left corner down to the bottom right.
- `stops` need at least two entries. `offset` is a percentage from 0 to 100, and a stop's color can carry alpha.
- Any color prop takes a gradient, including `bgColor` and the eyes. `QRCodeCanvas` cannot draw gradients and uses the first stop; use `QRCode` or `QRCodeSVG`.

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.

![Three codes with gradient colors: a linear gradient from indigo to pink, a radial gradient from teal in the middle to dark blue at the edges, and an angular gradient that sweeps from blue through violet and back.](https://qrdx.dev/docs-static/shots/lib-gradient-codes.light.webp)

## Radial gradients [#radial-gradients]

```tsx title="components/radial-code.tsx"
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 [#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.

```tsx title="components/angular-code.tsx"
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 [#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.

```tsx title="components/palette-code.tsx"
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,
      }}
    />
  );
}
```

- `colors` holds 2 to 8 colors, each any CSS color a solid color takes.
- `mode` says 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 as `liquid` or `classy`, each piece reads as one colored shape. `modules` colors each dot on its own. `rows` runs the colors as bands from top to bottom, mixed dot by dot where two bands meet (an ordered dither, so the edge stays crisp). `tones` lays 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_PRESETS` holds 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`): `liquid` no smaller than 0.85, `classy` 0.8, `star` and the thin liquids at full size.
- Palettes carry into every download: SVG, PNG and the other bitmaps, the print PDF and EPS. `QRCodeCanvas` draws 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 [#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.

```tsx title="components/eye-gradient-code.tsx"
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 [#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 [#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.

```tsx title="components/photo-code.tsx"
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",
      }}
    />
  );
}
```

- `src` is the picture itself, as with a logo. QRdx saves an image fill (in codes, themes and the REST API) only as a base64 `data:image` URL (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.
- `underlay` is a solid color under the picture. `opacity` lets 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](https://qrdx.dev/docs/features/downloads#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 [#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:

```ts title="lib/check-contrast.ts"
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 [#related]

- [Choose module and eye shapes](https://qrdx.dev/docs/features/patterns): Per-eye colors and the shapes these colors fill.
- [Add a logo in code](https://qrdx.dev/docs/features/logos): A logo on a colored code, with a plate behind it.
- [Export and download](https://qrdx.dev/docs/features/downloads): Which formats keep gradients, transparency and image fills.
- [Utilities](https://qrdx.dev/docs/utilities): The color and contrast helpers in full.
