EAN-13 barcodes

EAN-13 encodes 13 digits: 12 data digits and a check digit. It is the retail barcode used worldwide and is defined by GS1.

Input rules

Example

Input 400638133393 encodes as 4006381333931. The barcode is 95 modules wide.

Generate it in JavaScript

The same pattern applies in every language. Here is JavaScript as an example.

JavaScriptjavascript
import { EAN } from "@openbarcode/javascript/linear";
const modules = new EAN("400638133393").barcode();

Draw it as SVG

The library returns the module pattern, so you draw it yourself. This example writes one SVG bar for each module of a EAN-13 barcode.

JavaScriptjavascript
import { EAN } from "@openbarcode/javascript/linear";

const modules = new EAN("400638133393").barcode();
const quiet = 10;
const width = modules.length + quiet * 2;
const bars = modules
  .map((m, i) => (m ? `<rect x="${i + quiet}" width="1" height="100"/>` : ""))
  .join("");
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} 100">${bars}</svg>`;

Try it in the live generator, which renders this way in your browser.

Other barcode types