v22.18.0 release notes

Barcode

Barcode draws linear barcodes as SVG rendered on the server: Code 128, EAN-13, EAN-8, UPC-A, UPC-E, Code 39, ITF-14, Interleaved 2 of 5 and Codabar, with the human-readable digits, computed and validated check digits, an error state and PNG or SVG downloads. It has no dependency.

View as .md
import { Barcode } from '@exhaustive-ui/core/barcode';

Barcode encodes its value into a linear barcode, drawn as an inline SVG that is crisp at any zoom and rendered on the server. The default format is code128, which encodes any ASCII text: the encoder picks the code sets that make the shortest symbol, two digits a bar pattern in runs of digits. The value is printed under the bars.

EXH-2026-0042

format selects the symbology. Every encoder is part of the component, with no dependency.

  • code128: any ASCII text, with automatic switches between the code sets A, B and C for the shortest symbol. Shipping labels, logistics, tickets.
  • ean13 and ean8: retail products, 12 or 7 digits and a check digit.
  • upca and upce: retail products in North America; UPC-E is the zero-suppressed form of a UPC-A number, with a number system 0 or 1.
  • code39: upper case letters, digits, space and - . $ / + %, common in industry and on badges.
  • itf14: shipping cartons, 13 digits and a check digit, with bearer bars above and below.
  • itf: Interleaved 2 of 5, an even number of digits.
  • codabar: digits and - $ : / . + between start and stop letters A to D, used by libraries and blood banks.

Each format has the quiet zone its specification recommends, and its own text layout.

Exhaustive-128
Code 128
4006381333931
EAN-13
96385074
EAN-8
036000291452
UPC-A
01234565
UPC-E
CODE-39
Code 39
15400141288763
ITF-14
12345678
Interleaved 2 of 5
40156
Codabar

The human-readable value is printed under the bars, the check digit included. EAN and UPC follow the layout of product packaging: the start, center and end guard bars go down between the digit groups, the first digit of EAN-13 sits in the left quiet zone, and the first and last digits of UPC-A and UPC-E are printed smaller outside the bars. The quiet zone grows when a digit needs more room.

displayValue set to false hides the text, and fontSize sets its size in pixels. The font is the barcode.text.font.family design token, a monospace stack.

5901234123457036000291452

width is the width of the narrowest bar, a module, in pixels: 2 by default. Whole pixels keep the edges sharp on screen. height is the height of the bars without the text, 80 pixels by default. margin is the quiet zone on each side, in modules; leave it to the default of the format, as scanners need that light space to find the bars. The SVG shrinks to the width of its container on small screens.

color paints the bars and the text, background the background and the quiet zones; both accept any CSS color and default to the barcode.foreground and barcode.background design tokens, black on white in both color schemes. Scanners read the contrast between dark bars and a light background: keep the bars dark, avoid red bars, which laser scanners cannot see, and inverted colors.

SMALL-01LARGE-01
400638133393196385074

EAN, UPC and ITF-14 take the digits with or without their check digit: when it is missing it is computed, when it is given it is validated. checksum adds the optional check character of Code 39 (modulo 43) and of Interleaved 2 of 5 (modulo 10); Code 128 always has its own.

A value the format cannot encode draws no bars: a wrong check digit, a character the format does not have or a wrong length. The component displays an error state instead, announced to screen readers, and emits onError with a reason, invalid-character, invalid-length, invalid-check-digit or invalid-format, and an English message that tells what is wrong, for example the expected check digit. The error template replaces the error state, and its texts can be translated through labels. An empty value draws nothing and is not an error.

Valid EAN-13
4006381333931
Code 39 has no lower case letter: code 39
Invalid barcode value. It has a character this format cannot encode.

download(filename, type, scale) saves the barcode as a PNG or SVG file and toDataURL(type, scale) returns it as a data URL; both return a promise and are only available in the browser. The PNG is scale times the size displayed, 1 by default: a whole number keeps every module the same width. toSVG() returns the SVG markup as a string, to print a label or to send to a server. The exports have the colors and the font displayed.

15400141288763

Screen Reader

The SVG has the img role and an accessible name made of the barcode text of labels, the format and the encoded value with its check digit, for example "Barcode EAN-13: 4006381333931", so that a screen reader user gets the number without a scanner. ariaLabel replaces it, for example with what the barcode is for, and ariaLabelledBy refers to a visible caption. The bars and the printed digits are inside the image and are not read one by one.

When the value cannot be encoded, the error state is plain text that tells what is wrong, and a polite live region announces it when the value changes, "Invalid barcode value. Its check digit is wrong.". The warning icon is hidden from assistive technologies. Every text can be translated through labels.

The bars stay black on white in dark mode, the contrast scanners need; the error state follows the color scheme.

<p-barcode value="4006381333931" format="ean13" />

<p-barcode [value]="trackingNumber" ariaLabel="Tracking number of the parcel" />

<p-barcode [value]="sku" format="ean13" [labels]="{ barcode: 'Code-barres', invalid: 'Code-barres invalide', invalidCheckDigit: 'La clé de contrôle est fausse.' }" />

Keyboard Support

The barcode is an image and is not focusable: it has no keyboard interaction.