ZPL basics
ZPL (Zebra Programming Language) describes a label as a list of commands. Most start with ^, a few printer control commands with ~. Everything is measured in dots of the printer (see ZPL dots and printer resolution).
A complete label
^XA
^PW812^LL406
^FO40,40^A0N,40,40^FDHello label^FS
^FO40,100^GB732,3,3^FS
^BY3,3,120
^FO60,130^BCN,120,Y,N,N^FDABC-12345^FS
^XZ
Open this label in the ZPL Viewer
Line by line
| Command | Meaning here |
|---|---|
^XA | Start of the label format. |
^PW812 | Print width: 812 dots (4 inches at 203 dpi). |
^LL406 | Label length: 406 dots (2 inches at 203 dpi). |
^FO40,40 | Field origin: the next field starts 40 dots from the left and 40 dots from the top. |
^A0N,40,40 | Font 0, normal orientation, 40 dots high and 40 dots wide. |
^FDHello label | Field data: the text to print. |
^FS | Field separator: ends the field. |
^GB732,3,3 | Graphic box 732 × 3 dots with a line thickness of 3: a horizontal line. |
^BY3,3,120 | Barcode defaults: module width 3 dots, wide-to-narrow ratio 3, height 120 dots. |
^BCN,120,Y,N,N | Code 128, normal orientation, 120 dots high, interpretation line printed below. |
^XZ | End of the label format. The printer prints the label now. |
Coordinates
The origin is the top-left corner of the label. x grows to the right, y grows downwards. ^FO places the top-left corner of a field. ^FT is the alternative that places text by its baseline. ^LH moves the origin of the whole label.
Common mistakes
- Missing
^FS: the next field’s commands run into the previous field. - Missing
^XZ: the printer waits for the end of the format and prints nothing. - Fields outside
^PW/^LL: they are cut off or land on the next label. - Designed for 203 dpi, printed at 300 dpi: everything comes out about one third smaller. Convert the dot values first.
- Text that should fit exactly: Zebra fonts are proprietary, every preview (ours included) substitutes them. Positions, lines and barcodes are exact, text widths are not. Confirm with a test print.
Related tools
- ZPL Viewer: render ZPL, list warnings and commands
- ZPL Playground: edit with highlighting, inline errors and command help
- Barcode to ZPL: generate the barcode commands for your data
- Label Size Calculator:
^PWand^LLfor your label - Label Position Calculator:
^FOvalues to centre or align fields