Barcode Generator
Generate barcodes in Code 128, Code 39, EAN-13, and UPC-A formats. Renders as SVG with PNG download. No external libraries needed.
This barcode generator produces standard-compliant 1D barcodes in Code 128, Code 39, EAN-13, and UPC-A formats, rendered client-side as clean SVG with a 2x PNG download option. Code 128 handles any printable ASCII input, EAN-13 encodes 13-digit retail product codes, UPC-A encodes 12-digit North American retail codes, and Code 39 handles alphanumeric IDs for inventory, libraries, and asset tags.
About Barcode Generator
How Barcodes Encode Data
A 1D barcode represents data as a series of parallel bars and spaces of varying widths. A laser or camera scanner measures the widths in sequence, converts them back to numbers, and maps those numbers to characters using the symbology's lookup table. Each format has its own encoding rules, a required start and stop pattern, and usually a checksum so scanners can detect damaged or misread codes.
Worked example (UPC-A check digit for 04210000526): Multiply odd-positioned digits (from the left, 1-indexed) by 3 and even-positioned digits by 1: (0x3)+(4x1)+(2x3)+(1x1)+(0x3)+(0x1)+(0x3)+(0x1)+(5x3)+(2x1)+(6x3) = 0+4+6+1+0+0+0+0+15+2+18 = 46. The check digit is the number that brings the total to the next multiple of 10, so (10 - (46 mod 10)) mod 10 = 4. The complete barcode is 042100005264.
Supported Barcode Formats
| Format | Characters Supported | Length | Common Uses |
|---|---|---|---|
| Code 128 | All 128 ASCII characters (letters, numbers, symbols) | Variable | Shipping labels, logistics, general-purpose barcodes |
| Code 39 | A-Z, 0-9, space, - . $ / + % | Variable | Automotive, defence, government ID badges |
| EAN-13 | Digits only (0-9) | 13 digits (12 + 1 check digit) | International retail products, books (ISBN) |
| UPC-A | Digits only (0-9) | 12 digits (11 + 1 check digit) | North American retail products |
How to Use the Generator
| Step | Action |
|---|---|
| 1. Choose format | Select the barcode type that matches your use case |
| 2. Enter data | Type or paste the value to encode (the tool validates input in real time) |
| 3. Adjust settings | Set bar height and toggle text display below the barcode |
| 4. Preview | The barcode renders instantly as you type |
| 5. Export | Copy the SVG code or download as a 2x resolution PNG |
Which Format Should You Use?
| Scenario | Recommended Format | Why |
|---|---|---|
| Shipping labels | Code 128 | Compact encoding, supports all ASCII characters, universally scanned |
| Inventory asset tags | Code 128 or Code 39 | Code 128 for mixed data; Code 39 for simple alphanumeric IDs |
| Retail product (worldwide) | EAN-13 | Required by retailers outside North America; also encodes ISBNs |
| Retail product (US/Canada) | UPC-A | Standard for North American point-of-sale systems |
| Library books | Code 39 or Code 128 | Many library systems use Code 39 for patron and item barcodes |
| Event tickets | Code 128 | Can encode alphanumeric ticket IDs efficiently |
Check Digit Calculation
EAN-13 and UPC-A barcodes include a check digit as the final character. This digit is calculated from the preceding digits using a weighted sum formula and catches single-digit errors and most transposition errors during scanning. When you enter your data digits, this tool calculates and appends the correct check digit automatically - you do not need to calculate it yourself.
| Format | You Enter | Tool Outputs | Check Digit Method |
|---|---|---|---|
| EAN-13 | 12 digits | 13-digit barcode (12 + check) | Alternating weights of 1 and 3, mod 10 |
| UPC-A | 11 digits | 12-digit barcode (11 + check) | Alternating weights of 3 and 1, mod 10 |
| Code 128 | Any text | Barcode with built-in checksum | Weighted modular sum |
| Code 39 | Alphanumeric text | Barcode (optional check digit) | Modulo 43 sum |
1D Barcodes vs QR Codes
| Feature | 1D Barcode (this tool) | QR Code |
|---|---|---|
| Data capacity | ~20-80 characters | Up to ~4,296 characters |
| Data types | Primarily text and numbers | URLs, text, WiFi credentials, vCards, any binary data |
| Scanning direction | Horizontal only - scanner must align with bars | Any angle - reads in all orientations |
| Physical size | Wide and short | Compact square |
| Scanner compatibility | Laser and CCD scanners (retail, logistics) | Smartphone cameras and image-based scanners |
| Industry standard | Retail POS, shipping, manufacturing | Marketing, mobile apps, contactless sharing |
Printing and Sizing Tips
| Tip | Why |
|---|---|
| Use the 2x PNG for print | Higher resolution produces sharper bars at small sizes |
| Maintain quiet zones | Leave blank space on either side of the barcode (at least 10x the narrowest bar width) |
| Do not stretch horizontally | Distorting the bar widths makes the code unscannable |
| Print on light backgrounds | Dark bars on white/light backgrounds scan most reliably |
| Test before bulk printing | Scan a test print with your actual scanner to confirm readability |
Common Mistakes When Generating Barcodes
| Mistake | What Goes Wrong | How to Avoid It |
|---|---|---|
| Printing too small | Bars blur together and the scanner cannot resolve narrow bars from wide ones | GS1 recommends a nominal X-dimension (narrowest bar) of 0.33 mm for retail POS, with a minimum of 0.264 mm. For supply chain barcodes the minimum is 0.495 mm. |
| No quiet zone | Scanner cannot find the start and stop patterns, so the read fails or decodes partial data | Leave blank margin of at least 10x the narrowest bar width on both sides. For EAN-13 this is typically 7 modules left and right. |
| Stretched horizontally | Bar widths no longer match the ratios the symbology requires, breaking the decode | Always scale proportionally. If you need a different size, regenerate the barcode rather than stretching the image. |
| Wrong contrast | Low print contrast between bars and background causes scanners to misread or reject the code | Print black bars on white, cream, or very light backgrounds. Avoid red backgrounds - many red laser scanners read red bars as spaces. |
| Reusing another company's GS1 prefix | Products collide with an existing GTIN at retail | Only use EAN-13 or UPC-A codes that your company has been assigned by GS1. For internal use, a different symbology (Code 128 or Code 39) is safer. |
| Embedding special characters in Code 39 | Generator rejects the input because Code 39 only supports a limited character set | Switch to Code 128, which encodes any printable ASCII character including lowercase letters and punctuation. |
Which Barcode Is Used Where?
| Industry | Typical Symbology | Why |
|---|---|---|
| Grocery and general retail (worldwide) | EAN-13 | Assigned and managed by GS1 member organisations in over 110 countries. The first 2-3 digits identify the GS1 prefix, the next block identifies the brand owner, and the remainder identifies the product. |
| North American retail | UPC-A | The original 12-digit symbol adopted in 1974 with the first retail scan of a pack of Wrigley's gum. UPC-A is a subset of EAN-13 with an implied leading zero. |
| Books and periodicals | EAN-13 (ISBN/ISSN) | ISBNs have been encoded as 13-digit EAN barcodes since 2007. The prefix 978 or 979 identifies a book, and the check digit follows the standard EAN-13 rule. |
| Healthcare and pharmaceuticals | GS1-128 (Code 128 variant) | Encodes GTIN plus batch, expiry, and serial using GS1 Application Identifiers. Required by the EU Falsified Medicines Directive and the US Drug Supply Chain Security Act. |
| Shipping and logistics | Code 128 (SSCC-18) | GS1 Serial Shipping Container Code encoded as Code 128 for pallet tracking. Dense encoding keeps the label small. |
| Automotive and defence | Code 39 | Adopted by the US Department of Defense (LOGMARS) and the Automotive Industry Action Group. Self-checking, does not require a checksum, simple scanner electronics. |
| Libraries | Code 39 or Codabar | Many older library management systems still use Code 39 for patron cards and item labels. Newer systems moved to Code 128 for density. |
How the Check Digit Catches Errors
The Mod 10 check digit used by EAN-13 and UPC-A is designed to catch the most common keying and scanning errors. It always detects any single-digit error (typing one digit wrong) and detects around 90 percent of two-digit transposition errors. It does not catch every transposition - swapping two digits of equal weight (both odd-position or both even-position) can produce the same checksum - but it is effective enough to keep false reads from propagating into retail databases. Code 128 uses a different scheme, a modulo 103 weighted checksum calculated across every encoded value, which is even stronger because the weighting is linear rather than alternating.
Quiet Zones and Print Resolution
The quiet zone is the blank margin around a barcode that tells the scanner where the symbol begins and ends. GS1 specifies a minimum quiet zone of 7 modules (seven narrow-bar widths) on the left and right of every EAN-13 barcode. Omitting quiet zones is the most common reason retail barcodes fail at checkout - the bars scan fine, but the scanner cannot find the start pattern. For Code 128 the rule is 10 times the narrowest bar on each side, and for Code 39 it is 10 times the narrowest bar or 0.25 inches, whichever is greater.
Print resolution matters more than most people realise. A 300 dpi laser printer produces bars with an edge jitter of roughly 0.08 mm, which is fine for retail EAN at the nominal size but can fail at 80 percent magnification. Thermal transfer printers at 203 dpi are the industry standard for shipping labels because the dot placement is more consistent. Ink-jet printers often struggle because ink bleed widens the dark bars, narrowing the spaces, and a scanner calibrated for the nominal ratios rejects the decode. If you are printing at high volume, test the output with the actual scanner model rather than relying on a smartphone app that is often more forgiving than industrial hardware.
Barcode or QR Code: Which Should You Use?
1D barcodes remain dominant in retail point-of-sale and high-speed logistics because laser scanners are inexpensive, fast, and reliable. QR codes are better when you need to encode URLs, WiFi credentials, payment data, or more than around 80 characters. For most consumer-facing uses like restaurant menus, marketing posters, or contactless sharing, use the QR Code Generator. For inventory and retail tags, stick with 1D barcodes from this tool. For generating unique identifiers to encode, the UUID Generator creates RFC 4122 compliant IDs that pair well with Code 128. For shorter random strings, the Password Generator can produce alphanumeric tokens that fit in Code 39.
All encoding happens in your browser. No input is ever sent to a server, which makes this tool safe for confidential asset tags, internal part numbers, and pre-release SKUs.
Sources
Frequently Asked Questions
Which barcode format should I use?
Code 128 is the most versatile and can encode all ASCII characters, making it ideal for most purposes. Use EAN-13 for European retail products, UPC-A for North American retail, and Code 39 if you only need alphanumeric characters and your industry requires it.
How do check digits work for EAN-13 and UPC-A?
EAN-13 and UPC-A include a check digit as the last number to detect scanning errors. If you enter 12 digits for EAN-13 or 11 for UPC-A, the tool automatically calculates and appends the correct check digit. If you enter the full number including the check digit, it verifies that it is correct.
Can I use these barcodes commercially?
The barcodes this tool generates are standard-compliant and scannable. For retail products using EAN or UPC codes, you need to register with GS1 to get an assigned number range. Code 128 and Code 39 can be used freely for internal purposes like inventory tracking.
What file formats can I download?
The barcode renders as SVG in the browser, which you can copy directly. You can also download it as a 2x resolution PNG file for use in documents, labels, or print materials.
Related Tools
Link to this tool
Copy this HTML to link to this tool from your website or blog.
<a href="https://toolboxkit.io/tools/barcode-generator/" title="Barcode Generator - Free Online Tool">Try Barcode Generator on ToolboxKit.io</a>