---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/email/api/personalization#article
headline: Personalization
description: Learn how to personalize emails using the Twilio Email API and Liquid templating.
url: https://www.twilio.com/docs/email/api/personalization
inLanguage: en
dateModified: 2026-08-20T18:09:16.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# Personalization

The Twilio Email API uses [LiquidJS](https://liquidjs.com) templating to personalize email content for each recipient. Use it for simple variable replacement or advanced control flow such as `if` and `unless`.

## Personalize emails inline

To personalize the `subject`, `html`, and `text` fields for each recipient, use the [LiquidJS](https://liquidjs.com) templating language. Enclose each variable name in double curly braces (`{{ }}`). For every variable in your content, include a matching key in the `variables` object for each recipient in the `to` array.

To get email messages to render properly, provide a default value for every variable. When a recipient's variables don't contain the corresponding data, the email message displays a generic value.

```bash {title="Personalize an email with inline variables"}
curl -X POST 'https://comms.twilio.com/v1/Emails' \
-H 'Content-Type: application/json' \
-d '{
    "from": {
        "address": "support@example.com",
        "name": "Support Team"
    },
    "to": [
        {
            "address": "jane.doe@example.com",
            "variables": {
                "firstName": "Jane",
                "lastName": "Doe"
            }
        },
        {
            "address": "john.doe@example.com",
            "variables": {
                "firstName": "John",
                "lastName": "Doe"
            }
        }
    ],
    "content": {
        "subject": "Hello {{ firstName | default: '\''there'\'' }}",
        "html": "<html><body><p>Hey {{ firstName | default: '\''there'\'' }} {{ lastName }}, your order is ready.</p></body></html>",
        "text": "Hey {{ firstName | default: '\''there'\'' }} {{ lastName }}, your order is ready."
    }
}' \
-u $TWILIO_API_KEY:$TWILIO_API_SECRET
```

## Advanced templating

In addition to simple variable replacement, you can use control flow structures like `if` and `unless`. This lets you render parts of an email for only specific recipients.

```bash {title="Render content conditionally with Liquid control flow"}
curl -X POST 'https://comms.twilio.com/v1/Emails' \
-H 'Content-Type: application/json' \
-d '{
    "from": {
        "address": "marketing@example.com",
        "name": "Marketing Team"
    },
    "to": [
        {
            "address": "jane.doe@example.com",
            "variables": {
                "firstName": "Jane",
                "plan": "premium"
            }
        },
        {
            "address": "john.doe@example.com",
            "variables": {
                "firstName": "John",
                "plan": "free"
            }
        }
    ],
    "content": {
        "subject": "Your monthly update, {{ firstName | default: '\''there'\'' }}",
        "html": "<html><body><p>Hello {{ firstName | default: '\''there'\'' }}!</p>{% if plan == '\''premium'\'' %}<p>Thank you for being a premium member. Here are your exclusive benefits.</p>{% endif %}</body></html>",
        "text": "Hello {{ firstName | default: '\''there'\'' }}! {% if plan == '\''premium'\'' %}Thank you for being a premium member. Here are your exclusive benefits.{% endif %}"
    }
}' \
-u $TWILIO_API_KEY:$TWILIO_API_SECRET
```

## Next steps

* To learn about tracking the status of your email sends, see [Operations and Email Tracking](/docs/email/api/operations-and-email-tracking).
* To view delivery activity in the Console, see [Email logs](/docs/email/logs).
