10 minutes

Creating Interactive, Highly Optimized AMP Emails

Google’s AMP framework – Accelerated Mobile Pages is a powerful tool that can make highly interactive and user-centered emails that load faster than traditional emails. This framework can be a powerful tool for sending dynamic and useful content through AMP emails.

Tip: Try Postcards and create HTML emails in minutes without coding knowledge.

AMP is made up of HTML, CSS, and JS with the primary goal of building user-first experiences. The framework works for websites, ads, and emails. The framework features a variety of standard components such as forms, carousels, sliders, and capabilities to grab content from remote endpoints. The beauty of AMP is that the recipient can interact with the component directly inside the email without leaving it such as filling out a form, booking a reservation, pinning an item to a Pinterest board, browsing products or scheduling a call.

The Basic Structure of AMP Emails

For the email to qualify as AMP, it has to have the minimum code structure below. It’s the base code.

<!doctype html>
<html ⚡4email>
<head>
  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <style amp4email-boilerplate>body{visibility:hidden}</style>
</head>
<body>
  Hello, AMP4EMAIL world.
</body>
</html>

There are three essential elements to note from the above snippet:

  • To identify the email’s code as AMP you must specify ‘⚡4email’ or ‘amp4email’ in the <HTML> tag.
  • The <head> tag must contain the <script> for loading AMP.
  • Last, you must also include AMP’s CSS boilerplate. It hides the AMP content until it’s fully loaded in the email.

Don’t be put off by the fact that there is a script within this code. It’s there to help turn the content dynamic. Email providers conduct intense security checks to make sure that only AMP scripts can run within their clients.

AMP also introduced a variety of new syntax to make their components work. It’s nothing too complicated to get the hang of; but, it’s highly worth it. Let’s go over some elements you can use within your AMP emails below.

AMP Emails Playground

At any point, you’re free to use the AMP Playground to test or play around with the AMp framework.

Online HTML Email Template Builder

With Postcards you can create and edit email templates online without any coding skills! Includes more than 100 components to help you create custom emails templates faster than ever before. Try now for free!

Learn MoreOther Products

Adding Responsive Images

The <image> tag has been rewritten in AMP. The syntax is ‘amp-img’ and it requires that the image specifies the width and height of the image as well as includes a closing tag </amp-img>. AMP also supports gifs and more on that a bit later.

<amp-img src=“https://link/to/img.jpg”
         alt=“photo description”
         width=“100”
         height=“100”>
</amp-img>

One important thing to remember is that image URLs must be HTTPS in order to comply with AMP’s security guidelines.

To make your elements responsive, all you have to do is add the ‘layout=“responsive”’ attribute to your element’s code. AMP comes with predefined media queries that will resize your content for you, which they refer to the AMP layout system. This feature itself is going to make coding emails through AMP a lot more appealing.

<amp-img layout="responsive" src="https://placekitten.com/800/400" alt="Welcome" height="400" width="800"></amp-img>

Using Gif Images

AMP supports email GIFs. They require a specific AMP tag <amp-anim> to enclose the GIF <amp-img> tag. This animation tag has been specifically designed to reduce CPU usage when the gif is off-screen. Similar to the <amp-img>,  <amp-anim> needs to have the width and height defined as well as a closing tag. The <amp-anim> tag also supports the AMP layout system for responsive design.

Additionally, AMP recommends using a placeholder <amp-img> within the <amp-anim> tag for when the gif has yet to load.

<amp-anim width=400 height=300 src=“my-gif.gif” layout=“responsive”>
  <amp-img placeholder width=400 height=300 src=“my-gif-screencap.jpg”>
  </amp-img>
</amp-anim>

Adding an Image Carousel

One of the most basic AMP elements is got to be an image carousel. Imagine a slideshow of images and content within an email. How mind-blowingly amazing is that?!

In order to use one in your email, you’d first have to call the carousel script in your email’s <head>.

<head>
  …
  <script async custom-element=“amp-carousel” src=“https://cdn.ampproject.org/v0/amp-carousel-0.1.js”></script>
</head>

