We scanned 160 light-on-dark QR codes: OpenCV read none, jsQR missed 15, and ZXing read all 160 only with its invert switch on

White-on-black QR codes look good on a dark poster, a black T-shirt or a dark-mode screen. Many designers just swap the two colours and move on. But does the code still scan? A QR code is defined as dark squares on a light background, and some readers only look for that. So we tried it.

We made 160 QR codes (40 links of 23 to 150 characters, each at all four error correction levels), drew every one twice, once normal and once with the colours swapped, and read each picture with three open-source readers, with their "try the inverted image" switch on and off. That was 3,200 reads. The result: <strong>OpenCV read none of the 160 inverted codes, ZXing read all 160 but only because its invert switch was on, and jsQR read all 160 sharp ones but missed 15 of the phone-like ones.</strong> Normal codes were read almost every time by all of them.

How we tested

  • Links: 40 made-up links of 23 to 150 characters on four hostnames (b59.link, example.com and two others), fixed random seed. Python qrcode at the smallest version that fits (versions 2 to 12), 4-square quiet zone.
  • Inverted: the same picture with every pixel flipped: light squares on black, and the quiet zone black too. Nothing else changed.
  • Two conditions: sharp (10 pixels per square) and phone-like (shrunk to 240 × 240 pixels with a 0.8-pixel blur).
  • Readers: OpenCV 4.11 QRCodeDetector (it has no invert option), ZXing-C++ via zxing-cpp with try_invert on and off, and jsQR with attemptBoth and dontInvert.
  • A read counts only if the text matches the link exactly.

Results: how many of 160 codes each reader got

Reader and settingNormal, sharpInverted, sharpNormal, phone-likeInverted, phone-like
OpenCV QRCodeDetector (no switch)154 / 160 *0 / 160157 / 1600 / 160
ZXing-C++, try_invert on (default)160 / 160160 / 160160 / 160160 / 160
ZXing-C++, try_invert off160 / 1600 / 160160 / 1600 / 160
jsQR, attemptBoth (default)160 / 160160 / 160159 / 160145 / 160
jsQR, dontInvert160 / 1600 / 160159 / 1600 / 160

* OpenCV missed 6 of the 160 normal sharp codes and 3 of the phone-like ones, mostly dense codes for long links, so it isn't a perfect reader even on ordinary codes.

The same QR code drawn dark on light and light on dark, with which reader settings read each one
Same link, same level M code. On the inverted version OpenCV and both readers with their invert switch off fail.

Where jsQR dropped codes

jsQR with its default setting read every sharp inverted code, but in the phone-like condition it lost 15 of 160. All 15 were dense codes (versions 9 and 10, which means links of 95 characters and more at levels Q and H). The same links drawn normally lost 1. So inverted codes for short links were fine, and the longer the link, the more it hurt:

Link lengthInverted codesZXing, invert onjsQR, invert onAny reader, invert off
23-60 characters4848 / 4848 / 480 / 48
61-100 characters4848 / 4847 / 480 / 48
101-150 characters6464 / 6450 / 640 / 64

What to do with a light-on-dark code

  • If you can, print dark on light. Every reader we tried read nearly all normal codes. A dark or coloured background is fine as long as the code itself is a dark pattern on a light patch; our colour and contrast test covers how much colour is safe.
  • If you must invert, use a short link. A short link makes a small, sparse code, and every reader with an invert setting read all of those. You can also change where it points after printing.
  • Print a test. Scan the printed code with a phone camera and at least one other scanner app before you order a batch. We only tested open-source readers, not the camera apps built into phones; some of those read inverted codes and some may not.
  • Check library defaults. If you scan codes in your own app or website and want inverted ones to work, make sure the invert option is on. OpenCV's detector had none.

Limits of this test: pictures drawn on screen, not printed and photographed; plain black and white only; three readers. Phone camera apps use their own decoders, which we didn't test.

Make the code

Our free <a href="/tools/qr">QR code generator</a> makes dark-on-light codes with the error correction level and colours you choose, as PNG or SVG. Point it at a <a href="/">b59.link short link</a> to keep the code small and count scans. For size and distance see <a href="/articles/print-qr-code-size-scan-distance">printing a QR code that scans</a>, and for logos <a href="/articles/qr-code-logo-placement-centre-corner-test">where a logo can sit</a>.

b59.link free QR code generator with a link entered, colour, background, size and error correction settings, and the code ready to download as PNG or SVG
The b59.link QR generator.