ZPL Examples
Eight ZPL examples, from a 4 × 6 in shipping label to QR and Data Matrix codes, each drawn beside its code so you can change it and see the result, without the ZPL leaving your device.
How to use these ZPL examples
Pick an example
Choose one from the Samples list above the ZPL box, which is open on this page and holds the eight labels below. It loads into the box and the label is drawn.
Change it
Edit any value: a position after
^FO, the text after^FD, a size after^A. The label is drawn again a moment after you stop typing.Use it
Copy the code into your own label, or save the result with Download PNG or Download PDF. Each example below explains the commands it uses.
What each part of a ZPL file does: What is a ZPL file?
How to read the examples
The examples are written for an 8 dpmm (203 dpi) printer. Positions and sizes are in printer dots, counted from the top left corner of the label: in ^FO40,48, 40 is the distance across and 48 the distance down. Each label starts with ^XA and ends with ^XZ, and each field ends with ^FS.
Each heading gives the smallest inch size in the Label size list that holds the example. Choosing an example does not change the label size, and 4 × 6 in, the size the viewer starts with on a first visit, holds all eight.
The code is shown on one line. In the editor the samples are laid out one field per line, which is easier to change; Zebra's guide shows the same label written one command per line and as a single line, and the printer reads both the same way.
Shipping label (4 × 6 in)
A parcel label with a heading, a dock number in large text, a line in font D, a bin and a route, a sort zone in a box and a Code 128 barcode, divided by lines. This is the Shipping label sample, with single spaces where its text has three:
^XA^FO40,48^A0N,34,32^FDPARCEL / TEST STOCK^FS^FO40,105^GB730,5,5^FS^FO40,160^A0N,80,70^FDDOCK 07^FS^FO42,275^ADN,36,20^FDPACKING STATION 03^FS^FO40,345^GB730,4,4^FS^FO40,396^A0N,32,30^FDBIN C-12^FS^FO40,468^A0N,32,30^FDROUTE NORTH LOOP^FS^FO40,595^GB730,132,4^FS^FO66,629^A0N,60,52^FDSORT / BLUE^FS^BY3,2,110^FO64,845^BCN,110,Y,N,N^FDDEMO-0703^FS^XZ
Each field is ^FO with its position, ^FD with its text and ^FS to close it. ^A0N,34,32 sets font 0, upright, 34 dots high and 32 wide, for the field after it, and each text field here sets its own size this way. ^ADN,36,20 uses font D at twice its base size of 18 × 10 dots. ^GB730,5,5 draws a box 730 dots wide and 5 high with a 5-dot border, which prints as a solid line across the label, and ^GB730,132,4 draws the box around the sort zone with a 4-dot border.
^BY3,2,110 sets the narrowest bar of the barcodes after it to 3 dots and their height to 110 dots; the 2 is a wide-to-narrow bar ratio, which Code 128 ignores because its ratio is fixed. ^BCN,110,Y,N,N is a Code 128 barcode, upright, 110 dots high, with its text printed under the bars and no UCC check digit.
Product label with an EAN-13 barcode (3 × 2 in)
A product name and an EAN-13 retail barcode:
^XA^FO40,45^A0N,52,46^FDLINEN / OCHRE^FS^BY3^FO60,170^BEN,110,Y,N^FD200123456789^FS^XZ
^BEN,110,Y,N is EAN-13, upright, 110 dots high, with the digits printed under the bars. Its ^FD holds exactly 12 digits: Zebra's guide says ZPL II truncates the data or pads it on the left with zeros to make 12. The barcode adds a 13th digit, the check digit, so a scanner reads 2001234567893. For a UPC-A barcode, use ^BU with exactly 11 digits. ^BY3 sets the narrowest bar to 3 dots for this barcode and the ones after it.
Code 128 barcode (2.25 × 1.25 in)
One Code 128 barcode with its text under it:
^XA^BY3,2,72^FO56,55^BCN,80,Y,N,N^FDCRATE-17^FS^XZ
^BY3,2,72 sets a default height of 72 dots, and the 80 in ^BCN,80,Y,N,N replaces it for this barcode, so its bars are 80 dots high. Code 128 encodes letters, digits and symbols in three subsets. With no start code in the data, the printer uses subset B. Add A as a sixth value, as in ^BCN,80,Y,N,N,A, and the printer chooses the subsets itself: Zebra's guide says a run of four or more digits then switches to subset C. To make the barcode wider or narrower, change the first value of ^BY, the width of the narrowest bar in dots, from 1 to 10.
QR code (2.25 × 1.25 in)
A QR code holding a short text:
^XA^FO56,64^BQN,2,7^FDLA,WORKSHOP-QR^FS^XZ
^BQN,2,7 is a QR code, model 2 (the model Zebra recommends), at magnification 7; Zebra's default is 2 on 200 dpi printers and 3 on 300 dpi ones. The first characters of the field data are settings, not data: L sets the error correction level (H, Q, M or L, from the most reliable to the densest), and A, lets the printer choose how to encode the data that follows, so a scanner reads WORKSHOP-QR. Zebra's guide says ^FW does not rotate a QR code.
Data Matrix (2 × 1 in)
A Data Matrix symbol holding a short text:
^XA^FO56,64^BXN,6,200^FDWORKSHOP-DM^FS^XZ
^BXN,6,200 is Data Matrix, upright, with each square element 6 dots high and wide, at quality 200. Quality 200 uses Reed-Solomon error correction, and Zebra's guide recommends it for new applications; the lower qualities are for closed systems. The printer sizes the symbol to the data: here the viewer draws 16 by 16 elements, 96 dots square. To make a GS1 or other Data Matrix symbol with its own settings, datamatrixgenerator.app makes one as a picture.
Wrapped text block (2.25 × 1.25 in)
A sentence that wraps inside a set width:
^XA^FO50,70^A0N,44,36^FB340,5,8,L,0^FDStore the small parts in the marked bin before packing.^FS^XZ
^FB340,5,8,L,0 makes a block 340 dots wide with at most 5 lines, 8 extra dots between lines, left-justified, and no hanging indent. The printer wraps the words to fit, here on three lines. Text longer than the block prints over its last line, so raise the line count if the end is missing. Inside the block, \& starts a new line.
Boxes, lines and circles (4 × 4 in)
A box with rounded corners, a circle, an ellipse and a diagonal line:
^XA^FO60,80^GB420,180,8,B,4^FS^FO90,320^GC140,8^FS^FO300,320^GE200,120,8^FS^FO90,570^GD280,130,9,B,R^FS^XZ
^GB420,180,8,B,4 is a box 420 dots wide and 180 high with an 8-dot border, in black (B; W is white), with its corners rounded at 4 on a scale from 0 to 8. When the height or the width is no more than the border, as in ^GB730,5,5 in the shipping label, the box prints as a solid line. ^GC140,8 is a circle 140 dots across with an 8-dot outline, which grows inward from the edge, and ^GE200,120,8 an ellipse 200 dots wide and 120 high. ^GD280,130,9,B,R draws a line 9 dots thick across a box 280 by 130 dots, leaning right.
A picture with ^GF (2 × 1 in)
In ZPL, a logo or picture is written out as dots. This one is a small pattern, 16 dots wide and 16 high:
^XA^FO40,50^GFA,32,32,2,FF818181FF818181FF818181FF818181FF818181FF818181FF818181FF818181^FS^XZ
^GFA,32,32,2 means the data is in ASCII hexadecimal, 32 bytes in all, a picture 32 bytes in size, and 2 bytes in each row, so the picture has 16 rows of 16 dots. Each hex digit stands for four dots, and a 1 is a black dot. The rows alternate: FF81 is a row whose first nine dots and last dot are black, and 8181 a row with dots 1, 8, 9 and 16 black.
Hexadecimal takes two characters for every 8 dots, so Zebra's guide also describes two shorter encodings for downloaded data: B64, the data in Base64 (:B64:), and Z64, the data compressed with LZ77 and then Base64-encoded (:Z64:). The viewer draws both. A picture can also be stored on the printer with ~DG and printed in later labels with ^XG; the viewer draws it when both are in the same ZPL and ~DG names the memory, such as R:.
Frequently asked questions
Can you provide an example ZPL file?
Every example on this page is a whole ZPL label. Copy one into a text file, save it with the .zpl extension, and open it here or send it to a Zebra printer.
How can I create a ZPL file?
Write the commands in any plain text editor, such as Notepad on Windows, starting each label with ^XA and ending it with ^XZ, and save the file as text. Start from one of these examples and check each change in the viewer.
How do I print a barcode in ZPL?
Set its size with ^BY, place the field with ^FO, choose the barcode type, such as ^BC for Code 128, ^BE for EAN-13 or ^BQ for QR, and put the data in ^FD, ending with ^FS.
How do I draw a line in ZPL?
Use ^GB with one side no thicker than the border: ^GB730,4,4 in the shipping label is a line 730 dots long and 4 thick, and ^GB4,160,4 is an upright line 160 dots long.
How do I print a test label on a Zebra printer?
Zebra's user guides test a printer by sending it a file that holds only ~WC, which prints the printer's configuration report. That report comes from the printer itself, so the viewer finds no label in such a file. To test a label layout, send one of these examples.
Why is there a crossed-out box instead of my barcode?
The viewer draws a crossed-out box that names the command in place of a barcode it cannot draw: Code 49, CODABLOCK, TLC39 and GS1 DataBar composite symbols ("^B4 not supported", for example), and a barcode command whose settings it cannot read ("^BQ has invalid parameters"). The line under the preview lists the command as not drawn. Data a barcode type cannot hold is not always refused: letters in a UPC-A or EAN-13 field are drawn as zeros, so check the digits under the bars.