Next, you’d wrap your images in a <amp-carousel> tag as seen below. As you can see, the <amp-carousel> tag have a few attributes, one of which is ‘type.’ The code below features a ‘slides’ type and will render a carousel slideshow.

<amp-carousel id="carousel-with-preview"
              layout=“responsive”
              width=“800”
              height=“400”
              type=“slides”>
        <amp-img layout=“fill” src=“https://placekitten.com/800/400”  alt=“Welcome” height=“400” width=“800”></amp-img>
        <amp-img layout=“fill” src=“https://placekitten.com/800/400”  alt=“Welcome” height=“400” width=“800”></amp-img>
        <amp-img layout=“fill” src=“https://placekitten.com/800/400”  alt=“Welcome” height=“400” width=“800”></amp-img>

</amp-carousel>

Additional Layout Elements

Before we jump into additional information such as styling, let’s talk about a couple more layout elements that are possible thanks to AMP including accordions and sidebars.

Accordions

<amp-accordion> is another amazing interactive layout element from AMP. It allows you to create and simply collapsible and expandable content sections. Each content section within <amp-accordion> must be defined with <section> tags.

Accordions must contain at least one <section> element as a direct child and each <section> must contain exactly two direct children. The first of which must be a heading element such as <h1>.

Same as using a carousel, you must first add an accordion script to the email’s <head>.

<head>
  …
   <script async custom-element="amp-accordion" src="https://cdn.ampproject.org/v0/amp-accordion-0.1.js"></script>
</head>

Below is an example code of an accordion written with the AMP framework:

<amp-accordion class="sample">
  <section expanded>
    <h4>Section 1</h4>
    <p>Bunch of awesome content.</p>
  </section>
  <section>
    <h4>Section 2</h4>
    <div>Bunch of even more awesome content. This time in a <code>&lt;div&gt;</code>.</div>
  </section>
  <section>
    <h4>Section 3</h4>
    <figure>
      <amp-img src="/static/samples/img/clean-1.jpg"
        layout="intrinsic"
        width="400"
        height="710"></amp-img>
      <figcaption>Images work as well.</figcaption>
    </figure>
  </section>
</amp-accordion>

Sidebars

<amp-sidebar> is a great way to display meta content intended for temporary access such as navigation links, menus, or buttons. A sidebar can be opened or closed through button taps while the main email content remains underneath it. You can use optional attributes such as a child toolbar with media queries, <nav toolbar=”(media query)” toolbar-target=”elementID”>, to show content within the sidebar that’s displayed elsewhere in the email as well.

There are a few important things you must know about the sidebar’s behavior:

  • <amp-sidebar> element must be a direct child of the <body> element.
  • True to its name a sidebar can only appear on the left or right side of the content.
  • All valid HTML elements, supported by AMP, can appear in the <amp-sidebar> element including <amp-accordion>, <amp-img>, <amp-live-list> or <amp-social-share>.
  • The default max height of <amp-sidebar> is 100vh with scrolling overflow which can be overridden in CSS. It also has a min-width of 45px, also changeable with CSS.

To use the <amp-sidebar> within your emails’ code, first import the element in the <head>:

<head>
  …
   <script async custom-element="amp-sidebar" src="https://cdn.ampproject.org/v0/amp-sidebar-0.1.js"></script>
</head>

Next, simply enclose your HTML content with the <amp-sidebar> tags.

<amp-sidebar id="sidebar1" side="right">
  <ul>
    <li>Nav item 1</li>
    <li><a href="#idTwo" on="tap:idTwo.scrollTo">Nav item 2</a></li>
    <li>Nav item 3</li>
    <li><a href="#idFour" on="tap:idFour.scrollTo">Nav item 4</a></li>
    <li>Nav item 5</li>
    <li>Nav item 6</li>
  </ul>
</amp-sidebar>

Note that the <amp-sidebar> element comes with a “side” attribute to specify whether it shows up on the ‘left’ or the ‘right’ of the content.

CSS Styling

Another amazing thing about AMP is its capability for CSS customization in the <head> of the email instead of inline. Check out some sample code below:

<head>
  …
  <style amp-custom>
    h1 {
      font-family: arial;
      margin: 10px;
    }
    .center {
      text-align: center;
    }
    .carousel-preview {
      margin-top: 10px;
    }
  </style>
