ZPL guide 7 of 9
Boxes, lines, circles and ellipses
Draw rectangles, horizontal and vertical lines, circles, ellipses and diagonals in ZPL, round corners, fill shapes, and print white text on black with ^FR and ^LR.
Boxes and lines are the same command
Question How do I draw a rectangle, a horizontal line or a vertical line?
^GB draws both boxes and lines. Its values are the width, the height, the border thickness, the color and the corner rounding, in that order. Everything is measured in dots; to work in millimeters, multiply by your printer's dots per millimeter.p. 210
A line is simply a box that is very thin in one direction. A line 300 dots long and 3 dots thick is ^GB300,3,3, and a vertical one is ^GB3,160,3.
The width and height range from the value of the thickness up to 32000, so keep both at least as large as the thickness. The guide's own exercise draws a line with a height of 1 and a thickness of 4, and its entry examples pass a width or height of 0 for lines; all of these fall below that documented minimum, so do not copy them.pp. 53, 210, 211
TipA practical way to build a panel: place the box with ^FO, then place each text field a fixed margin inside it by adding that margin to the box's x and y. Keeping all sizes in dots from one origin makes the arithmetic easy to check.
Like any field, a box is placed by ^FO and closed by ^FS. Its position is the upper-left corner, and you can place text on, in or beside it with other fields.pp. 201, 204
^XA ^FO30,30^GB360,160,4^FS ^FO30,100^GB360,3,3^FS ^FO200,30^GB3,160,3^FS ^XZ
A 360 by 160 dot box with a 4-dot border, a horizontal rule across it at 100 dots down and a vertical rule at 200 dots across.
Thickness, color, corners and solid fills
Question How do I choose border thickness, color and rounded corners, and fill a shape?
Thickness runs from 1 to 32000 dots and defaults to 1. The color is B for black or W for white, and defaults to black.p. 210
Since the only colors are black and white, a white shape only makes sense over something that is already black, for example a white rule cutting across a solid bar.
Corner rounding is an index from 0 (none, the default) to 8 (heaviest). The radius is the index divided by 8, multiplied by half the shorter side. So an index of 4 on a box 100 dots high gives a radius of 25 dots.p. 210
To fill a box, the guide's own examples set the thickness equal to the box's shorter side. If you leave out the width and height, you get a solid square whose side equals the thickness.pp. 51, 210
^XA ^FO30,30^GB200,100,3,B,4^FS ^FO260,30^GB100,100,100^FS ^XZ
The first box is outlined with rounded corners (index 4). The second is solid, because its thickness equals its width and height.
Circles, ellipses and diagonal lines
Question How do I draw a circle, an ellipse or a diagonal line?
^GC draws a circle from a diameter, a border thickness and a color. The diameter runs from 3 to 4095 dots. The border grows inward, so the diameter you set is the outside size.p. 212
^GE draws an ellipse from a width, a height, a thickness and a color, with width and height from 3 to 4095 dots.p. 214
Circles and ellipses stop at 4095 dots: a larger circle diameter or ellipse width is replaced with 4095. Boxes and diagonals go to 32000.pp. 210, 212 to 214
The guide lists the thickness for both as 2 to 4095 but the default as 1. Since a default outside the stated range is hard to trust, set the thickness explicitly on circles and ellipses.pp. 212, 214
^GD draws a diagonal across a box of the width and height you give. Its fifth value chooses the lean: right-leaning is the default, and a left-leaning option exists. Width and height each run from 3 to 32000. The guide suggests combining it with other graphic commands to build more complex figures.p. 213
^XA ^FO30,30^GC100,5^FS ^FO160,30^GE160,100,5^FS ^FO360,30^GD100,100,5^FS ^XZ
A circle 100 dots across, an ellipse 160 by 100, and a right-leaning diagonal in a 100 by 100 box, each with a 5-dot line.
White on black, and black on white
Question How do I print white text on a black box?
^FR makes one field print as the opposite of what is behind it, so black over white becomes white over black and the reverse. In the guide's own example, a ^GB command creates the black areas, and the reversed text appears white over them.pp. 51, 203, 1752
Warning^FR applies to only one field and must be repeated on each field that needs it.p. 203
^LR applies the ^FR effect to the fields of a format. It stays on until you send ^LRN or the printer is turned off. The guide describes it as covering all current and subsequent fields but also says only fields after it are affected, so send ^LR before the fields it should reverse.p. 295
The guide's reverse-print examples define the black shape first and the reversed field after it. This page does the same; it does not give a general rule about ordering.pp. 51, 203
A reversed field takes the opposite color of whatever is under it, and the color parameter of these commands is only black or white, so the guide's examples put reversed text over black areas drawn with ^GB.pp. 51, 203, 210
^XA ^FO30,30^GB300,80,80^FS ^FO45,45^A0N,50,50^FR^FDSHIP TO^FS ^XZ
A solid black bar 300 by 80 dots, then a text field with ^FR placed on top of it, so the text takes the opposite color of the bar under it.
The same label with BarcoderX
Question How does BarcoderX handle shapes?
BarcoderX is pre-launch and its API is not final. It is designed to let you describe the label once in .NET and emit ZPL or EPL. The published samples on the Developers page do not show shape calls yet, so there is no code here.
Questions
How do I draw a line in ZPL?
Use ^GB with a width and height where one is as small as the thickness, for example ^GB300,3,3 for a horizontal line.p. 210
What is the difference between ^FR and ^LR?
^FR reverses one field. ^LR reverses every field that follows until turned off with ^LRN.pp. 203, 295
Can I draw a filled box?
Yes. Set the border thickness equal to the box's shorter side, as the guide's examples do, or leave out width and height for a solid square of that thickness.pp. 51, 210
Commands in this guide
- ^GBGraphic BoxDraws a box, or a line, with chosen width, height, border thickness, color and corner rounding.
- ^GCGraphic CircleDraws a circle from a diameter, an outline thickness and a color.
- ^GDGraphic Diagonal LineDraws a straight diagonal line inside a box of given width and height, leaning right or left.
- ^GEGraphic EllipseDraws an ellipse from a width, a height, an outline thickness and a color.
- ^FRField Reverse PrintMakes one field print as the reverse of its background: white over black or black over white.
- ^LRLabel Reverse PrintTurns reverse printing on or off for the fields that follow it, so that fields appear as the reverse of their background without a ^FR in each one.
- ^FOField OriginSets where the next field starts: the position of the field's upper-left corner, counted in dots from the label home position.
- ^FSField SeparatorMarks the end of a field definition, so the commands that follow start a new field.
- ^FDField DataDefines the data string of a field: the text or barcode data that the field carries.
- ^AScalable/Bitmapped FontChooses the font, orientation, character height and width for the text field that follows. The choice applies to that one field only.
- ^XAStart FormatOpens a label format. A valid ZPL II format starts with ^XA and ends with ^XZ.
- ^XZEnd FormatCloses a label format. When the printer receives it, a label prints.
Related guides
Text and fonts in ZPL Printing images and logos Coordinates, dots and print density What is ZPL? The anatomy of a labelBarcoderX is a .NET SDK for thermal labels and barcodes. See how it prints and exports labels.
Source Zebra, ZPL II, ZBI 2, Set-Get-Do, Mirror, WML Programming Guide, P1134473-11EN Rev A, 2026/07/05, pages 51, 53, 60, 201, 203, 204, 210 to 214, 295, 1752.
Written by BarcoderX in its own words. Checked against the guide on 2026-11-14.
ZPL and ZPL II are trademarks of Zebra Technologies Corporation. This reference is written by BarcoderX in its own words from Zebra's published programming guide. BarcoderX is an independent product and is not affiliated with, endorsed by or sponsored by Zebra Technologies.