← Back to Blog
ZPL & Zebra Printing

ZPL Command Reference: ^XA and ^XZ (Label Home and End)

Olivia MorganJuly 3, 2026822 views

In ZPL (Zebra Programming Language), ^XA marks the start of a label format and ^XZ marks its end. Every valid label sent to a Zebra printer must open with ^XA and close with ^XZ; nothing outside those two commands is treated as part of the label. Label Toolkit's browser-based ZPL export wraps every design in this pair automatically, so your output is always structurally correct.

  • ^XA tells the printer to begin a new label format and clears the format buffer.
  • ^XZ tells the printer the format is complete and triggers label printing.
  • All other ZPL commands, including field origins (^FO), field data (^FD), barcodes (^BC), and fonts (^A0), must appear between these two delimiters.
  • Forgetting either delimiter is the single most common cause of a Zebra printer receiving data but printing nothing.

What exactly do ^XA and ^XZ mean?

The caret (^) is ZPL's command prefix character. XA stands for "format start" (think of it as "eXecute A label") and XZ stands for "format end." Together they define a label format, which is the complete set of instructions Zebra firmware needs to render one or more identical labels.

When the printer's firmware receives ^XA, it allocates a format buffer and begins parsing subsequent bytes as ZPL commands. When it receives ^XZ, it commits the buffer, renders the image at the configured DPI (dots per inch, also expressed as dpmm, dots per millimeter), and feeds the label. A 203 dpi printer produces approximately 8 dots per millimeter; a 300 dpi printer produces roughly 12 dots per millimeter. The physical dot size affects minimum readable barcode widths and text legibility, but ^XA/^XZ themselves are DPI-agnostic.

For a broader orientation to the language, see the complete guide to ZPL II before working through individual commands.

The minimal valid ZPL label

The shortest syntactically valid ZPL document is just two lines:

^XA
^XZ

This prints a blank label. It is useful for advancing (feeding) media without printing content, for example when calibrating label gap sensors.

A real working label with text and a barcode

Below is a complete, copy-paste ZPL format that prints a human-readable line of text and a Code 128 barcode on a 4 inch x 2 inch (101.6 mm x 50.8 mm) label at 203 dpi. Coordinates are in dots (1 dot = 1/203 inch at 203 dpi).

^XA
^FO50,30^A0N,40,30^FDShip-To: Warehouse B^FS
^FO50,90^BY2^BCN,80,Y,N,N^FD123456789012^FS
^XZ

Command-by-command breakdown:

  1. ^XA opens the format.
  2. ^FO50,30 sets the field origin to x=50 dots, y=30 dots from the top-left corner.
  3. ^A0N,40,30 selects the scalable font (font 0), orientation Normal, height 40 dots, width 30 dots.
  4. ^FD...^FS wraps the field data between "field data" start and "field separator" end.
  5. ^FO50,90 moves down to y=90 dots for the barcode row.
  6. ^BY2 sets the barcode module width to 2 dots (the narrowest bar).
  7. ^BCN,80,Y,N,N prints a Code 128 barcode: Normal orientation, 80 dots tall, with a human-readable interpretation line below.
  8. ^FD123456789012^FS supplies the barcode data and closes the field.
  9. ^XZ closes the format and fires the print.
Annotated diagram of a ZPL label showing XA at top, field commands in the middle, and XZ at the bottom with arrows pointing to each section

Rules and edge cases you need to know

Can you use lowercase? Does whitespace matter?

ZPL commands are case-sensitive. ^xa is not the same as ^XA. Many Zebra printers accept ^xa in practice, but the Zebra ZPL II Programming Guide specifies uppercase, and relying on lowercase is fragile across firmware versions. Always use uppercase.

Whitespace (spaces, tabs, newlines) between commands is ignored by the parser. You can write the entire format on one line or spread it across many lines for readability. Neither approach affects the printed output.

Can you nest multiple ^XA...^XZ blocks?

No. You cannot nest one format inside another. If the printer encounters a second ^XA before it sees ^XZ, firmware behavior varies by model, but most printers treat the second ^XA as an implicit close of the previous format and a start of a new one. This can result in partial or missing labels. Always close every format with ^XZ before opening a new ^XA.

Printing multiple copies of the same label

You do not repeat ^XA...^XZ to get multiple copies. Instead, use the ^PQ (Print Quantity) command inside the format:

^XA
^FO50,30^A0N,40,30^FDProduct Label^FS
^PQ5,0,1,Y
^XZ

