AMP by Example

Introduction
Introduction

Components
Components

Advanced
Advanced

Samples & Templates
Samples & Templates

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

View Demo View Source

News Article

Introduction

This is a sample template for a news article in AMP. It demonstrates the usage of AMP components which works well in news articles. Examples include social sharing, image galleries, personalized content, ads, and more.

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

Setup

All additionally used AMP components must be imported in the header.

    <script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
Show Hidden Code Hide Code
    <script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>
    <script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
    <script async custom-element="amp-user-notification" src="https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"></script>
    <script async custom-element="amp-list" src="https://cdn.ampproject.org/v0/amp-list-0.1.js"></script>
    <script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
    <link rel="canonical" href="https://ampbyexample.com/samples_templates/news_article/">

Metadata

The Top Stories carousel requires schema.org markup for one of the following types: Article, NewsArticle, BlogPosting, or VideoObject. Learn more.

    <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "NewsArticle",
      "mainEntityOfPage": "https://ampbyexample.com/samples_templates/news_article/",
      "headline": "Lorem Ipsum",
      "datePublished": "2016-04-21T11:55:02Z",
      "dateModified": "2016-04-21T11:55:02Z",
      "description": "A sample news article build with AMP.",
      "author": {
        "@type": "Person",
        "name": "Sebastian Benz"
      },
      "publisher": {
        "@type": "Organization",
        "name": "Google",
        "logo": {
          "@type": "ImageObject",
          "url": "http://cdn.ampproject.org/logo.jpg",
          "width": 600,
          "height": 60
        }
      },
      "image": {
        "@type": "ImageObject",
        "url": "https://ampbyexample.com/img/landscape_lake_1280x857.jpg",
        "height": 1280,
        "width": 857
      }
    }
    </script>
Show Hidden Code Hide Code
    <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>
      <style amp-custom>
  .carousel .slide > amp-img > img {
    object-fit: contain;
  }
  .logo {
    background-position: left 16px center;
    background-repeat: no-repeat;
    background-image: -webkit-image-set(
      url(/img/ic_menu_white_1x_web_24dp.png) 1x,
      url(/img/ic_menu_white_2x_web_24dp.png) 2x
      );
    background-color: #333;
    text-align: left;
    padding: 16px;
    padding-left: 72px;
    box-shadow: 0 2px 2px 0 rgba(0,0,0,.14),0 3px 1px -2px rgba(0,0,0,.2),0 1px 5px 0 rgba(0,0,0,.12);
  }
  .logo > a {
    font-size: 16px;
    font-weight: 500;
    color: white;
    text-transform: uppercase;
  }
  .heading {
    padding-bottom: 8px;
  }
  .heading > #summary {
    font-weight: 500;
  }
  .heading > small {
    color: #656565;
  }
  .related {
   background-color: #f5f5f5;
   margin: 16px 16px;
   display: block;
   color: #111;
   height: 75px;
   padding: 0;
 }
 .related > span {
   font-size: 16px;
   line-height: 75px;
   font-weight: 400;
   vertical-align: top;
   margin: 8px;
 }
 .related:hover {
   background-color: #ccc;
 }
 amp-user-notification {
   padding: 8px;
   background: #bbb;
   text-align: center;
   color: white;
 }
      </style>

  </head>
<body>
  <div class="logo">
    <a href="/"> AMP by Example</a>
  </div>
Show Hidden Code Hide Code

  <div class="heading">
    <h1>A sample AMP Article</h1>
    <p id="summary">This is a sample article demonstrating how to write a news article in AMP. It demonstrates the usage of AMP components which works well in news articles. Examples include social sharing, image galleries, personalized content, ads, and more.</p>
    <p>
      <small>by Sebastian Benz</small>
    </p>
  </div>

A sample AMP Article

This is a sample article demonstrating how to write a news article in AMP. It demonstrates the usage of AMP components which works well in news articles. Examples include social sharing, image galleries, personalized content, ads, and more.

