How to create interactive product images with AMP for Email

Up your email coding skills with this stage-by-step AMP for Email tutorial. Create your have e mail that allows readers alter the colors of a product or service picture.

In this this tutorial you will find out how to build an interactive e-commerce email concept. We’ll display a merchandise with quite a few coloration possibilities. The reader will be equipped to push just about every coloration and dynamically update the solution image. Here’s what it appears to be like (see the full code case in point):

An example of an interactive ecommerce AMP element in an email.
As found in Yahoo Mail inbox

Whilst it is a comparatively basic instance, you will come to be common with a number of important AMP for E mail parts this kind of as:

  • amp-img an AMP substitution for the html5 img tag.
  • amp-selector a regulate for deciding on one or much more selections
  • amp-bind responds to user actions these kinds of as hovers, clicks, variety submissions, and many others.

To give you an concept of what else can be with these parts, here’s a a lot more subtle example from Google. This adds the more complexity of demonstrating different solutions (the 1-pack, 2-pack, and 3-pack) and lets people today see all those goods in unique hues, but the basic principle of what you will learn beneath is the very same.

An example of AMP for Email that uses interactive images for different product packs.

Stage 1 – Speedy Start with the AMP Playground

We will use the official AMP Playground for this tutorial. I have gone ahead and provided some primary CSS for laying out our product or service graphic and the coloration selectors so you can emphasis on learning how the AMP parts get the job done.

Check out this customized AMP Playground for a swift way to get started.

An example of the code that generates the AMP ecommerce email element
The AMP Playground, established up just for this tutorial. Check out code in AMP Playground

Action 2 – Insert The Merchandise Details

Code at conclude of Action 2

Let’s begin laying out the information. We’ll start out with the item tile, description (just colour in this case), and the solution pictures. Include the adhering to inside the .

45 Qt Challenging Cooler

Colour Amber

Observe, we’re applying [text]=colorChoice. This is a hook that we can use later on in the tutorial to update the solution description with the selected shade. For case in point, when the user chooses “Blue”, the text will dynamically update from “COLOR Amber” to “COLOR Blue”.

Subsequent let’s increase our very first solution impression. Let’s start out with our default color, Amber.

The is contained within a div with a little bit of logic, [hidden]="!(colorChoice == 'Amber') which indicates that the Amber products graphic will only be witnessed when the user selects the Amber coloration.

Up coming, add the remaining merchandise photographs, just one for each colour. Every single of these will in the beginning be hidden, as the Amber coloration will be the default item variation.


An example of the AMP email code and the image is generates.
Environment the initial product or service structure. Check out code in AMP Playground

Move 3 – Introducing the Shade Selections

It’s finally time to increase a selector for every single of the shade options. We’ll use with the default, one-choice location so that they get the job done a great deal like a radio button. And on choosing a colour alternative, the amp-point out will be current to mirror that coloration selection. The improve to amp-state allows the relaxation of our document know to alter the product or service graphic and the shade description. Insert the pursuing beneath the products specifics.

The has an party cause. When it is selected, it updates the colorChoice variable. This variable is used to display screen the ideal merchandise picture and to update the shade description textual content in the product specifics.

on="decide on: AMP.setState(colorChoice: celebration.targetOption)"

At this stage, go in advance and attempt picking each and every shade decision. You should see your merchandise aspects update appropriately.

What the code for the AMP email looks like later on in development
Introducing the solution coloration selectors. Look at code in AMP Playground

Comprehension How it Will work

Listed here is a summary of the primary concepts made use of in this illustration.

Color Selectors: The colour selector, , has a “select” event. When the motion occurs, it updates the colorChoice variable during the document. ( is what associates an motion with 1 or more updates to the document.)

on="pick: AMP.setState(colorChoice: party.targetOption)"

Product or service Photos: The solution visuals have essential logic to cover or display every single image dependent on the value of the colorChoice variable. Instance: concealed = Legitimate when colorChoice is not equal to ‘Amber’.

[hidden]="!(colorChoice == 'Amber')"

Solution Description: The item description textual content also updates to the worth of the colorChoice variable.


Present us what you produced!

Subsequent, I advise sending on your own a copy of the message you created from this tutorial. Use an e mail service company that supports AMP for E mail this sort of as AWeber or use the Gmail AMP Playground.

If you ended up motivated by this write-up, I’d enjoy to see what you created! Share in the responses below or ship me an email and talk to me to consider a glance.

Leave a Reply