← Back to Blog

QR Code Generation: Error Correction, Size, and Design Tips

April 11, 2026 4 min read By CodeTidy Team

QR Code Generation: The Surprising Mistakes You're Making

QR codes are everywhere, from product packaging to business cards, but have you ever stopped to think about the intricacies of generating them? We've seen many developers overlook crucial aspects of QR code design, leading to failed scans, distorted logos, and a poor user experience. Let's dive into the world of QR code generation and explore the best practices to ensure your codes are scannable, stylish, and effective.

Table of Contents

  • Error Correction Levels: Why You Need to Choose Wisely
  • The Minimum Size Conundrum: How to Balance Aesthetics and Functionality
  • Embedding Logos: The Dos and Don'ts
  • Color Contrast: The Secret to Scannable QR Codes
  • Version and Capacity: How to Choose the Right One for Your Needs
  • Testing Your QR Code: The Final Check

Error Correction Levels: Why You Need to Choose Wisely

When generating a QR code, you'll often be asked to choose an error correction level. This determines how much damage the code can withstand before it becomes unscannable. There are four levels to choose from: L (7% correction), M (15% correction), Q (25% correction), and H (30% correction). We recommend using the H level for most use cases, as it provides the highest level of protection against errors.

// Example of generating a QR code with error correction level H using the jsQR library
const jsQR = require('jsqr');
const qrCode = jsQR.generate('https://example.com', { errorCorrectionLevel: 'H' });

The Minimum Size Conundrum: How to Balance Aesthetics and Functionality

The minimum size of a QR code is a common point of contention among designers and developers. While it's tempting to shrink the code to fit it into a tight space, this can lead to failed scans and a poor user experience. We recommend a minimum size of 2x2 inches (5x5 cm) to ensure scannability. However, if you're working with a very large dataset, you may need to increase the size accordingly.

/* Example of styling a QR code container to ensure a minimum size */
.qr-code-container {
  width: 200px; /* 2 inches at 96 DPI */
  height: 200px; /* 2 inches at 96 DPI */
  padding: 20px;
  background-color: #ffffff;
}

Embedding Logos: The Dos and Don'ts

Embedding a logo into a QR code can add an extra layer of branding and visual appeal. However, it's essential to do it correctly to avoid distorting the code. We recommend using a logo that's no larger than 30% of the code's size and ensuring it's centered and symmetrical. Avoid using logos with intricate details or complex patterns, as these can interfere with the code's scannability.

# Example of embedding a logo into a QR code using the python-qrcode library
from PIL import Image
import qrcode

qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,
)
qr.add_data('https://example.com')
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")
logo = Image.open('logo.png')
pos = ((img.size[0] - logo.size[0]) // 2, (img.size[1] - logo.size[1]) // 2)
img.paste(logo, pos)
img.save('qr_code_with_logo.png')

Color Contrast: The Secret to Scannable QR Codes

Color contrast is a crucial aspect of QR code design that's often overlooked. A QR code should have sufficient contrast between the dark and light modules to ensure scannability. We recommend using a dark color for the modules and a light color for the background. Avoid using colors that are too similar, as this can lead to failed scans.

/* Example of styling a QR code with high contrast colors */
.qr-code {
  background-color: #ffffff;
  .module {
    background-color: #000000;
  }
}

Version and Capacity: How to Choose the Right One for Your Needs

QR codes come in different versions, each with its own capacity and characteristics. The version you choose will depend on the amount of data you need to store and the level of error correction required. We recommend using version 40 for most use cases, as it provides a good balance between capacity and error correction.

// Example of generating a QR code with version 40 using the ZXing library
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.encoder.QRCode;

QRCodeWriter writer = new QRCodeWriter();
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.VERSION, 40);
writer.encode('https://example.com', BarcodeFormat.QR_CODE, hints);

Testing Your QR Code: The Final Check

Once you've generated your QR code, it's essential to test it thoroughly to ensure it scans correctly. We recommend testing the code on different devices and platforms, including Android and iOS devices, as well as various QR code readers.

Key Takeaways

  • Choose the right error correction level for your QR code (we recommend H for most use cases)
  • Ensure a minimum size of 2x2 inches (5x5 cm) to ensure scannability
  • Embed logos correctly to avoid distorting the code
  • Use high contrast colors to ensure scannability
  • Choose the right version and capacity for your needs (we recommend version 40 for most use cases)
  • Test your QR code thoroughly on different devices and platforms

FAQ

Q: What is the maximum amount of data that can be stored in a QR code?

A: The maximum amount of data that can be stored in a QR code depends on the version and error correction level. For example, version 40 with error correction level H can store up to 2953 bytes of data.

Q: Can I use a QR code with a low error correction level for a simple URL?

A: Yes, you can use a QR code with a low error correction level for a simple URL, but we recommend using a higher error correction level (such as H) to ensure the code remains scannable even if it's damaged.

Q: How do I ensure my QR code is accessible to users with visual impairments?

A: To ensure your QR code is accessible to users with visual impairments, use high contrast colors and provide an alternative text description of the code's contents.

AI agent tools available. The CodeTidy MCP Server gives Claude, Cursor, and other AI agents access to 60+ developer tools. One command: npx @codetidy/mcp