ZPL Commands

ZPL Commands Cheat Sheet: The Commands You Will Use Most

The ZPL commands that build almost every label, grouped by job, with syntax and a one line example for each.

By ZPL Viewer Editorial Team4 min read

Key points

  • Format commands start with a caret (^); control commands that act immediately start with a tilde (~).
  • A field is usually position, font or barcode, data, then ^FS.
  • Settings like ^CF, ^BY, ^LH and ^FW apply to every following field in the label.
  • Printer settings such as ^MD and ~SD change print quality, not layout.

ZPL has well over a hundred commands, but a typical label uses fewer than fifteen. This cheat sheet groups the essentials by job. Every example is valid ZPL; paste any of them into the ZPL Viewer, and its command inspector will explain the rest of your file line by line.

Format structure

CommandPurposeExample
^XAStart a label format^XA
^XZEnd the format and print^XZ
^FSEnd a field^FDText^FS
^FXComment^FX Address block
^PQPrint quantity^PQ3 prints three copies

Positioning

CommandPurposeExample
^FOx,yField origin: top left corner of the field^FO50,100
^FTx,yField typeset: text baseline or barcode bottom^FT50,140
^LHx,yLabel home: offset for all following fields^LH20,10
^LSxLabel shift left or right^LS-10
^FWrDefault field rotation: N, R, I or B^FWR

Text

CommandPurposeExample
^Afo,h,wFont f, orientation o, height h, width w^A0N,40,36
^CFf,h,wChange default font^CF0,30
^FDdataField data^FDHello^FS
^FBw,l,s,j,hField block: width, max lines, spacing, justification, indent^FB600,3,0,C
^FHcHex escapes in the next ^FD^FH^FDA_5EB^FS prints A^B
^CI28Interpret field data as UTF-8^CI28

More in ZPL fonts and text formatting.

Barcodes

CommandSymbologyExample
^BYw,r,hModule width, ratio, default height^BY3,3,120
^BCCode 128 and GS1-128^BCN,120,Y,N,N^FD12345^FS
^B3Code 39^B3N,N,100,Y,N
^BE / ^BUEAN-13 / UPC-A^BEN,100,Y,N
^BQQR Code^BQN,2,6^FDQA,text^FS
^BXData Matrix^BXN,8,200
^B7PDF417^B7N,8,5,6

Details in the ZPL barcode guide and QR codes in ZPL.

Graphics

CommandPurposeExample
^GBw,h,t,c,rBox or line; thickness, colour, rounding^GB700,3,3^FS
^GCd,t,cCircle^GC100,5,B
^GEw,h,t,cEllipse^GE200,100,4
^GDw,h,t,c,oDiagonal line, R or L leaning^GD200,100,5,B,R
^GFa,b,c,d,dataBitmap graphic^GFA,8,8,1,FF818181818181FF
^FR / ^LRYReverse one field / the whole label^FR^FDWHITE^FS
Most of this cheat sheet on one label
^XA
^PW812
^LL609
^LH0,0
^CF0,30
^FO40,40^A0N,46,46^FDZPL cheat sheet demo^FS
^FO40,100^FB730,2,4,L^FDText wraps inside a field block that is 730 dots wide.^FS
^FO40,180^GB730,3,3^FS
^FO40,210^GC90,6,B^FS
^FO160,210^GE160,90,6,B^FS
^FO350,210^GD120,90,6,B,R^FS
^FO520,200^GB250,110,110,B,3^FS
^FO550,230^FR^A0N,50,46^FDFR^FS
^BY2,3,100
^FO40,350^BCN,100,Y,N,N^FDCHEAT-SHEET^FS
^FO560,340^BQN,2,4^FDQA,ZPL^FS
^XZ

Label and printer settings

  • ^PWw print width and ^LLl label length, both in dots.
  • ^POI prints the label upside down; ^PMY mirrors it.
  • ^MDn and ~SDnn set darkness; ^PRs sets speed.
  • ^MNY and ^MTT or ^MTD set media tracking and thermal transfer or direct thermal.
  • ^JUS saves current settings permanently, so use it deliberately.

How to read an unfamiliar ZPL file

When someone hands you a long file, work through it in this order:

  1. Find the label boundaries. Count the ^XA and ^XZ pairs to see how many labels the file prints.
  2. Read the settings at the top. ^PW, ^LL, ^LH, ^CI, ^CF and ^BY change how every later field behaves.
  3. Split it into fields. Each ^FO or ^FT starts a field and each ^FS ends one. The Format button in the ZPL Viewer does this for you.
  4. Ignore printer settings for layout work. Commands such as ~SD, ^MD, ^PR and ^MN affect print quality and media, not positions.
  5. Check the inspector. Anything marked "Not drawn" or listed in Warnings is where surprises usually hide.

Stored formats and graphics

Store a format, then reuse it
^XA^DFR:SHELF.ZPL^FS
^FO40,40^A0N,50,50^FN1^FS
^FO40,110^BCN,100,Y,N,N^FN2^FS
^XZ
^XA^XFR:SHELF.ZPL^FS
^FN1^FDAisle 4 Bay 2^FS
^FN2^FDA04B02^FS
^XZ

^DF saves the layout in printer memory with numbered fields; ^XF recalls it and ^FN fills each field. Similarly, ~DG downloads a graphic and ^XG prints it. Our viewer supports both as long as the download happens earlier in the same file.

Preview this in the ZPL Viewer

Paste your code, pick the label size and density, then check every field before you print.

Open the viewer

Frequently asked questions

What is the difference between ^ and ~ commands?

Caret commands are format commands that build the label between ^XA and ^XZ. Tilde commands are control commands that the printer acts on immediately, such as ~DG to download a graphic or ~SD to set darkness.

Are ZPL commands case sensitive?

Command letters are generally accepted in upper or lower case, but parameters such as orientation letters and stored file names should be written exactly as documented. Upper case is the convention.

What is the minimum ZPL needed to print text?

Five commands: ^XA^FO50,50^A0N,50,50^FDHello^FS^XZ. That places the word Hello with the scalable font at 50 dots from the top left corner.

Where can I find the full ZPL command reference?

Zebra publishes the ZPL II Programming Guide with every command and parameter. Our viewer’s inspector also explains each command in your file.

Sources and further reading

Written by the ZPL Viewer Editorial Team

We build and maintain the ZPL Viewer rendering engine and write these guides from real testing of label code. Every example in this article was rendered in our viewer before publishing. Read more about how we work.