How to Add a Gift Message Field to Shopify Cart Without an App

2026-12-04 · upselling

Gift messaging is one of those features shoppers expect and merchants keep putting off, because the app store makes it look like a $10–$30/month problem. It isn't. Shopify's cart object accepts line item properties and cart attributes natively, and you can wire up a gift message field with a handful of Liquid edits and about 20 lines of JavaScript. Here's the full build, from backup to test order.

Why Use Cart Attributes Instead of a Gift Message App

Most gift message apps charge a monthly fee and add a script to every page of your store. In exchange you get a text box, a character limit, and a line in the order. You can build that yourself in an afternoon, and you keep three things an app takes from you:

The mechanism is Shopify's cart.attributes object. Anything you submit with a name beginning attributes[ is stored on the cart, carried through checkout, and printed on the order. No app, no metafields, no subscription.

One caveat up front: cart attributes work on the cart page. If your theme has a slide-out cart drawer, this guide covers the cart page form; the drawer needs its own edit using the same field name.

Before You Start: Theme Backup and Where the Code Goes

Do this in a duplicate theme, not your live one.

  1. In Shopify admin, go to Online Store → Themes.
  2. On your live theme, click ⋯ → Duplicate. Name it something like Gift message – test.
  3. On the duplicate, click ⋯ → Edit code.

You'll be editing two files and possibly a third:

File What you're adding
sections/main-cart.liquid (or cart.liquid on older themes) The textarea inside the cart form
assets/base.css or theme.css Styling for the field
sections/main-cart.liquid again A display of the saved message above the form
templates/customers/order.liquid (optional) Message on the customer account order page

The cart section filename varies by theme. Dawn uses main-cart.liquid. Older themes use cart-template.liquid. Open the file and look for a <form> tag with action="/cart" and method="post" — that's the form you need.

Step 1: Add the Gift Message Field to Your Cart Form

Find the closing </form> of the cart form in your cart section. Immediately before it, paste:

<div class="gift-message">
  <label for="gift-message-field">Add a gift message (optional)</label>
  <textarea
    id="gift-message-field"
    name="attributes[Gift message]"
    maxlength="200"
    placeholder="We'll include this on a printed card."
    aria-describedby="gift-message-help"
  >{{ cart.attributes['Gift message'] }}</textarea>
  <p id="gift-message-help" class="gift-message__help">
    <span id="gift-message-count">0</span>/200 characters
  </p>
</div>

Three details matter here:

Now add the character counter. Put this in the same section, just before the {% schema %} tag or at the bottom of the file inside a <script> tag:

<script>
  (function () {
    var field = document.getElementById('gift-message-field');
    var count = document.getElementById('gift-message-count');
    if (!field || !count) return;
    var update = function () { count.textContent = field.value.length; };
    field.addEventListener('input', update);
    update();
  })();
</script>

That's the whole form. The cart form posts to /cart with method="post", and Shopify saves any attributes[...] field automatically — no AJAX or fetch call needed.

If your theme uses Shopify's Cart API for quantity updates, the message is preserved because it's stored server-side on the cart, not in the DOM.

Step 2: Style the Field So It Matches Your Theme

An unstyled textarea looks broken next to a polished cart. Add this to your theme's CSS file, then adjust the color variables to match your theme — Dawn, for example, exposes --color-foreground and --color-border; other themes may use different names, so check the top of your CSS file.

.gift-message {
  margin: 1.5rem 0;
  padding: 1rem;
  border: 1px solid rgba(var(--color-foreground), 0.15);
  border-radius: 8px;
}

.gift-message label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.gift-message textarea {
  width: 100%;
  min-height: 90px;
  padding: 0.75rem;
  border: 1px solid rgba(var(--color-foreground), 0.25);
  border-radius: 6px;
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
}

.gift-message__help {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  text-align: right;
  opacity: 0.7;
}

Two practical notes. Use font-family: inherit on the textarea — browsers default form fields to a system font that will look out of place. And keep resize: vertical so shoppers can't drag the box wider than your cart column and break the layout on desktop.

Step 3: Show the Gift Message in Cart, Checkout, and Order Emails

The field saves the message, but shoppers need to see it confirmed. Add this block at the top of your cart section, inside the cart form or just above it:

{% if cart.attributes['Gift message'] != blank %}
  <div class="gift-message-summary">
    <strong>Gift message:</strong>
    <p>{{ cart.attributes['Gift message'] | escape }}</p>
  </div>
{% endif %}

The escape filter matters — it prevents a shopper from injecting HTML into your cart page.

Checkout: cart attributes appear automatically in the order's Additional details panel in the Shopify admin. In checkout itself, Shopify shows them under the order summary in most themes. You can't restyle that without Shopify Plus checkout extensibility, so don't try.

Order emails: open Settings → Notifications → Order confirmation (and New order for your own notification). Find the line items loop and add, after it:

{% if attributes['Gift message'] %}
  <p><strong>Gift message:</strong> {{ attributes['Gift message'] }}</p>
{% endif %}

In notification templates the variable is attributes, not order.attributes — that trips people up constantly.

Packing slips: same edit in Settings → Notifications → Packing slip, so whoever packs the box sees the message without opening the admin.

Step 4: Test the Whole Flow Before You Launch

Run a real order on your duplicated theme with a test payment (Shopify's Bogus Gateway is fine, or use a 100%-off discount code and a real card).

Check each of these:

Only after all seven pass should you publish the duplicate theme.

Common Problems and How to Fix Them

Message disappears after "Update cart." Your textarea is outside the <form>. Check that it sits before </form> in the cart section.

Field doesn't appear at all. You edited the wrong file, or your theme renders cart through a snippet. Search the theme for action="/cart" using the code editor's search to find the real form.

Message shows in the admin but not in the email. You used order.attributes in the notification template. Use attributes.

Field appears in the cart drawer but won't save. Drawer carts often post via the Cart API, which ignores form fields. Either remove the field from the drawer or add an attributes object to the fetch call.

Character count shows 0 after reload. The counter script runs before the pre-filled value is set, or the IDs don't match. Confirm the id attributes on the textarea and counter span.

Multiple messages stacking on the order. Someone added the field to both the cart page and the drawer with different attribute names. Use attributes[Gift message] in exactly one place.

Conclusion

A gift message field is a form input and a Liquid variable — nothing more. Build it on a duplicated theme, test a real order end to end, and you've replaced a monthly subscription with code you control. If you later need gift wrapping SKUs or per-product gift options, that's when a paid app starts earning its fee.

FAQ

Does the gift message field work with Shopify's new checkout? Yes. Cart attributes are carried into checkout and displayed in the order summary on all plans. Restyling that display requires Shopify Plus, but the data itself works everywhere.

Will the message survive if a customer abandons checkout and comes back? Yes, as long as the cart hasn't been cleared. Attributes are stored on the cart server-side, so returning shoppers see their message pre-filled.

Can I add a gift message field to product pages instead? Yes — use properties[Gift message] on the product form instead of attributes[...]. It saves per line item, which is better if a customer might gift only some items in a multi-item order.