UPC-A barcodes

UPC-A encodes 12 digits: 11 data digits and a check digit. Open Barcode computes the check digit, or verifies it when you pass all 12 digits.

Input rules

Example

Input 03600029145 encodes as 036000291452. 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 { UPC } from "@openbarcode/javascript/linear";
const modules = new UPC("03600029145").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 UPC-A barcode.

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

const modules = new UPC("03600029145").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