Barcode Generator

EAN-13, EAN-8 and UPC-A as SVG, with the check digit worked out, the quiet zone kept and the printed size in millimetres.

Live output

Enable JavaScript to customise; default output below.

Symbology

EAN-13 is the worldwide retail standard, UPC-A is its North American twelve-digit form, EAN-8 is for packages too small for thirteen digits.

Leave the check digit off and it is worked out for you. Paste it on and it is verified instead.

The standard allows 80 to 200 percent of the nominal size. This sets the millimetre figures, not the SVG's pixel size.

Live preview ean-13-4006381333931.svg.txt
Symbology               EAN-13
Code                    4006381333931
Check digit             1 (worked out for you)

At 100% magnification
  Module width          0.330 mm
  Symbol width          37.29 mm
  Symbol height         25.93 mm
  Quiet zone each side  2.97 mm

SVG
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 226 73" width="226" height="73" role="img" aria-label="EAN-13 barcode 4006381333931">
	<rect width="226" height="73" fill="#ffffff" />
	<g fill="#000000">
		<rect x="18" y="0" width="2" height="66.05" />
		<rect x="22" y="0" width="2" height="66.05" />
		<rect x="30" y="0" width="4" height="60" />
		<rect x="36" y="0" width="2" height="60" />
		<rect x="40" y="0" width="2" height="60" />
		<rect x="46" y="0" width="6" height="60" />
		<rect x="54" y="0" width="2" height="60" />
		<rect x="58" y="0" width="8" height="60" />
		<rect x="68" y="0" width="8" height="60" />
		<rect x="78" y="0" width="2" height="60" />
		<rect x="86" y="0" width="2" height="60" />
		<rect x="92" y="0" width="2" height="60" />
		<rect x="96" y="0" width="4" height="60" />
		<rect x="104" y="0" width="4" height="60" />
		<rect x="110" y="0" width="2" height="66.05" />
		<rect x="114" y="0" width="2" height="66.05" />
		<rect x="118" y="0" width="2" height="60" />
		<rect x="128" y="0" width="2" height="60" />
		<rect x="132" y="0" width="2" height="60" />
		<rect x="142" y="0" width="2" height="60" />
		<rect x="146" y="0" width="2" height="60" />
		<rect x="156" y="0" width="2" height="60" />
		<rect x="160" y="0" width="6" height="60" />
		<rect x="168" y="0" width="2" height="60" />
		<rect x="174" y="0" width="2" height="60" />
		<rect x="184" y="0" width="2" height="60" />
		<rect x="188" y="0" width="4" height="60" />
		<rect x="196" y="0" width="4" height="60" />
		<rect x="202" y="0" width="2" height="66.05" />
		<rect x="206" y="0" width="2" height="66.05" />
	</g>
	<text x="2" y="72" font-family="monospace" font-size="9" fill="#000000">4</text>
	<text x="68" y="72" text-anchor="middle" font-family="monospace" font-size="9" fill="#000000">006381</text>
	<text x="162" y="72" text-anchor="middle" font-family="monospace" font-size="9" fill="#000000">333931</text>
</svg>

The check digit is 1, from the alternating weighted sum of the other 12
digits. The weights count from the right, so they sit in different
columns for EAN-13 than for the other lengths, and getting that
backwards gives the right answer about half the time.

The 400 to 440 range was allocated through GS1 Germany.

The white space at each end is part of the symbol, not a margin you can
crop. 2.97 mm each side at this magnification, and without it the
scanner has nothing to measure the module width against. On a busy piece
of packaging it is the first thing a designer removes and the first
reason the barcode stops working.

Printed size is the other half. At 100 percent this symbol is 37.29 mm
wide with a module of 0.330 mm. The standard allows 80 to 200 percent;
keep it above 100 unless the packaging genuinely cannot take it, and
never scale it non-uniformly.

A GTIN is allocated, not invented. The company prefix comes from GS1 and
the item numbers are yours to assign inside it. A made-up number either
belongs to somebody else or fails the retailer's checks, and the
in-store range, 02 and 20 to 29, is the right answer for internal
labelling.

Print black on white and leave it alone: no gradients, no light bars on
dark, no rounded corners, no logo across the middle. Red bars are
invisible to a red laser scanner. Image scanners cope with more, and the
ones at a supermarket till often do not.

Output is valid and updates as you type.

EAN-13, EAN-8 and UPC-A, drawn as SVG, with the check digit worked out and the printed size in millimetres.

