工具 指南
developer 免费 无需注册

二维码生成器

生成Code 128、Code 39、EAN-13、UPC-A和ITF-14格式的条形码,并下载为SVG或PNG。

正在加载工具…

关于此工具

无需服务器,直接在浏览器中即时生成标准条形码。支持Code 128、Code 39、EAN-13、UPC-A和ITF-14格式,使用纯JavaScript编码和SVG渲染。工具自动计算校验位,并允许您将结果下载为矢量SVG或光栅PNG。

使用方法

  1. 1 从下拉列表中选择条形码格式(如Code 128、EAN-13)。
  2. 2 在输入框中输入要编码的值。
  3. 3 条形码会立即在表单下方渲染为SVG图像。
  4. 4 点击「下载SVG」或「下载PNG」保存条形码文件。

How a 1D barcode encodes data in bars and spaces

A linear (one-dimensional) barcode stores information in the widths of alternating black bars and white spaces along a single line. A scanner sweeps a beam across the symbol, measures how long it stays dark versus light, and translates that sequence of widths back into characters. Each symbology — Code 128, Code 39, EAN-13, UPC-A, ITF-14 — is just a different rulebook for which width patterns map to which characters, plus rules for the start, stop, and check structures that let a scanner know where the code begins, ends, and whether it read correctly. This tool implements those rulebooks in pure JavaScript and draws the result as a crisp SVG, so the bars stay sharp at any size.

Choosing the right symbology

FormatAcceptsTypical use
Code 128All printable ASCIIShipping labels, internal tracking, anything alphanumeric
Code 39A–Z, 0–9, space, - . $ / + %Industry, military, ID badges (older, less dense)
EAN-1312 or 13 digitsRetail products sold internationally
UPC-A11 or 12 digitsRetail products in North America
ITF-1413 or 14 digitsShipping cartons and cases of retail goods

If you just need to encode an arbitrary string — a serial number, a URL fragment, a product name — Code 128 is the right default: it is compact and handles the full ASCII set. The numeric retail formats only exist to fit the global product-numbering system and reject any non-digit input.

The check digit: a worked example

Retail barcodes append a check digit that lets a scanner detect a misread. For EAN-13 it is computed from the first 12 digits: multiply each digit by 1 or 3 in alternating positions, sum them, and the check digit is whatever makes that sum a multiple of 10. Take 400638133393. Summing digits in odd positions (1st, 3rd, …) times 1 and even positions times 3 gives a weighted total; the check digit is (10 − (total mod 10)) mod 10. This tool does that automatically — if you enter 12 digits it calculates and appends the 13th for you, and if you enter all 13 it validates the last one and refuses the code if it doesn't match. That validation is a feature: a typo in a product number produces a barcode that real scanners would reject anyway, so the tool catches it up front. UPC-A is computed the same way (it is internally an EAN-13 with a leading zero), and ITF-14 uses an equivalent modulo-10 scheme.

Practical tips for codes that actually scan

  • Keep the quiet zone. Barcodes need clear white margin on both ends (roughly 10× a narrow-bar width for EAN/UPC). The SVG includes padding — don't crop it away when placing the code.
  • Download SVG for print, PNG for the web. SVG is vector, so it stays razor-sharp at any print size; the PNG export rasterizes at 2× resolution for places that won't accept SVG. For physical labels, prefer SVG.
  • Don't stretch the height freely, and never the width. Horizontal scaling distorts the bar-to-space ratios the scanner relies on. Resize proportionally only.
  • Mind contrast. Black bars on a white background is the safe choice. Red bars or low-contrast colors can be invisible to laser scanners, which often read in red light.
  • Test on the real medium. Print it and scan it with a phone or handheld reader before committing to a run; ink bleed and glossy glare both reduce readability.

Common mistakes

  • Wrong digit count. EAN-13 needs exactly 12 or 13 digits, UPC-A 11 or 12, ITF-14 13 or 14. Spaces and dashes are stripped, but letters in a numeric format are rejected.
  • Expecting Code 39 to handle lowercase. Standard Code 39 is uppercase only; this tool uppercases your input automatically, which can surprise you if case mattered.
  • Confusing a 1D barcode with a QR code. These linear codes hold a short identifier, not a webpage. For URLs and rich data, use a QR (2D) code instead.

Everything runs in your browser

All encoding, check-digit calculation, and rendering happen entirely on your device in JavaScript. Nothing you type is sent to a server, so product numbers and serial codes you generate stay private — you can confirm this by generating a barcode with your network disconnected.

常见问题

{# Alpine.js — self-hosted. (The previous jsdelivr CDN tag had a stale SRI integrity hash, so the browser refused to run it and window.Alpine was never defined — silently breaking every FAQ accordion and Alpine tool.) #}