by Sebastian Benz

Social Sharing

The Social Share extension provides a common interface for share buttons. Learn more about amp-social-share here.

  <p class="heading">
    <amp-social-share type="twitter"
        width="45"
        height="33"></amp-social-share>
    <amp-social-share type="facebook"
        width="45"
        height="33"
        data-attribution=254325784911610></amp-social-share>
    <amp-social-share type="gplus"
        width="45"
        height="33"></amp-social-share>
    <amp-social-share type="email"
        width="45"
        height="33"></amp-social-share>
    <amp-social-share type="pinterest"
        width="45"
        height="33"></amp-social-share>
  </p>

Show Hidden Code Hide Code

  <p>Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum,
    tale utinam postea mei in, eam in odio dicta patrioque.
  </p>
  <p>
    Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis
    moderatius, est reque vidisse copiosae eu.
  </p>
  <p>
    Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.
  </p>

  <figure>
    <amp-img src="/img/landscape_village_1280x853.jpg"
        width=1280
        height=768
        layout=responsive></amp-img>
    <figcaption>Here is a responsive image.</figcaption>
  </figure>

  <p>Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum,
    tale utinam postea mei in, eam in odio dicta patrioque.</p>

Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum, tale utinam postea mei in, eam in odio dicta patrioque.

Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis moderatius, est reque vidisse copiosae eu.

Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.

Here is a responsive image.

Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum, tale utinam postea mei in, eam in odio dicta patrioque.

AD Support

There are no limitations regarding the number or placement of ads in an AMP. Learn more about amp-ad here.

  <div class="amp-ad-container">
    <span>amp-ad</span>
    <amp-ad width=300
        height=250
        type="a9"
        data-aax_size="300x250"
        data-aax_pubname="test123"
        data-aax_src="302">
    </amp-ad>
  </div>
amp-ad
Show Hidden Code Hide Code

  <p>
    Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis
    moderatius, est reque vidisse copiosae eu.</p>
  <p>
    Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.
  </p>
  <p>
    Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis
    moderatius, est reque vidisse copiosae eu.</p>
  <p>
    Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.
  </p>

Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis moderatius, est reque vidisse copiosae eu.

Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.

Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis moderatius, est reque vidisse copiosae eu.

Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.

Image Galleries

Use amp-carousel for image galleries. Learn more about creating image galleries in AMP here.

  <amp-carousel width="1280"
      height="970"
      layout="responsive"
      type="slides">
    <figure>
      <amp-img src="/img/landscape_trees_1280x960.jpg"
          width=1280
          height=960
          layout=responsive></amp-img>
      <figcaption>This is an image gallery.</figcaption>
    </figure>
    <figure>
      <amp-img src="/img/landscape_lake_1280x857.jpg"
          width=1280
          height=857
          layout=responsive></amp-img>
      <figcaption>Each image has a different caption.</figcaption>
    </figure>
    <figure>
      <amp-img src="/img/landscape_village_1280x853.jpg"
          width=1280
          height=853
          layout=responsive></amp-img>
      <figcaption>Each image has a different caption.</figcaption>
    </figure>
    <figure>
      <amp-img src="/img/landscape_trees_1280x960.jpg"
          width=1280
          height=960
          layout=responsive></amp-img>
      <figcaption>Each image has a different caption.</figcaption>
    </figure>
    <figure>
      <amp-img src="/img/landscape_desert_1280x853.jpg"
          width=1280
          height=853
          layout=responsive></amp-img>
      <figcaption>Each image has a different caption.</figcaption>
    </figure>
  </amp-carousel>
This is an image gallery.
Each image has a different caption.
Each image has a different caption.
Each image has a different caption.
Each image has a different caption.
Show Hidden Code Hide Code

  <p>Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum,
    tale utinam postea mei in, eam in odio dicta patrioque.
  </p>
  <p>
    Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis
    moderatius, est reque vidisse copiosae eu.
  </p>
  <p>
    Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.
  </p>

Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum, tale utinam postea mei in, eam in odio dicta patrioque.

Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis moderatius, est reque vidisse copiosae eu.

Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.

