QR Code Generator
Fully-functional QR code generator for Node.js and the browser, with zero dependencies
Show code in browser
IMG tag
// Show QR code in HTML as an image
document.getElementById('container')!.innerHTML = qrCode.createImgTag(
10, // Each block will be 10 by 10 pixels
20, // 20 pixels of margin around the code
'Scan the QR code' // alt tag value
)A SVG image
// Show QR code as SVG
document.getElementById('container')!.innerHTML = qrCode.createSvgTag({
cellSize: 10, // Each block will be 10 by 10 pixels
margin: 20, // 20 pixels of margin around the code
title: {
text: 'Visit my website' // Show a title above the QR code
},
alt: {
text: 'Scan the QR code' // Show description above the QR code
}
})HTML table
// Show QR code as HTML table (e.g. for emails or other places with only basic HTML support)
document.getElementById('container')!.innerHTML = qrCode.createTableTag(
10, // Each block will be 10 by 10 pixels
20 // 20 pixels of margin around the code
)Open a new page
// Get a data URL and open it in a new window
window.open(qrCode.toDataURL(
10, // Each block will be 10 by 10 pixels
20 // 20 pixels of margin around the code
))Render on a canvas
// Render QR code on a canvas
qrCode.renderTo2dContext(
document.querySelector<HTMLCanvasElement>('canvas#container')!.getContext('2d')!,
10 // Each block will be 10 by 10 pixels
)in Node.js
Show QR code in CLI
// Code as ASCII characters
console.log(qrCode.createASCII(
2, // 2 terminal cells per block
4 // 4 cells of margin
))Save as SVG
const code = qrCode.createSvgTag({
cellSize: 10, // Each block will be 10 by 10 pixels
margin: 20, // 20 pixels of margin around the code
title: {
text: 'Visit my website' // Show a title above the QR code
},
alt: {
text: 'Scan the QR code' // Show description above the QR code
}
})
await writeFile('qr-code.svg', `<?xml version="1.0" encoding="UTF-8"?>
${code}
`)