Code 39 barcodes

Code 39 is a variable-length alphanumeric barcode. It encodes letters, digits and a few symbols, and is common in logistics and industry.

Input rules

Example

Input CODE39 encodes as *CODE39*.

Generate it in JavaScript

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

JavaScriptjavascript
import { Code39 } from "@openbarcode/javascript/linear";
const modules = new Code39("CODE39").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 Code 39 barcode.

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

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