Interactive Content

To achieve its performance, AMP HTML doesn't allow custom Javascript. This doesn't mean that you can't created visually rich and interactive websites with AMP. Embed interactive content via amp-iframe. Learn more about amp-iframe here.

  <figure>
    <amp-iframe src="https://www.google.us/trends/embed/US_cu_82I1CVMBAACV6M_en/horserace_chart_3c6cdb21-e1eb-4412-9c28-707c3638ea35?hl=en&template=fe"
        height="360"
        layout="fixed-height"
        frameborder="0"
        sandbox="allow-scripts allow-same-origin">
      <amp-img src="/img/oscars_placeholder_1.png"
          layout="fixed-height"
          height="360"
          width="auto"
          placeholder>
      </amp-img>
    </amp-iframe>
    <figcaption>An interactive chart - in AMP!</figcaption>
  </figure>
An interactive chart - in AMP!
Show Hidden Code Hide Code
  <p>Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum,
    tale utinam postea mei in, eam in odio dicta patrioque.
  </p>
  <p>
    Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis
    moderatius, est reque vidisse copiosae eu.
  </p>
  <p>
    Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.
  </p>

Lorem ipsum dolor sit amet, voluptua oporteat cum cu, eu vix interesset scribentur. Et iudico efficiendi duo, vim an odio iusto reformidans. At maluisset scripserit duo, cum in sumo delenit. Quot erant maiestatis usu ut. Ne mea maiorum vivendum argumentum, tale utinam postea mei in, eam in odio dicta patrioque.

Cum ad graeci legimus, ut duo omnesque petentium, mei saepe explicari principes eu. Ex mei ocurreret expetendis, ex errem blandit has. Phaedrum mediocrem appellantur his ut. Erat viris mediocrem id ius, ad dicta appareat assentior sit. Nec et nullam singulis moderatius, est reque vidisse copiosae eu.

Mutat dolores ea duo. Usu cu dico everti tincidunt, pri vero nullam vidisse no. Eam novum aeque populo cu. Verear contentiones ne quo, no sed consulatu definitionem.

  <h4>Related Articles</h4>

Related Articles

  <p>These articles might be interesting for you as well:</p>

These articles might be interesting for you as well:

It's a good idea to recommend related content to your readers. With amp-list it is possible to dynamically include personalized content into your AMPs. It's a good idea to link to the AMP version of related content in order to keep the user in the fast AMP world. Learn more about amp-list here

  <amp-list width=300
      height=75
      layout=responsive
      src="/json/related_articles.json">
    <template type="amp-mustache">
      <a class="card related"
          href={{url}}>
        <amp-img width="101"
            height="75"
            src="{{thumbnail}}"></amp-img>
        <span>{{title}}</span>
      </a>
    </template>
  </amp-list>

Use amp-user-notification to implement a cookie consent form (if needed). By default, the AMP runtime doesn't use cookies. Some analytics vendors might use require cookies though. Learn more about amp-user-notification here

  <amp-user-notification layout=nodisplay
      id="amp-user-notification1">
    This page might use cookies if your analytics vendor requires them.
    <a on="tap:amp-user-notification1.dismiss">Accept</a>
  </amp-user-notification>
This page might use cookies if your analytics vendor requires them. Accept

Analytics

Analytics must be configured in the body. Here we use Google Analytics to track pageviews.

  <amp-analytics type="googleanalytics">
    <script type="application/json">
      {
        "vars": {
          "account": "UA-73836974-1"
        },
        "triggers": {
          "default pageview": {
            "on": "visible",
            "request": "pageview",
            "vars": {
              "title": "{{title}}"
            }
          }
        }
      }
    </script>
  </amp-analytics>

Next up:

</body>
</html>