Three things decide whether a barcode scans, and only one of them is the drawing. The check digit has to be right. The quiet zone, the white margin at each end, has to be there, because the scanner measures the module width against it. And the symbol has to be printed somewhere between 80 and 200 percent of its nominal size. A barcode that fails at the till gets typed in by hand, and it is nearly always one of those three.

How to use

  1. Pick the symbology.
  2. Type the digits without the check digit, and it is calculated. Paste it on and it is verified.
  3. Set the print magnification for the millimetre figures.
  4. Copy the SVG.

Example

400638133393 as an EAN-13:

Symbology               EAN-13
Code                    4006381333931
Check digit             1 (worked out for you)

At 100% magnification
  Module width          0.330 mm
  Symbol width          37.29 mm
  Symbol height         25.93 mm
  Quiet zone each side  2.97 mm

37.29 by 25.93 millimetres is the nominal EAN-13 size, and the 2.97 millimetres at each end is part of it rather than a margin around it.

Pitfalls

The check digit weights count from the right. Alternating 3 and 1, starting with 3 at the rightmost digit of the body. Because the body is a different length for EAN-13 and EAN-8, the weights fall in different columns, and an implementation that counts from the left gets the right answer often enough to pass a careless test.

The quiet zone is not a margin. Crop it and the barcode stops working. It is the first thing a designer removes when a label is tight and the first reason a barcode fails. On EAN-13 it is nine modules each side.

Do not scale it non-uniformly. Stretching the width changes the module widths relative to each other and the symbol becomes unreadable. Scale both dimensions together, inside the 80 to 200 percent range, or leave it alone.

A GTIN is allocated, not invented. The leading digits are a company prefix issued by GS1. A number you made up either belongs to somebody else’s product or fails a retailer’s validation. For internal labelling, the in-store ranges, 02 and 20 to 29, exist precisely so you can print numbers that are valid inside your own shop and nowhere else.

The prefix is not the country of manufacture. 400 to 440 means the number was issued through GS1 Germany, not that the product was made there. This is repeated as fact all over the internet and it is wrong in both directions.

Red bars are invisible to a red laser. So are low-contrast bars, gradients, and light bars on a dark background. Black on white, and nothing across the middle. Image scanners cope with more than laser scanners; the ones at a supermarket till often do not.

Bar height matters more than it looks. A short barcode gives the scanner less to aim at, and a scan that misses the middle of the symbol fails. The standard proportion is about 70 percent of the symbol width; truncating the height is allowed and it costs reliability.

Compatibility

Everything runs in the browser: nothing is uploaded and nothing is stored.

The output is SVG, so it prints at whatever resolution the printer has. That matters more here than for most graphics: a barcode rasterised at 72 dpi and printed at 100 percent has bars whose widths have been rounded, and the rounding is what a scanner reads as the wrong module width. If you need a raster, export at 600 dpi or more.

The encoding was verified by decoding it back. The module strings for every symbology are fed through a decoder in the test suite, and the rendered SVGs were read by Chrome’s own BarcodeDetector, which returned the same digits that went in: 4006381333931 and 9780201379624 as EAN-13, 96385074 as EAN-8, and the UPC-A as the EAN-13 0036000291452, which is what a UPC-A is.

The nominal module width used for the millimetre figures is GS1’s 0.33 mm, giving 37.29 mm by 25.93 mm at 100 percent for EAN-13. Those are the numbers on the GS1 specification sheet.

UPC-A is not a separate symbology in any technical sense: it is an EAN-13 whose first digit is zero, which is why the same drawing code produces both and why a scanner reports one as the other.

Frequently asked questions

Can I make up a barcode number?
For internal use, yes, from the in-store range: start with 02 or 20 to 29 and the number is reserved for use inside your own premises. For anything you sell through a retailer, no. You need a GS1 company prefix.
Which should I use, EAN-13 or UPC-A?
EAN-13 unless a North American retailer specifically asks for twelve digits. They are the same symbol and every modern scanner reads both.
What about Code 128 or QR codes?
Not here. Code 128 carries letters as well as digits and is the right choice for internal labels and shipping; this tool covers the retail GTIN family. For a QR code, the QR generator on this site encodes text and URLs.
Why is my barcode not scanning?
In order of likelihood: the quiet zone has been cropped, it has been printed too small, it has been stretched in one direction, the contrast is too low, or it is printed on a curved or shiny surface. Check those five before suspecting the number.
How big should I print it?
100 percent unless the packaging genuinely cannot take 37 mm. 80 percent is the floor and it is a real floor: below it the bars are narrower than many scanners in the field can resolve.
Weekly drops

New tools, when there are new tools

One email when something worth using ships. No schedule to fill, so no filler.

Your address goes nowhere else, and one click unsubscribes.