Barcode Generator
Generate barcodes from text. Supports multiple barcode formats with customizable size.
Barcode Content
Generated Barcode
Note: This generates a simplified Code 128 barcode representation. For production use, consider a dedicated barcode library.
What Is a Barcode?
A barcode is a machine-readable representation of data in a visual, scannable format. It encodes information — numbers, letters, or special characters — as a series of parallel bars and spaces of varying widths. Barcode scanners read these patterns by measuring the transitions between dark bars and light gaps, translating them back into the original data.
Barcodes are foundational to modern logistics, retail, healthcare, and manufacturing. Every product on a supermarket shelf, every parcel in a shipping warehouse, and every patient wristband in a hospital carries a barcode that uniquely identifies it. Because the data is machine-readable rather than human-readable, barcodes dramatically reduce manual entry errors and accelerate data capture at scale.
This barcode generator tool lets you create a Code 128 barcode from any alphanumeric input, customise the bar width (1–4 px) and overall height (50–200 px), toggle a human-readable text label below the bars, and download the result as a PNG image — all directly in your browser with no server calls and no software to install.
How Barcode Generation Works
The generator follows the Code 128 standard, one of the most versatile linear barcode symbologies in widespread use. Each character is encoded as an 11-bit binary pattern, where 1 represents a black bar and 0 represents a white space. The full barcode pattern is assembled by concatenating three components:
- Start symbol — a fixed 11-bit pattern (
11010010000) that signals the beginning of a Code 128 barcode and identifies which character set is in use (Code Set B for this tool). - Data symbols — one 11-bit pattern per input character, drawn from a lookup table of 43 supported characters (digits 0–9, uppercase A–Z, space, hyphen, and period).
- Stop symbol — a fixed 13-bit termination pattern (
1100011101011) that signals the scanner to stop reading.
Once the full bit string is assembled, the tool renders it onto an HTML5 Canvas element. Each bit position advances the x-coordinate by the chosen bar width. A 1 bit causes a filled rectangle of width × height pixels to be drawn; a 0 bit is left blank (white). The canvas is padded by 20 px on each side to ensure scanners can detect the quiet zone, giving a total canvas width of patternLength × barWidth + 40 pixels.
Canvas Dimension Formulas
Where:
- patternLength= Total number of bits in the assembled barcode string (start + data characters + stop)
- barWidth= Width of each individual bar in pixels (slider range: 1–4 px)
- 40= Horizontal quiet-zone padding: 20 px on each side
- barcodeHeight= Height of the bar area in pixels (slider range: 50–200 px)
- 30= Extra vertical space added when the text label is shown below the bars
Supported Barcode Types
The tool offers four barcode format options in its interface. Understanding the purpose of each helps you choose the right one for your use case:
| Format | Character Set | Typical Use | Digits Required |
|---|---|---|---|
| Code 128 | Full ASCII (128 chars) | Shipping labels, inventory | Variable length |
| Code 39 | 43 characters (A–Z, 0–9, symbols) | Automotive, aerospace | Variable length |
| EAN-13 | Digits only | International retail products | Exactly 13 digits |
| UPC-A | Digits only | US retail products | Exactly 12 digits |
The core barcode pattern rendered on the canvas is always derived from the Code 128 Code Set B lookup table, which covers uppercase letters A–Z, digits 0–9, space, hyphen, and period. Input characters that fall outside this set are silently skipped during pattern assembly, so ensure your input uses only supported characters for accurate results.
Bar Width and Height Settings
Two sliders control the physical dimensions of the generated barcode image.
Bar Width (1–4 px): This setting determines how many pixels wide each individual bar module is. A module is the narrowest element in the barcode — every bar and space in the pattern is a whole-number multiple of this base unit. Wider modules produce a larger, more print-friendly barcode that scanners at longer distances can read more reliably. Narrower modules compress more data into less horizontal space but require a higher-resolution scanner and more precise printing.
Height (50–200 px): Barcode height does not carry data; it is a scanning aid. Taller barcodes allow scanners to read the code even if the beam passes at an angle or if part of the barcode is damaged or obscured. Industry standards like GS1 recommend a minimum height-to-width ratio for reliable scanning in production environments. For web or preview use, a height of 80–120 px with a bar width of 2 px is typically sufficient.
Show text label: When enabled, the plain-text value of your input is printed below the bars in a 14 px monospace font, centred on the canvas. This adds 30 px to the total canvas height. Human-readable text helps people verify the encoded value without a scanner and is required by some labelling standards.
Use Cases and Best Practices
Barcodes generated with this tool are suitable for prototyping, internal labelling, educational demonstrations, and low-volume inventory systems. Here are practical scenarios and guidance for each:
- Inventory tagging: Encode a short SKU or asset number (e.g.,
SKU-0042) and print at 2–3 px bar width, 120 px height. Attach to shelves, boxes, or equipment. - Event check-in: Encode an attendee ID or ticket number. Scan with any Code 128–capable mobile app at the door.
- Library or document management: Assign barcode IDs to folders or files. A spreadsheet scanner can populate a database row per scan.
- Classroom demonstrations: Show students how character patterns map to bars. Decode by eye using the Code 128 pattern table.
- Prototyping retail labels: Mock up product labels for UI/UX design reviews or client presentations before commissioning a certified GS1 barcode.
For production retail use (products sold in stores), you need a GS1-registered barcode with a certified check digit. EAN-13 and UPC-A require the last digit to be a computed check digit derived from the preceding digits using a weighted modulo-10 algorithm. This generator's UI offers EAN-13 and UPC-A as format labels, but always validate your output with a reference decoder before printing labels for commercial distribution.
When downloading the PNG, print at 300 DPI or higher for physical labels. If you are generating barcodes programmatically at scale, a dedicated library such as JsBarcode or bwip-js implements full GS1 compliance including check-digit verification and quiet-zone enforcement.
Worked Examples
Three-digit input "123" at 2 px width
Problem:
Calculate the canvas dimensions when encoding "123" with bar width = 2 px, height = 100 px, and text label shown.
Solution Steps:
- 1Assemble the bit pattern: Start (11 bits) + "1" (11 bits) + "2" (11 bits) + "3" (11 bits) + Stop (13 bits) = 57 bits total.
- 2Compute canvas width: patternLength × barWidth + 40 = 57 × 2 + 40 = 114 + 40 = 154 px.
- 3Compute canvas height: barcodeHeight + 30 (text label shown) = 100 + 30 = 130 px.
- 4The barcode canvas is 154 × 130 px. Bars start at x = 20 px (left quiet zone) and are drawn 100 px tall.
Result:
Canvas: 154 × 130 px. Pattern length: 57 bits.
Five-letter input "HELLO" at 1 px width, no text
Problem:
Determine canvas size for "HELLO" with bar width = 1 px, height = 150 px, and text label hidden.
Solution Steps:
- 1Assemble the bit pattern: Start (11 bits) + "H" (11) + "E" (11) + "L" (11) + "L" (11) + "O" (11) + Stop (13) = 11 + 5×11 + 13 = 11 + 55 + 13 = 79 bits.
- 2Compute canvas width: 79 × 1 + 40 = 79 + 40 = 119 px.
- 3Compute canvas height: showText is false, so no extra 30 px. Height = 150 + 0 = 150 px.
- 4The finished canvas is 119 × 150 px. This narrow bar width demands a high-resolution print or screen for reliable scanning.
Result:
Canvas: 119 × 150 px. Pattern length: 79 bits.
Three-letter input "ABC" at 3 px width, text shown
Problem:
Find canvas dimensions for "ABC" with bar width = 3 px, height = 80 px, and text label shown.
Solution Steps:
- 1Assemble the bit pattern: Start (11 bits) + "A" (11 bits) + "B" (11 bits) + "C" (11 bits) + Stop (13 bits) = 11 + 3×11 + 13 = 11 + 33 + 13 = 57 bits.
- 2Compute canvas width: 57 × 3 + 40 = 171 + 40 = 211 px.
- 3Compute canvas height: 80 + 30 (text label shown) = 110 px.
- 4At 3 px per module, the barcode is wider and more print-friendly while still compact at 211 × 110 px total canvas size.
Result:
Canvas: 211 × 110 px. Pattern length: 57 bits.
Ten-digit default input "1234567890" at 2 px width
Problem:
Verify the canvas size for the tool's default input "1234567890" with bar width = 2 px, height = 100 px, text shown.
Solution Steps:
- 1Assemble the bit pattern: Start (11 bits) + 10 characters × 11 bits each + Stop (13 bits) = 11 + 110 + 13 = 134 bits.
- 2Compute canvas width: 134 × 2 + 40 = 268 + 40 = 308 px.
- 3Compute canvas height: 100 + 30 = 130 px.
- 4This is the default barcode generated on page load: a 308 × 130 px canvas encoding the ten-digit sequence.
Result:
Canvas: 308 × 130 px. Pattern length: 134 bits.
Tips & Best Practices
- ✓Keep input text short (under 20 characters) for barcodes that are compact enough to fit on small labels.
- ✓Use bar width 2–3 px for general-purpose printing; 1 px is best for large-format displays only.
- ✓Always scan the generated barcode with a real scanner app before using it in a production workflow.
- ✓If encoding a number-only string for retail-style use, confirm whether EAN-13 (13 digits) or UPC-A (12 digits) check-digit requirements apply.
- ✓Increase barcode height to at least 100 px when printing labels that may be partially covered or tilted during scanning.
- ✓Enable the text label option so human operators can verify the encoded value without a scanner.
- ✓Avoid using special characters beyond space, hyphen, and period — they are silently skipped and will shorten your barcode unexpectedly.
- ✓Download the PNG at its native pixel dimensions and scale it in your design tool rather than resizing the canvas output, to avoid anti-aliasing blurring the bars.
Frequently Asked Questions
Sources & References
- Code 128 — Wikipedia (2024)
- Barcode — Wikipedia (2024)
- GS1 Barcode Standards (2024)
- EAN-13 — Wikipedia (2024)
Last updated: 2026-06-05
Help us improve!
How would you rate the Barcode Generator?
Editorial Note
MyCalcBuddy Editorial Team
This page is maintained as an educational calculator reference.
Formula Source: Standard Mathematical References
by Various