← Back to Blog
Technology Mobile 12 min read

QR Codes: Complete Developer Guide

Learn QR code technology, generation techniques, use cases, security considerations, and implementation guidelines for modern applications.

What are QR Codes?

QR (Quick Response) codes are two-dimensional barcodes that can store significantly more data than traditional barcodes. Originally developed in 1994 for tracking automotive parts, QR codes have become ubiquitous in modern technology for sharing information quickly and efficiently.

Key Advantages:
  • High Capacity: Store up to 7,089 numeric or 4,296 alphanumeric characters
  • Fast Scanning: Can be read quickly from any direction (360°)
  • Error Correction: Up to 30% of code can be damaged and still readable
  • Versatility: Support various data types (URL, text, contact info, etc.)
  • No Internet Required: Can store data directly in the code

1. QR Code Structure and Components

Anatomy of a QR Code

Core Components

  • Position Patterns: Three large squares for orientation
  • Alignment Patterns: Smaller squares for distortion correction
  • Timing Patterns: Alternating black/white modules for coordinate reference
  • Format Information: Error correction level and mask pattern
  • Version Information: QR code size (1-40)
  • Data Area: Encoded information and error correction
  • Quiet Zone: Blank border around the code
QR

QR Code Versions

QR codes come in 40 versions (1-40), with increasing capacity:

Version Modules Max Numeric Max Alphanumeric
1 (Smallest) 21×21 41 25
10 57×57 652 395
25 117×117 3,391 2,054
40 (Largest) 177×177 7,089 4,296

2. Error Correction Levels

Four Error Correction Levels

Level Recovery Capacity Use Case Storage Impact
L (Low) ~7% Clean environments, high quality printing +7% data overhead
M (Medium) ~15% General purpose, standard quality +15% data overhead
Q (Quartile) ~25% Industrial, outdoor use +25% data overhead
H (High) ~30% Critical applications, damaged surfaces +30% data overhead
Choosing Error Correction Level:
  • Use L: For clean digital displays, high-resolution printing
  • Use M: For most web and mobile applications (recommended default)
  • Use Q: For printed materials, product packaging
  • Use H: For industrial labels, outdoor signage, damaged surfaces

3. Data Types and Encoding

Supported Data Modes

// QR Code Data Modes 1. Numeric Mode (0-9) - Most efficient: 10 bits per 3 digits - Example: "1234567890" 2. Alphanumeric Mode (0-9, A-Z, space, $%*+-./:) - 11 bits per 2 characters - Example: "HELLO WORLD" 3. Byte Mode (ISO-8859-1) - 8 bits per character - Supports extended characters - Example: "Hello 世界" 4. Kanji Mode (Shift JIS) - 13 bits per character - For Japanese characters - Example: "日本語" 5. Structured Append - Multiple QR codes as one message - Up to 16 QR codes combined 6. FNC1 Mode - For industry-specific applications - GS1 standards for retail

Common QR Code Formats

// URL (Most Common) https://dailytools.uk // vCard Contact Information BEGIN:VCARD VERSION:3.0 FN:John Doe TEL:+1234567890 EMAIL:[email protected] END:VCARD // WiFi Network Configuration WIFI:S:MyNetwork;T:WPA;P:MyPassword;; // Email mailto:[email protected]?subject=Hello&body=Message // SMS smsto:+1234567890:Hello World // Calendar Event BEGIN:VEVENT SUMMARY:Meeting DTSTART:20260101T090000 DTEND:20260101T100000 END:VEVENT // Bitcoin Payment bitcoin:1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa?amount=0.01 // Plain Text This is a text message stored in QR code

4. Practical Use Cases

Business Applications

Marketing & Advertising

  • Product information and reviews
  • Promotional offers and coupons
  • Event registration and tickets
  • Social media follows and shares
  • App downloads and installations

Retail & E-commerce

  • Product pricing and inventory
  • Mobile payments and checkout
  • Loyalty programs and rewards
  • Customer feedback and reviews
  • Shipping and tracking information

Healthcare

  • Patient identification and records
  • Medication information and dosage
  • Appointment scheduling
  • Medical device tracking
  • Prescription verification

Education

  • Textbook supplements and resources
  • Classroom attendance tracking
  • Library book management
  • Assignment submission
  • Campus navigation and maps

5. Implementation Examples

JavaScript QR Code Generation

