Skip to content

4 × 6 in

Shipping labels

Shipping label 4 × 6 in

A carrier-neutral 4 × 6 inch shipping label in high-contrast black and white for thermal printers. It has a large ship-to address, service level, weight, package count, a bold routing code, Code 128 barcodes for the tracking number and postal code, and a QR code with the shipment summary.

Custom sizeLocale en-USHTML + Jinja

Opens Dynamic Document API with this template preloaded in a free workspace.

Template language features

  • Loops
  • Conditionals
  • Macros
  • Filters
  • Barcode
  • QR code
  • Date formatting
  • Number formatting

Filters such as format_currency and qrcode are described in the template language reference.

Variables

Derived from the sample data: 3 top-level fields, 37 paths in total. Send the same shape as data.

PathTypeExample
shipmentobject
shipment.tracking_numberstring"ND48273019665502"
shipment.service_levelstring"Ground"
shipment.service_codestring"GND"
shipment.transitstring"3–5 business days"
shipment.ship_datedate"2026-09-17"
shipment.weight_lbnumber12.4
shipment.dimensions_inobject
shipment.dimensions_in.lengthnumber14
shipment.dimensions_in.widthnumber10
shipment.dimensions_in.heightnumber8
shipment.package_numbernumber2
shipment.package_countnumber3
shipment.routing_codestring"AZ 860 9-07"
shipment.hubstring"PHX-3"
shipment.referencestring"SO-58213"
shipment.po_numberstring"7730-114"
shipment.billingstring"Prepaid"
shipment.signature_requiredbooleantrue
shipment.localestring"en-US"
senderobject
sender.namestring"Driftwood Supply Co."
sender.attentionstring"Shipping Dept."
sender.address_linesarray<string> · 1"480 Harbor Industrial Way, Unit C"
sender.citystring"Portland"
sender.statestring"OR"
sender.postal_codestring"97217"
sender.phonestring"+1 202-555-0119"
recipientobject
recipient.namestring"Rosalind Achebe-Morrow"
recipient.companystring"Tamarack Ceramics Studio"
recipient.address_linesarray<string> · 2"2215 W Juniper Ave"
recipient.citystring"Flagstaff"
recipient.statestring"AZ"
recipient.postal_codestring"86001"
recipient.countrystring"United States"
recipient.phonestring"+1 202-555-0182"

Sample data

Fictional records used for previews. Replace them with your own data when you call the API.

data.json
{
  "shipment": {
    "tracking_number": "ND48273019665502",
    "service_level": "Ground",
    "service_code": "GND",
    "transit": "3–5 business days",
    "ship_date": "2026-09-17",
    "weight_lb": 12.4,
    "dimensions_in": { "length": 14, "width": 10, "height": 8 },
    "package_number": 2,
    "package_count": 3,
    "routing_code": "AZ 860 9-07",
    "hub": "PHX-3",
    "reference": "SO-58213",
    "po_number": "7730-114",
    "billing": "Prepaid",
    "signature_required": true,
    "locale": "en-US"
  },
  "sender": {
    "name": "Driftwood Supply Co.",
    "attention": "Shipping Dept.",
    "address_lines": ["480 Harbor Industrial Way, Unit C"],
    "city": "Portland",
    "state": "OR",
    "postal_code": "97217",
    "phone": "+1 202-555-0119"
  },
  "recipient": {
    "name": "Rosalind Achebe-Morrow",
    "company": "Tamarack Ceramics Studio",
    "address_lines": ["2215 W Juniper Ave", "Suite 110"],
    "city": "Flagstaff",
    "state": "AZ",
    "postal_code": "86001",
    "country": "United States",
    "phone": "+1 202-555-0182"
  }
}

Source

The body markup with Jinja, the stylesheet placed in <head>.

