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
- Accepts A–Z, 0–9, space and - . $ / + %. Lowercase letters are converted to uppercase.
- Start and stop characters (*) are added automatically.
- Any other character raises an error that names the character and its position.
Example
Input CODE39 encodes as *CODE39*.
- Each character is 12 modules wide, and a 1-module gap separates characters.
- No check digit is added. CODE39 encodes to 103 modules.
Generate it in JavaScript
The same pattern applies in every language. Here is JavaScript as an example.
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.
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.