AMP by Example

Introduction
Introduction

Components
Components

Advanced
Advanced

Samples & Templates
Samples & Templates

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

View Source

amp-twitter

Introduction

Embed tweets into your AMP HTML files.

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

Setup

Don't forget to import the twitter component

  <script async custom-element="amp-twitter" src="https://cdn.ampproject.org/v0/amp-twitter-0.1.js"></script>
Show Hidden Code Hide Code
  <link rel="canonical" href="https://ampbyexample.com/components/amp-twitter/">
  <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

Tweets are embedded via id.

  <amp-twitter width="375"
      height="472"
      layout="responsive"
      data-tweetid="638793490521001985">
  </amp-twitter>

Options for the Tweet appearance can be set using data- attributes. E.g. data-cards="hidden" deactivates Twitter cards.

  <amp-twitter width="390"
      height="330"
      layout="responsive"
      data-tweetid="585110598171631616"
      data-cards="hidden">
  </amp-twitter>

Twitter does not currently provide an API that yields fixed aspect ratio Tweet embeds. You may need to manually tweak the provided width and height.

  <amp-twitter width="390"
      height="330"
      data-tweetid="585110598171631616"
      data-cards="hidden">
  </amp-twitter>
</body>
</html>