^PQ5,0,1,Y prints 5 copies, with 0 labels between cuts, 1 reprint on error, and Y meaning "override" for the cut behavior. This is far more efficient than sending five separate ^XA...^XZ blocks because the format is compiled once in firmware.

Stored (recalled) formats and ^XA

ZPL supports storing a format in printer memory using ^DF (Download Format) and recalling it later. When you recall a stored format and supply variable data, you still wrap the recall command in ^XA...^XZ. For example:

^XA
^XFR:LABEL01.ZPL^FS
^FN1^FDSKU-98765^FS
^XZ

^XF calls the stored format; ^FN1 fills in field number 1 (a variable placeholder defined with ^FN when the format was originally saved). The outer ^XA/^XZ pair is still required.

How ^XA and ^XZ interact with Label Toolkit

When you export a label from Label Toolkit's browser-based designer as ZPL, the engine automatically inserts ^XA as the first line and ^XZ as the last. You never need to type them manually. The export also inserts the correct ^PW (Print Width) and ^LL (Label Length) commands before any field commands, ensuring the printer knows the media dimensions before it tries to place dots.

If you are editing raw ZPL in the built-in code editor or sending ZPL via the Label Toolkit ZPL API, the parser validates that every submitted block starts with ^XA and ends with ^XZ and returns a clear error message if either is missing.

For a guided tour of the full set of ZPL commands and how they interact with each other, the ZPL commands hub for Zebra label printing is the best place to continue.

Screenshot of a browser-based ZPL code editor showing XA at line 1 and XZ at the final line, with syntax highlighting

Common errors caused by missing or malformed ^XA / ^XZ

SymptomLikely causeFix
Printer receives data but feeds blank labels^XZ missing; format never commitsAdd ^XZ as the last line of the format
First label blank, subsequent labels print correctlyLeading junk bytes before ^XAStrip BOM or extra characters from the stream head
Only part of the label printsSecond ^XA encountered before ^XZRemove nested ^XA or close the first format
Printer ignores all data silentlyLowercase ^xa not recognized on that firmwareUse uppercase ^XA and ^XZ
Label prints once when five copies expectedFive separate ^XA...^XZ blocks sent but printer queues as oneUse ^PQ5 inside a single format block

ZPL vs. other printer languages: why this delimiter pattern?

Competing printer languages use different conventions. EPL2 (Zebra's older Eltron Programming Language) uses an N command to clear the buffer and P1 to print, with no explicit end marker. CPCL (used on some Zebra mobile printers) uses ! 0 200 200 406 1 as a header and PRINT as the terminator. The ^XA...^XZ pattern in ZPL II is deliberately explicit: the firmware never has to guess where a format ends. This makes ZPL robust over unreliable serial or network connections where partial transmissions are common. The official ZPL II Programming Guide documents this design rationale in the format structure section.

Frequently asked questions

What happens if I forget ^XZ at the end of my ZPL?

The printer holds the format in its buffer indefinitely and prints nothing. On most Zebra models, the buffer is cleared when the printer is power-cycled or when a new ^XA arrives. Always close every format with ^XZ.

Is ^XA the same as ^XZ in reverse, or do they do different things?

They do different things. ^XA allocates the format buffer and starts parsing; ^XZ compiles the buffer, renders the label image, and triggers the print mechanism. They are not symmetric: you can send many commands between them but you cannot swap their order.

Can I send multiple labels in one data stream?

Yes. Concatenate multiple ^XA...^XZ blocks one after the other in the same TCP/IP, USB, or serial stream. The printer processes them in sequence, printing one label per block. This is the standard approach for variable-data label batches.

Do I need ^XA and ^XZ when using the Label Toolkit ZPL API?

The API accepts both raw ZPL (with your own ^XA/^XZ) and structured JSON input that the engine wraps in the correct delimiters for you. If you submit raw ZPL, the validator checks for the delimiters and rejects malformed input with a descriptive error.

What is the caret character and can I change it?

The caret (^) is ZPL's default command prefix. You can change it to a different ASCII character using the ^CT (Change Caret) command, but almost no one does this in practice; every tool, example, and documentation assumes the default ^. Stick with the default unless you have a specific reason, such as a data stream that contains literal caret characters.

Ready to try it yourself? Create a free Label Toolkit account and export your first ZPL label directly from the browser-based designer, no software to install.

Related reading: ZPL Command Reference: ^FO (Field Origin)

#caret XA zpl #caret XZ zpl #zpl commands #zpl reference #zebra printing #label format
OM
Written by Olivia Morgan
View profile →