# Barcodes

> Code128, EAN-13 and 8, UPC-A, Code39, ITF, ITF-14: check digits and scannable sizes.

Source: https://82label.app/en/docs/barcodes/

A barcode is one element. The value alone is enough: without a position it goes in the middle of the label, 80% wide.

```js
{ type: 'barcode', value: '{{sku}}' }                       // Code 128, centred
{ type: 'barcode', x: 3, y: 14, w: 44, h: 13, format: 'ean13', value: '{{ean}}', showText: true }
```

```js
Label82.barcodeSVG('880123456789', { format: 'ean13', height: 18 })
```

## Formats

| format | Value | Used for |
| --- | --- | --- |
| `code128` | Digits, letters, symbols, any length | The default. SKUs, order numbers, waybills. Long digit runs switch to the dense C set automatically. |
| `ean13` | 12 digits (+1 check) | Retail product barcodes. Give 12 digits and the check digit is added; give 13 and it is verified. |
| `ean8` | 7 digits (+1 check) | Small products. |
| `upca` | 11 digits (+1 check) | North American retail. |
| `code39` | Upper-case letters, digits, `- . space $ / + %` | Older in-house systems, asset tags. |
| `itf14` | 13 digits (+1 check) | Shipping cartons (GTIN-14). |
| `itf` | An even number of digits | Interleaved 2 of 5 with no check digit. Hanjin and Lotte tracking numbers. |

## Invalid values

A value that does not fit the format (wrong EAN length, lower case in Code39 …) is drawn as a crossed box and reported in the print result's `errors`. To check ahead, call `encodeBarcode`.

```js
import { encodeBarcode, eanCheckDigit, BarcodeError } from '@82label/core';

eanCheckDigit('880123456789'); // 3 → 8801234567893
try {
  encodeBarcode('ean13', '88012345');
} catch (e) {
  if (e instanceof BarcodeError) console.log(e.message);
}

const r = await Label82.print(template, rows);
r.errors; // [{ element: 2, code: 'barcode_invalid', message: '…' }]
```

## Sizes that scan

- The narrow bar (module) is snapped to whole printer dots (`paper.dpi`). At 203 dpi a dot is 0.125 mm.
- Keep a quiet zone of ten modules on each side; do not run the barcode to the label edge.
- Make it at least 10 mm tall; 15 mm or more for barcodes read from a distance, like waybills.
- A long value in a narrow box pushes modules below 0.19 mm and scanners struggle. The designer warns you.

## A barcode on its own

Need only the barcode picture? `barcodeSVG` returns an SVG string for a screen or a PDF.

```js
Label82.barcodeSVG('EP-2026-0412', { height: 15, showText: true });
Label82.barcodeSVG('880123456789', { format: 'ean13', moduleWidth: 0.33 });
```
