AMP by Example

Introduction
Introduction

Components
Components

Advanced
Advanced

Samples & Templates
Samples & Templates

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

View Source

amp-video

Introduction

Embed videos into your AMP HTML files. Video source files should be served via HTTPS.

<!doctype html>
<html ⚡>
<head>
  <meta charset="utf-8">

Setup

amp-video is builtin custom tag and is automatically imported via the AMP runtime.

  <script async src="https://cdn.ampproject.org/v0.js"></script>
Show Hidden Code Hide Code
  <link rel="canonical" href="https://ampbyexample.com/components/amp-video/">
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <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 simple video with controller. amp-video supports the following formats: mp4, webm, ogg together with all the formats supported by the HTML5 video tag including HLS. Boolean attribute (controls in this case) must be without values. Expression with value like controls="controls" is invalid.

  <amp-video width=480
      height=270
      src="/video/tokyo.mp4"
      poster="/img/tokyo.jpg"
      layout="responsive"
      controls>
    <div fallback>
      <p>Your browser doesn't support HTML5 video.</p>
    </div>
    <source type="video/mp4"
        src="/video/tokyo.mp4">
    <source type="video/webm"
        src="/video/tokyo.webm">
  </amp-video>

Your browser doesn't support HTML5 video.

Autoplay

Setting autoplay will automatically play/pause the video as it is scrolled into/out of view on supported browsers.

The video is automatically muted before autoplay starts, when the user taps the video, the video is unmuted.

If the user has interacted with the video (e.g., mutes/unmutes, pauses/resumes, etc.), and the video is scrolled in or out of view, the state of the video remains as how the user left it.

  <amp-video width=480
      height=270
      src="/video/tokyo.mp4"
      poster="/img/tokyo.jpg"
      layout="responsive"
      controls
      autoplay>
    <div fallback>
      <p>Your browser doesn't support HTML5 video.</p>
    </div>
    <source type="video/webm"
        src="/video/tokyo.webm">
  </amp-video>

Your browser doesn't support HTML5 video.

Next up:

</body>
</html>