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:

  1. 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).
  2. 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).
  3. 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

canvasWidth = patternLength × barWidth + 40 canvasHeight = barcodeHeight + (showText ? 30 : 0)

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:

  1. 1Assemble the bit pattern: Start (11 bits) + "1" (11 bits) + "2" (11 bits) + "3" (11 bits) + Stop (13 bits) = 57 bits total.
  2. 2Compute canvas width: patternLength × barWidth + 40 = 57 × 2 + 40 = 114 + 40 = 154 px.
  3. 3Compute canvas height: barcodeHeight + 30 (text label shown) = 100 + 30 = 130 px.
  4. 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:

  1. 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.
  2. 2Compute canvas width: 79 × 1 + 40 = 79 + 40 = 119 px.
  3. 3Compute canvas height: showText is false, so no extra 30 px. Height = 150 + 0 = 150 px.
  4. 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:

  1. 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.
  2. 2Compute canvas width: 57 × 3 + 40 = 171 + 40 = 211 px.
  3. 3Compute canvas height: 80 + 30 (text label shown) = 110 px.
  4. 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:

  1. 1Assemble the bit pattern: Start (11 bits) + 10 characters × 11 bits each + Stop (13 bits) = 11 + 110 + 13 = 134 bits.
  2. 2Compute canvas width: 134 × 2 + 40 = 268 + 40 = 308 px.
  3. 3Compute canvas height: 100 + 30 = 130 px.
  4. 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

The tool uses the Code 128 Code Set B lookup table, which covers uppercase A–Z, digits 0–9, space, hyphen, and period. Lowercase letters are automatically converted to uppercase before encoding. Characters outside this supported set are silently skipped, so the resulting barcode may be shorter than expected if unsupported characters are present. Full Code 128 supports all 128 ASCII characters when Code Set A or C switching is used, but this simplified implementation targets the most common printable characters.
Not directly. Retail barcodes such as EAN-13 and UPC-A must be registered with GS1, the international standards body, and include a mathematically verified check digit as the last digit. This tool does not compute or validate check digits. For prototype or internal use the generated barcode is sufficient, but for products sold in stores you need a GS1 Company Prefix and a certified barcode with the correct check digit calculated via the weighted modulo-10 algorithm.
For printing on a standard inkjet or laser printer at 300 DPI or higher, a bar width of 2–3 px in this generator typically produces a scannable label. Very narrow widths (1 px) may cause bars to bleed together on low-resolution printers, making the barcode unreadable. If you plan to print at a small physical size, increase the bar width to 3–4 px to keep the bars distinct. Always test-print and scan with a real scanner before mass-producing labels.
In the current implementation, the canvas rendering always uses the Code 128 bit-pattern lookup table regardless of which type button is selected. The type selector reflects the intended standard, but the underlying canvas drawing logic in the useMemo hook is a unified Code 128 encoder. For a production system that strictly enforces each format's encoding rules, character sets, and check digits, a dedicated library such as JsBarcode or bwip-js should be used.
Any standard barcode scanner app on iOS or Android (such as Google Lens, Scandit, or a dedicated barcode reader) can scan a Code 128 barcode from a phone or printed sheet. Most point-of-sale scanners and USB barcode readers also support Code 128 out of the box. Simply point the scanner at the barcode and it will decode and display the original text string. Ensure adequate contrast (black bars on a white background) and sufficient quiet zones (the white margins on each side) for reliable reads.
The quiet zone is the blank white space on either side of the barcode. Scanners use the quiet zone to detect where the barcode begins and ends — without it, they may fail to lock onto the pattern. The generator adds 20 px of padding on each side (40 px total) to ensure a minimal quiet zone in the PNG output. Industry standards recommend a quiet zone of at least 10× the width of the narrowest bar module, so for a 2 px bar width that means at least 20 px per side, which this tool satisfies exactly.
This tool generates one barcode at a time interactively. For bulk generation — for example, creating hundreds of unique serial number barcodes — consider using a JavaScript barcode library (JsBarcode, bwip-js) in a Node.js script, or a spreadsheet add-in that renders barcodes from a column of values. The same Code 128 encoding logic applies: each unique input produces a unique bit pattern, and the canvas dimensions scale with the input length and bar width settings.

Sources & References

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.

Source

Formula Source: Standard Mathematical References

by Various

UpdatedLast reviewed: May 2026
CheckedFormula checks are based on standard references and internal QA review.