AMP by Example

Introduction
Introduction

Components
Components

Advanced
Advanced

Samples & Templates
Samples & Templates

AMP for Ads (A4A)
AMP for Ads (A4A)

View Source

amp-anim

Introduction

Embed animations (gif, webp) into your AMP HTML files. Animation files should be loaded via HTTPS.

Show Hidden Code Hide Code
<!doctype html>
<html ⚡>
<head>
  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>

Setup

Import the animation component in the header.

  <script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>
Show Hidden Code Hide Code
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <link rel="canonical" href="https://ampbyexample.com/components/amp-anim/">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>

Basic Usage

A basic embed. The usage of amp-anim is similar to that of amp-img.

  <amp-anim width=245
      height=300
      src="/img/gopher.gif"
      alt="an animation"
      attribution="The Go gopher was designed by Reneee French and is licensed under CC 3.0 attributions.">
  </amp-anim>

You can use amp-img as a placeholder when loading of src file takes time. placeholder attribute must be assigned in the child amp-img in this case.

  <amp-anim width=245
      height=300
      src="/img/gopher.gif"
      alt="an animation"
      attribution="The Go gopher was designed by Reneee French and is licensed under CC 3.0 attributions.">
    <amp-img placeholder
        width=245
        height=300
        src="/img/gopher.png">
    </amp-img>
  </amp-anim>

Next up:

</body>
</html>