https://github.com/bmlt-enabled/qrcode-svg
ES module for generating SVG QR codes in pure JavaScript
https://github.com/bmlt-enabled/qrcode-svg
Last synced: 4 days ago
JSON representation
ES module for generating SVG QR codes in pure JavaScript
- Host: GitHub
- URL: https://github.com/bmlt-enabled/qrcode-svg
- Owner: bmlt-enabled
- License: mit
- Created: 2026-04-11T02:08:32.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-06-14T15:17:23.000Z (16 days ago)
- Last Synced: 2026-06-14T17:14:24.650Z (15 days ago)
- Language: JavaScript
- Homepage: https://qrcode.bmlt.app/
- Size: 246 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
## Introduction
An ES module for generating SVG QR codes in pure JavaScript. Works in the browser and Node.js (>=22).
- pure JavaScript, zero dependencies
- ESM only
- SVG output
## Getting Started
Install the package:
```bash
npm install @bmlt-enabled/qrcode-svg
```
Inline example:
```javascript
import QRCode from '@bmlt-enabled/qrcode-svg'
const svg = new QRCode('Hello World!').svg()
```
More options:
```javascript
const qrcode = new QRCode({
content: 'http://github.com/',
padding: 4,
width: 256,
height: 256,
color: '#000000',
background: '#ffffff',
ecl: 'M',
})
const svg = qrcode.svg()
```
## Options
**List of options:**
- **content** - QR Code content, the only **required** parameter
- **padding** - white space padding, `4` modules by default, `0` for no border
- **width** - QR Code width in pixels
- **height** - QR Code height in pixels
- **color** - color of modules (squares), color name or hex string, e.g. `#000000`
- **background** - color of background, color name or hex string, e.g. `white`
- **ecl** - error correction level: `L`, `M`, `Q`, `H`
- **join** - join modules (squares) into one shape, into the SVG `path` element, **recommended** for web and responsive use, default: `false`
- **predefined** - to create a squares as pattern, then populate the canvas, default: `false`, see the output examples below
- **pretty** - apply indents and new lines, default: `true`
- **swap** - swap X and Y modules, only if you have issues with some QR readers, default: `false`
- **xmlDeclaration** - prepend XML declaration to the SVG document, i.e. ``, default: `true`
- **container** - wrapping element, default: `svg`, see below
- **typeNumber** - QR version (1–40), determined automatically if not set
- **image** - center logo to overlay, as a URL or data URI, see [Center logo](#center-logo)
- **imageSize** - logo size as a fraction of the QR's shorter side (`0`–`1`), default: `0.2`
- **imageBackground** - backdrop fill behind the logo, default: the `background` color
- **imageBackgroundShape** - backdrop shape: `rounded` (default), `circle`, or `none`
**Container options:**
- **svg** - populate squares in a SVG document with `width` and `height` attributes, recommended for converting to raster images or PDF where QR Code is being static (exact size)
- **svg-viewbox** - populate squares in a SVG document with `viewBox` attribute, **recommended** for responsive web pages
- **g** - put squares in `g` element, useful when you need to put multiple QR Codes in a single SVG document
- **none** - no wrapper
- **path-data** - returns only the raw SVG path data string (join mode is applied automatically)
## SVG output
### Editable squares
This mode is useful for designers to manipulate with particular squares.
Thus, one can open the QR Code in an editor, select particular modules, move around, change color, etc.
However, some old SVG viewers may generate minor gaps between the squares - the side effect when rendering an image at certain zoom level.
Default options
```javascript
const qrcode = new QRCode({
content: 'Pretty Fox',
join: false,
predefined: false,
})
```
Output with `rect` elements
```xml
...
```
### Responsive web page
Squares joined into one `path` shape produce a compact file size, i.e. 4-5x reduced compared with `rect` elements.
A single `path` element will result in an optimized rendering, thus not producing any minor gaps between the squares.
Also using the container with `viewBox` attribute may contribute to the responsive scaling on the web.
Set `join` to `true`
```javascript
const qrcode = new QRCode({
content: 'Pretty Fox',
join: true,
container: 'svg-viewbox', //Useful but not required
})
```
Output with `path` element
```xml
```
### Predefined pattern
Algorithm defines the square pattern once before populating a canvas. Useful if you want to generate QR Code with candies.
However, some SVG software and converters do not support `defs` or `use` elements.
Set `predefined` to `true`
```javascript
const qrcode = new QRCode({
content: 'Pretty Fox',
predefined: true,
})
```
Output with `defs` and `use` elements
```xml
...
```
### Center logo
Overlay a logo in the middle of the QR Code by passing an `image` (a URL or
data URI). The image is drawn on top of the modules — it does **not** remove
any data. The modules it covers are recovered by error correction, so set
`ecl: 'H'` and keep the logo small (≈20–25%) so the code still scans.
```javascript
const qrcode = new QRCode({
content: 'https://bmlt.app',
ecl: 'H', // high error correction keeps it scannable under the logo
image: 'data:image/png;base64,iVBORw0KGgo...', // or 'https://…/logo.png'
imageSize: 0.22, // fraction of the shorter side
imageBackgroundShape: 'rounded', // 'rounded' | 'circle' | 'none'
container: 'svg-viewbox',
join: true,
})
```
A backdrop in the `background` color (or `imageBackground`) is drawn behind the
logo by default so it stays legible against the modules. The logo is emitted as
an `` element in the SVG, so it is included in any PNG you rasterize from
it. The `path-data` container ignores `image` (it returns path data only).
## Usage in the browser
```html
import QRCode from 'https://cdn.jsdelivr.net/npm/@bmlt-enabled/qrcode-svg/dist/qrcode.js'
const qrcode = new QRCode({
content: 'Hello World!',
container: 'svg-viewbox',
join: true,
})
document.getElementById('container').innerHTML = qrcode.svg()
```
When using a bundler (Vite, Webpack, etc.), you can use the bare specifier instead:
```javascript
import QRCode from '@bmlt-enabled/qrcode-svg'
```
## Credits & lineage
This package is a modernized (ESM-only, browser and Node.js, Vite-built, typed) fork of the `qrcode-svg` library. Full lineage:
- Originally created by [papnkukn/qrcode-svg](https://github.com/papnkukn/qrcode-svg).
- Forked and deobfuscated by [leMaik/qrcode-svg](https://github.com/leMaik/qrcode-svg/)
- This fork (`@bmlt-enabled/qrcode-svg`) drops the Node CLI, `save()`/`fs` usage, and the ASCII helper; converts to ESM; adds Vite + Vitest + TypeScript declarations.
Thanks to [davidshimjs](https://github.com/davidshimjs/qrcodejs) for the base library, and to [Kazuhiko Arase](http://www.d-project.com/) for the original QR Code in JavaScript algorithm.
## Legal notice
Licensed under the [MIT license](https://opensource.org/license/mit).
The word "QR Code" is a registered trademark of [DENSO WAVE INCORPORATED](https://www.qrcode.com/en/patent.html).