Coloured QR codes and logos: what scanners forgive

Most people who print a QR code want it to look like theirs: the brand colour, rounded dots, the logo in the middle. Generators make that easy. What they don't tell you is where the line is. A code that scans on your laptop screen in the office can fail on a menu in a dim restaurant, on a poster in the shade, or on a customer's four-year-old phone.

We wanted numbers rather than rules of thumb, so we ran a test. We drew the same short address as a QR code in 17 colour pairs, with and without a logo at every error correction level, then shrank, blurred, dimmed and added noise to each image the way a phone camera in poor light does, and tried to read it with two widely used open-source decoders (ZXing-C++ and OpenCV's). Four tries per decoder per condition. It's a simulation, not a lab of real phones, but the pattern was clear, and it matches what you'll see when you test your own codes.

Six QR codes for the same address: black on white, read in every light; b59 green on white, 4 of 8 reads in very dim light; yellow on white, 1 of 8 reads in dim light; black on red, 4 of 8 reads in dim light; white on navy, read only with try inverted on; level H with a logo covering 16% of the area, read, the limit was about 18%
Six of the codes from our test. All of them open b59.link/tools/qr-size; try them with your own phone.

Colour: the gap in lightness is what counts

Scanners don't see colour. A phone camera turns the picture into shades of grey and decides, for each square, whether it's dark or light. So two colours that look very different to you can be nearly the same grey. Red and black is the classic case: striking to the eye, but red is a fairly dark grey, so black squares on a red background are dark on dark.

The best predictor in our test was simply the difference between the two colours' grey values, on a scale where black is 0 and white is 255:

text
colours                 grey gap   normal light   dim     very dim
black on white             255         8/8        8/8       8/8
navy on white              213         8/8        8/8       8/8
black on yellow            207         8/8        8/8       8/8
dark green on white        189         8/8        8/8       8/8
black on kraft brown       174         8/8        8/8       8/8
red on white               170         8/8        8/8       8/8
mid blue on white          144         8/8        8/8       6/8
teal on white              136         8/8        8/8       6/8
navy on kraft brown        132         8/8        8/8       5/8
black on mid grey          128         8/8        8/8       4/8
b59 green on white         126         8/8        8/8       4/8
orange on white             97         8/8        6/8       2/8
pink on white               93         8/8        5/8       3/8
light blue on white         86         8/8        5/8       2/8
black on red                85         8/8        4/8       1/8
dark grey on mid grey       80         8/8        4/8       0/8
yellow on white             55         7/8        1/8       0/8

Three things stand out. In good light, almost everything worked: that's why a code looks fine when you check it at your desk. In dim light, everything with a gap under about 100 started failing. And only the pairs with a gap of about 170 or more, two thirds of the way from black to white, were read every time in very dim light. Our own brand green on white, at 126, is a good example of a colour that looks strong and is only half-reliable in a dark room; we print our codes in black.

You don't need software to check this. Make the design greyscale (any photo editor, or print one copy on a black-and-white printer) and look at it. If the dark squares are clearly near-black and the background clearly near-white, you're fine. If both look like shades of mid-grey, choose again. A common contrast checker for web text gives a similar answer: aim for a ratio of 7:1 or more, though in our test the grey gap predicted failures better than the ratio did (black on red has a ratio of 4:1 and failed more often than teal at 2.9:1). If you make the code in our QR maker, it runs the same check while you pick the colours: it shows the grey gap, warns when a pair is likely to fail in dim light, and offers to swap colours that are the wrong way round.

The dark colour has to be the squares

A QR code is defined as dark squares on a light background. Turn it round, light squares on a dark background, and many readers see nothing at all. In our test neither decoder read white-on-black or white-on-navy codes in their default setting, even in perfect light. Switch on ZXing's "try inverted" option and both were read every time.

That option exists because inverted codes are rare and checking for them costs time: a ZXing maintainer once noted that looking for inverted codes as well would double the work of every scan. So whether a light-on-dark code scans depends on which app your visitor uses. Some phone cameras handle it; many scanner apps, payment apps and older phones don't. If your design has a dark background, put the code on a light panel inside it, with a light margin all round.

That margin, the quiet zone, matters for colour too. It should be the light colour, at least four squares wide, with nothing printed in it. A coloured code dropped straight onto a busy photograph has no quiet zone, and the scanner can't find where the code begins.

Gradients and rounded dots

A gradient is fine as long as every part of it stays dark enough. In our test, navy fading to teal, and even navy fading to a light cyan, were read in all light levels, because the lightest end was still clearly darker than the white background. A gradient that ends in a pale colour in one corner gives you a weak corner; check the lightest end with the greyscale test.

Rounded dots instead of squares were read by ZXing in every condition; OpenCV read them in every condition for one address and failed in very dim light for the other. Dots leave more white between squares, so there's less dark to see. Keep them reasonably large (close to the full square, not small specks) and leave the three big corner squares, the finder patterns, as plain squares. Those are what the scanner looks for first; turning them into circles, flowers or hearts is the riskiest styling of all.

A logo in the middle: how much can it cover?

A logo works because of error correction. A QR code carries spare data, so a reader can rebuild what it can't see. There are four levels, which can rebuild roughly 7% (L), 15% (M), 25% (Q) and 30% (H) of the code. A logo hides squares, so it uses up that spare capacity before the code has met any scratch, glare or bad light.

We put a logo (a filled circle on a white square) in the centre and made it bigger until reading failed. The share of the code's area it could cover:

text
level   can rebuild   logo that still read (share of area)
L       ~7%           2 to 3%
M       ~15%          3 to 12%
Q       ~25%          10 to 16%
H       ~30%          16 to 18%

The ranges come from two different addresses and the two decoders under phone-like conditions. Notice how much the result moves at level M: what sits underneath the logo, and how the decoder handles it, makes a big difference, so a logo that worked on last month's code can fail on this month's. At level H, the results were steady.

So, if you want a logo:

- Use level H. It makes the code a little denser (our 30-character address went from 29 to 33 squares a side), so print it slightly bigger.
- Keep the logo to about a tenth of the code's area, which means its width is under a third of the code's width. That leaves error correction for real-world wear. Our codes read with up to 18%, but only in clean conditions with nothing else wrong.
- Centre it, and keep it clear of the three corner squares and the thin dotted lines that run between them.
- Give it a white border rather than letting it touch the squares.
- Keep the address short. A short link makes a small, sparse code, which leaves bigger squares around the logo. Our guide to printing QR codes explains why higher error correction can make a code harder to read when the print size is tight.

Test it the way your customers will scan it

Your screen at full brightness is the best possible condition, and it tells you almost nothing. Before you print a run:

1. Print one copy at the real size, on the real paper or material. Gloss, metallic ink and laminate add glare that a screen never shows.
2. Scan it in poor light: the dimmest corner of the room, or with the lights off and only a window behind you. Then in harsh light, with a reflection across it.
3. Use an old phone and a cheap one, not only your own. Borrow one from someone with a different brand.
4. Scan from the real distance and angle: from the table, across the counter, from the pavement.
5. Try more than one app: the built-in camera, and one scanner app.
6. Do the greyscale check on the artwork.

If it fails any of those, the fix is almost always the same: more contrast, a smaller logo, or a bigger code, in that order.

One last thing that no styling can fix: what the code points to. A beautifully designed code still stops working if the generator that made it holds the address and switches it off, which is what we found inside 67 of 77 codes on QR generators' own websites. Make sure the code holds your own link, or a short link you can change later.

Method and sources: our test script drew each code with the Python library segno, simulated a phone camera (40% scale, blur, sensor noise, light at 100%, 50% and 35%), and decoded with ZXing-C++ (Python package 3.1) and OpenCV 5.0's QRCodeDetector, four tries per decoder; the tables above are its output. Error correction levels: DENSO WAVE, About error correction. Inverted codes and scan time: ZXing project discussion, Recognize inverted color (white on black) QR codes.

Make a QR code in your own colours: the maker shows the grey gap as you pick them, and suggests level H when you're adding a logo.

Make a QR code