// Using qrcode.js library const QRCode = require('qrcode'); // Generate QR code as data URL QRCode.toDataURL('https://dailytools.uk', { errorCorrectionLevel: 'M', type: 'image/png', quality: 0.92, margin: 1, color: { dark: '#000000', light: '#FFFFFF' }, width: 300 }, (err, url) => { if (err) throw err; // Use the data URL const img = document.createElement('img'); img.src = url; document.body.appendChild(img); }); // Generate QR code to canvas const canvas = document.getElementById('qr-canvas'); QRCode.toCanvas(canvas, 'https://dailytools.uk', { errorCorrectionLevel: 'H', margin: 2, width: 200, color: { dark: '#4f46e5', // Indigo light: '#f8fafc' // Slate 50 } }, (error) => { if (error) console.error(error); }); // Generate SVG QRCode.toString('https://dailytools.uk', { type: 'svg', errorCorrectionLevel: 'Q' }, (err, string) => { if (err) throw err; document.getElementById('qr-container').innerHTML = string; });

Python QR Code Generation

# Using qrcode library import qrcode from qrcode.constants import ERROR_CORRECT_H # Basic QR code qr = qrcode.QRCode( version=1, error_correction=ERROR_CORRECT_H, box_size=10, border=4, ) qr.add_data('https://dailytools.uk') qr.make(fit=True) # Create image img = qr.make_image(fill_color="black", back_color="white") img.save("dailytools_qr.png") # Advanced: Custom styling qr_advanced = qrcode.QRCode( version=5, error_correction=ERROR_CORRECT_M, box_size=20, border=2, ) qr_advanced.add_data('https://qr.dailytools.uk') qr_advanced.make(fit=True) img_advanced = qr_advanced.make_image( fill_color="#4f46e5", # Indigo back_color="#f8fafc" # Slate 50 ) img_advanced.save("styled_qr.png") # Generate SVG import qrcode.image.svg as svg factory = svg.SvgPathImage img_svg = qrcode.make('https://dailytools.uk', image_factory=factory) img_svg.save("dailytools_qr.svg")

6. Security Considerations

⚠️ QR Code Security Risks

  • Malicious URLs: QR codes can link to phishing sites or malware
  • Data Theft: Scanning unknown QR codes can expose personal information
  • Physical Tampering: QR codes on public displays can be replaced
  • Social Engineering: QR codes used in phishing campaigns
  • Unencrypted Data: QR codes store data in plain text

Security Best Practices

// 1. URL Validation function validateQRUrl(url) { const allowedDomains = ['dailytools.uk', 'example.com']; const urlObj = new URL(url); if (!allowedDomains.some(domain => urlObj.hostname.endsWith(domain))) { throw new Error('Untrusted domain'); } // Check for HTTPS if (urlObj.protocol !== 'https:') { throw new Error('URL must use HTTPS'); } return true; } // 2. Dynamic QR Codes with Expiration const crypto = require('crypto'); function generateSecureQRData(userId, action) { const timestamp = Date.now(); const token = crypto.randomBytes(32).toString('hex'); const expires = timestamp + (5 * 60 * 1000); // 5 minutes const data = { userId, action, timestamp, token, expires }; // Sign the data const signature = crypto .createHmac('sha256', process.env.QR_SECRET) .update(JSON.stringify(data)) .digest('hex'); data.signature = signature; return Buffer.from(JSON.stringify(data)).toString('base64'); } // 3. QR Code Verification function verifyQRData(encodedData) { const data = JSON.parse(Buffer.from(encodedData, 'base64').toString()); // Check expiration if (Date.now() > data.expires) { throw new Error('QR code expired'); } // Verify signature const expectedSignature = crypto .createHmac('sha256', process.env.QR_SECRET) .update(JSON.stringify({...data, signature: null})) .digest('hex'); if (data.signature !== expectedSignature) { throw new Error('Invalid signature'); } return data; }

7. Tools and Resources

DailyTools.uk QR Code Tool

Use our QR Code Tool to:

  • Generate QR codes from text, URLs, contact info, WiFi, etc.
  • Decode QR codes from images or camera
  • Customize QR code appearance (colors, logo, shape)
  • Test QR code scanning and readability
  • Export QR codes in multiple formats (PNG, SVG, PDF)
  • Create batch QR codes for multiple items

Development Libraries

  • JavaScript: qrcode.js, QRCode.js, node-qrcode
  • Python: qrcode, pyqrcode, segno
  • Java: ZXing ("Zebra Crossing"), QRGen
  • PHP: PHP QR Code, Endroid QR Code
  • Go: go-qrcode, rsc.io/qr
  • .NET: QRCoder, ZXing.Net

Conclusion

QR codes are a versatile and powerful technology for bridging physical and digital worlds. Key takeaways:

Best Practices Summary:
  • Choose appropriate error correction level based on use case
  • Use the smallest version that fits your data to improve scanning
  • Always include sufficient quiet zone (4 modules minimum)
  • Test QR codes on multiple devices and lighting conditions
  • Implement security measures for sensitive applications
  • Provide clear instructions for users on what to expect

For business applications, consider implementing dynamic QR codes that can be updated without changing the physical code, and always track analytics to measure engagement and effectiveness.

Remember that while QR codes are convenient, they should enhance user experience, not replace other necessary information or accessibility features.