Barcode
Since 0.1.0-alpha.21A barcode shows a value as bars for a scanner, with the value printed under them. It renders on the server as an SVG, so it works with JavaScript off, scales without blurring, and prints. For a link or longer text, see QrCode.
A shipping or order number
The default type, Code 128, accepts any ASCII text, such as letters, digits, dashes and spaces. Set Value to the text.
Static
Preview
Tracking number
Code
@* A shipping label's number: Code 128 holds letters, digits and dashes. *@
<Card MaxWidth="28.Rem">
<CardBody Gap="2">
<TextBlock Size="TextSize.Sm" Color="Color.Muted">Tracking number</TextBlock>
<Barcode Value="SHIP-2026-0417" Label="Tracking number" />
</CardBody>
</Card>Add this example to a page with the izzy CLI:
izzy add component Barcode --at <file>:<line>Digits take half the room of letters, so a mostly numeric value makes a shorter barcode. With no value yet, such as while the page loads it, nothing renders.
Products
For a retail product, set Type to Ean13, UpcA or Ean8. The digits print in the standard layout, between the guard bars.
Static
Preview
Code
@* A product's EAN-13 and UPC-A: give 12 or 11 digits and the check digit is added. *@
<Row Gap="6" Wrap Align="Align.End">
<Barcode Value="400638133393" Type="BarcodeType.Ean13" />
<Barcode Value="03600029145" Type="BarcodeType.UpcA" />
<Barcode Value="9638507" Type="BarcodeType.Ean8" />
</Row>Without the check digit, the barcode adds it. With it, the barcode checks it and throws if it's wrong, since a mistyped code would scan as another product.
Size and print
BarWidth sets the width of the narrowest bar, 2px by default, and the barcode is as wide as its bars need. BarHeight sets the bars' height in the same units, 50 by default. The blank margins on either side are part of the barcode: scanners need them, so keep other content out of them.
In a narrower box the barcode shrinks and keeps its shape. Below about 1.5px per bar, a phone's camera may not read it, so give it the room or use a shorter value.
For print, set BarWidth in millimetres, Length.Of("0.33mm"): that's EAN's standard size, and GS1 permits down to 0.264mm. A full-height EAN-13 at that size has a BarHeight of about 69; shorter bars are harder for retail scanners.
Labels and localization
Screen readers hear "Barcode" and the value. To say what the barcode is for, set Label, such as "Tracking number": the name becomes "Tracking number, SHIP-2026-0417". When the value is written beside it, set Decorative so screen readers skip it.
The default name comes from the app's text (IzzyText.BarcodeLabel, "Barcode {0}", where {0} is the value). To set it for the whole app, see Text and other languages.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Everything | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Accessibility
- It's an image (
role="img") named "Barcode" and its value (IzzyText.BarcodeLabel), as the value is printed under it anyway;Labelreplaces "Barcode", and the value still follows. - The text under the bars is hidden from screen readers, as the name says it.
- Set
Decorativewhen the value is written beside it, so it's skipped. - It's dark on light in both color schemes, as scanners need.
Parameters
| Prop | Type | Default |
|---|---|---|
ValueWhat to encode: any ASCII text for BarcodeType.Code128; the digits for EAN and UPC, with or without the check digit (added when it's left off, checked when it's there). | string | Required |
TypeThe kind of barcode. | BarcodeType | BarcodeType.Code128 |
BarWidthThe width of the narrowest bar; the barcode is as wide as its bars need. | Length? | computed |
BarHeightThe bars' height, in widths of the narrowest bar, so the barcode scales as one. | int | 50 |
ShowTextThe value under the bars. | bool | true |
LabelWhat the barcode is, for screen readers, such as "Tracking number": the name becomes it and the value, "Tracking number, SHIP-2026-0417". | string? | |
DecorativeHides it from screen readers, for when the value is written beside it. | bool | false |
Plus 17 item props and 4 common props.
Full APISee also
- QrCode: shows text, such as a link, as a QR code to scan.