</head>

CSS Attributes and Pseudo-Classes

Additionally, AMP allows for many previously unusable in email design class attributes or pseudo-classes – especially those previously not customizable through in-line styling such as ‘hover.’ It makes sense; many of these are also required to customize and style the new interactive and dynamic features.

Here is a shortlist of a handful of the newly supported class attributes and pseudo-classes in AMP:

  • align-items
  • box-shadow
  • z-index
  • active
  • checked
  • disabled
  • focus
  • hover
  • nth-child
  • required

And, here is the full list: Allowed AMP Components

Dynamic Content

Another powerful feature of the AMP framework is its ability to serve dynamic content on user interactions. For example, showing a product’s availability based on product selection within the email’s content.

<amp-bind> allows you to add custom interactive content and interactions that go well beyond AMP’s pre-built components. You can bind all sorts of things such as text or other materials as well as CSS classes or other element attributes. Check out AMP’s documentation for a full list of examples.

Pairing <amp-bind> with <amp-state> elements with a JSON end-point is how you can leverage the AMP framework to get up-to-date content and data within your AMP emails. The data will be updated only after a user interacts with the content because <amp-bind> statements are not derived on page load.

Although this limits the possible use cases a bit, it does open up a whole new world of possibilities for interactive and dynamic emails that so far have been extremely limiting to static content only.

How to Get Dynamic Content

As you’ve seen a bunch of time already, first you’ve got to setup the <amp-bind> script in the email’s <head>.

<head>
  …
   <script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-0.1.js"></script>
</head>

Second, make sure to add the <amp-state> tag within your content with a source linked to your JSON file.

To update the content in the below example, we’re using the AMP.setState() action to update the different content states on tap (or click) events.

Finally, you need to define where the content is being displayed from your JSON file within the AMP email content.

AMP email content

In the below example, a user selects a product by clicking on the image after which it’s availability is shown. AMP has a live example of this interaction. You can also copy and paste this code into the AMP Playground to have a go at it yourself.

<div>
  <amp-state id="products"
    src="/static/samples/json/products.json"></amp-state>

  <amp-img on="tap:AMP.setState({ productId: 0})"
    src="/static/samples/img/red_apple_1_60x40.jpg"
    width="60"
    height="40"
    role="button"
    tabindex="0">
  </amp-img>
  <amp-img on="tap:AMP.setState({ productId: 1})"
    src="/static/samples/img/green_apple_1_60x40.jpg"
    width="60"
    height="40"
    role="button"
    tabindex="0">
  </amp-img>
  <amp-img on="tap:AMP.setState({ productId: 2})"
    src="/static/samples/img/product1_alt1_60x40.jpg"
    width="60"
    height="40"
    role="button"
    tabindex="0">
  </amp-img>
  <div ="products[productId] + ' available'">Please select a product</div>
</div>

Registering to Send AMP Emails

In order to send AMP emails, you must register with Google. It’s not a complicated process, per se, but they do have many requirements; these are in place to ensure that you meet security, privacy, and general guidelines for quality emails.

Already, Google has partnered with Booking.com, Despegar, Doodle, Ecwid, and Freshworks. However, those are mostly promotional. Anyone can sign up to start using the framework, providing they follow the guidelines accurately.

Take a look at the full list of official requirements set by AMP. Some of these requirements include:

  • A real, production-ready email example
  • No bugs
  • The email must be authenticated through SPF, DKIM, and DMARC
  • The email must follow AMP best practices and Gmail’s Bulk Sender guidelines
  • The account holder must have low spam complaints and a good history of sending high-value emails associated from your domain

Once you’re ready to submit, you can fill out their application form here: Sender Registration – AMP for Email in Gmail.

Below we’re going to cover a few different steps from the above requirement list that will help get yourself whitelisted and accepted for AMP.

1. Select a Proper ESP

If your email service provider doesn’t support AMP, you’re not going to be able to send them. Currently, there are five ESPs that support AMP emails. Unfortunately, if your current ESP isn’t one of those five you’re going to have to switch or wait until your current ESP provides the service.