{#- Carrier-neutral 4 × 6 inch thermal shipping label, black on white. The tracking number is printed
    in groups of four and as a Code 128 barcode, the ship-to postal code gets its own routing barcode,
    and the QR code carries a compact summary of the shipment. -#}
{%- set locale = shipment.locale | default("en-US") -%}
{%- set tracking = shipment.tracking_number -%}
{%- set qr_payload = "ND1|" ~ tracking ~ "|" ~ recipient.postal_code ~ "|" ~ shipment.package_number ~ "/" ~ shipment.package_count ~ "|" ~ (shipment.weight_lb | format_number(locale, 1)) ~ "LB|" ~ shipment.service_code -%}

{%- macro grouped(value, size=4) -%}
  {%- for start in range(0, value | length, size) -%}{{ value[start:start + size] }}{% if not loop.last %} {% endif %}{%- endfor -%}
{%- endmacro -%}

<div class="label">
  <section class="top">
    <div class="from">
      <p class="tiny-label">From</p>
      <p class="from-name">{{ sender.name }}</p>
      {% if sender.attention %}<p>{{ sender.attention }}</p>{% endif %}
      {% for line in sender.address_lines %}<p>{{ line }}</p>{% endfor %}
      <p>{{ sender.city | upper }} {{ sender.state }} {{ sender.postal_code }}</p>
      {% if sender.phone %}<p>{{ sender.phone }}</p>{% endif %}
    </div>
    <div class="service">
      <div class="service-code">{{ shipment.service_code }}</div>
      <p class="service-transit">{{ shipment.transit }}</p>
    </div>
  </section>

  <section class="facts">
    <div><span class="tiny-label">Ship date</span><strong>{{ shipment.ship_date | format_date("short", locale) }}</strong></div>
    <div><span class="tiny-label">Weight</span><strong>{{ shipment.weight_lb | format_number(locale, 1) }} LB</strong></div>
    <div><span class="tiny-label">Dims (in)</span><strong>{{ shipment.dimensions_in.length }}×{{ shipment.dimensions_in.width }}×{{ shipment.dimensions_in.height }}</strong></div>
    <div class="pkg"><span class="tiny-label">Package</span><strong>{{ shipment.package_number }} of {{ shipment.package_count }}</strong></div>
  </section>

  <section class="ship-to">
    <p class="ship-to-label">Ship<br>to</p>
    <div class="ship-to-address">
      <p class="to-name">{{ recipient.name | upper }}</p>
      {% if recipient.company %}<p class="to-line">{{ recipient.company | upper }}</p>{% endif %}
      {% for line in recipient.address_lines %}<p class="to-line">{{ line | upper }}</p>{% endfor %}
      <p class="to-city">{{ recipient.city | upper }} {{ recipient.state }} {{ recipient.postal_code }}</p>
      {% if recipient.phone %}<p class="to-phone">{{ recipient.phone }}</p>{% endif %}
    </div>
  </section>

  <section class="routing">
    <div class="routing-main">
      <p class="routing-code">{{ shipment.routing_code }}</p>
      <div class="postal-barcode">{{ ("420" ~ recipient.postal_code) | barcode("code128", alt="Routing barcode for postal code " ~ recipient.postal_code) }}</div>
      <p class="postal-text">(420) {{ recipient.postal_code }}{% if shipment.hub %} · Hub {{ shipment.hub }}{% endif %}</p>
    </div>
    <div class="routing-qr">{{ qr_payload | qrcode(size=160, margin=0, ecc="M", alt="QR code with the shipment summary") }}</div>
  </section>

  <section class="service-bar">
    <span class="service-name">{{ shipment.service_level | upper }}</span>
    {% if shipment.signature_required %}<span class="flag">Signature required</span>{% endif %}
  </section>

  <section class="tracking">
    <p class="tracking-label">Tracking <strong>{{ grouped(tracking) }}</strong></p>
    <div class="tracking-barcode">{{ tracking | barcode("code128", alt="Tracking barcode " ~ tracking) }}</div>
  </section>

  <section class="refs">
    <div><span class="tiny-label">Ref</span>{{ shipment.reference }}</div>
    <div><span class="tiny-label">PO</span>{{ shipment.po_number }}</div>
    <div><span class="tiny-label">Bill</span>{{ shipment.billing | upper }}</div>
  </section>
</div>

Render it with the API

After adding the template to your workspace, render it by ID and pass your data. Arrays are shortened here.

curl -X POST https://api-eu.dynamicdocumentapi.com/v1/renders \
  -H "Authorization: Bearer $DYNAMIC_DOCUMENT_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
  "input": {
    "type": "template",
    "template_id": "tpl_01J9ZK3M7Q8V5W2X4Y6Z8A0B1C"
  },
  "data": {
    "shipment": {
      "tracking_number": "ND48273019665502",
      "service_level": "Ground",
      "service_code": "GND",
      "transit": "3–5 business days",
      "ship_date": "2026-09-17",
      "weight_lb": 12.4,
      "dimensions_in": {
        "length": 14,
        "width": 10,
        "height": 8
      },
      "package_number": 2,
      "package_count": 3,
      "routing_code": "AZ 860 9-07",
      "hub": "PHX-3",
      "reference": "SO-58213",
      "po_number": "7730-114",
      "billing": "Prepaid",
      "signature_required": true,
      "locale": "en-US"
    },
    "sender": {
      "name": "Driftwood Supply Co.",
      "attention": "Shipping Dept.",
      "address_lines": [
        "480 Harbor Industrial Way, Unit C"
      ],
      "city": "Portland",
      "state": "OR",
      "postal_code": "97217",
      "phone": "+1 202-555-0119"
    },
    "recipient": {
      "name": "Rosalind Achebe-Morrow",
      "company": "Tamarack Ceramics Studio",
      "address_lines": [
        "2215 W Juniper Ave",
        "Suite 110"
      ],
      "city": "Flagstaff",
      "state": "AZ",
      "postal_code": "86001",
      "country": "United States",
      "phone": "+1 202-555-0182"
    }
  },
  "output": {
    "format": "pdf",
    "filename": "shipping-label-4x6.pdf"
  }
}'