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

CommandMeaning here
^XAStart of the label format.
^PW812Print width: 812 dots (4 inches at 203 dpi).
^LL406Label length: 406 dots (2 inches at 203 dpi).
^FO40,40Field origin: the next field starts 40 dots from the left and 40 dots from the top.
^A0N,40,40Font 0, normal orientation, 40 dots high and 40 dots wide.
^FDHello labelField data: the text to print.
^FSField separator: ends the field.
^GB732,3,3Graphic box 732 × 3 dots with a line thickness of 3: a horizontal line.
^BY3,3,120Barcode defaults: module width 3 dots, wide-to-narrow ratio 3, height 120 dots.
^BCN,120,Y,N,NCode 128, normal orientation, 120 dots high, interpretation line printed below.
^XZEnd 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