As of this writing, the four ESPs that support AMP are:

  1. SendGrid
  2. Amason’s SES and Pinpoint
  3. SparkPost
  4. eSputnik
  5. Mailgun

2. Create a Demo Email

One of the most critical aspects of the AMP registration requirements must be the sample email. This makes absolute sense considering this is a new tool that can be abused easily. Taking the time to create a genuine email is not something many spammers are going to follow through on, partly because it takes time and partly because they don’t have legitimate content.

AMP Emails Example

The AMP framework does take a little bit of time to get the hang of. However, you can easily create your sample email in AMP Playground, and quickly, too. My advice is to decide on and gather the content first, then design the email, and finally have it developed. Once finished, copy the email’s source code to submit with your application.

Additionally, note that the “real, production-quality example” email must be sent directly, and not be forwarded, from your production servers.

3. Authenticate Your Email’s SPF and DKIM

AMP is capable of obtaining confidential information from the receiver, which is a potential security issue. For example, when a user fills out a contact form, you’ve sent them.  By authenticating your SPF – Sender Policy Framework – and DKIM – DomainKeys Identified Mail – you’re further telling Google that you’re not a spammer or phisher.

What is SPF?

SPF is a list of IP addresses emails can be sent from. It helps validate who send the email and prevents an authorized IP to email your subscribers using AMP. An email from a non-listed IP address will be automatically directed into the spam folder.

To obtain your own verified SPF list, follow the directions outlined by AMP.

What is DKIM?

DKIM is another spam prevention method which allows the email recipient’s email provider to check if the email is authentic. What happens is that DKIM verifies whether email attachments have been tampered with, but also it encodes the email from the sender and then decodes it on the recipient’s end — determining if an email is authentic and not spam is easy because spam emails do not encode in the first place.

While registering with AMP, make sure to register the same email address and domain you’ve been using to email your subscribers.

Again, follow the directions outlined by AMP to authenticate your DKIM.

4. Matching XHRs

XHRs –  XMLHttpRequests – must be authenticated to be approved. Whichever email you choose to register for AMP, the XHR requests need to match the domain used in the email in order for it to be authentic and approved by AMP. That’s because the XHRs are responsible for pulling in the dynamic content into the AMP emails.

5. Follow Google’s Gmail Bulk Sender Guidelines

The last thing you should be aware of when it comes to your AMP registration is the Bulk Sender Guidelines. Gmail defines these to help prevent spam for Gmail account holders. These guidelines are pretty standard. However, you must be compliant with them in order to get approved and whitelisted for AMP.

Which Email Clients Support AMP?

As of this writing, four email clients support AMP emails:

  • Gmail
  • Yahoo! Mail
  • Outlook
  • mail.ru

However, efforts are being made to adopt AMP support in other major clients.

Enable AMP emails in Gmail

In order for you to receive dynamic emails, you must enable this in Gmail’s settings first. Unfortunately, it’s turned off by default. Fortunately, it’s easy to change this setting.

Related: Try free the Postcards email builder – Create beautiful emails online.

Log into your Gmail account and go to your settings. Under the General Tab, scroll down to Dynamic emails and check the ‘Enable dynamic email’ option. Then save.

Enable dynamic email in gmail

Here you can also find the Developer Setting, which allows you to display dynamic emails during development. You can only add a single email at a time. It’s great for testing email campaigns to make sure you’ve set them up correctly or to enable while your learning, playing around and testing your initial AMP emails.

Amp Emails Developer Setting

Conclusion

The AMP framework is the first step in revolutionizing how we go about designing and creating emails. It’s a wonderful framework that gives us a whole new world of creative possibilities for interactive, optimized, and attention-grabbing emails. We’re curious what you think about the framework and its capabilities!

Do you plan on registering for AMP to start using this framework? Let us know in the comments.

Paula Borowska

Paula is a freelance web designer who documents her travels with photos and words. She works with small companies that want to re-brand their online businesses to create products that change lives of their customers all in the hopes of gaining more customers and retaining their current ones longer.

Posts by Paula Borowska
Cookie Icon
We use cookies to ensure that we give you the best experience on our website.
  • I disagree
  • I agree