List of important custom and in-built AMP tags


amp-img is use as replacment of HTML img tag. amp-img tag effectively manage image resource at runtime. It uses lazy load to reduce page load time.

To use amp-img need to specify width and height, src attriburtes. It also support three optional attributes srcset, alt, attribution.

  • src – url of image need to display.
  • srcset – for retine ready images. We can provide different image for devices varying pixel ratio.
  • attribution – to set attribution text of the image.

To set image to responsive use layout attribute and set it value responsive.

Example of amp-img
<amp-img src="/img/amp.jpg"
srcset="/img/amp.jpg 1080w, /img/amp-900.jpg 900w, /img/amp-800.jpg 800w,
/img/amp-700.jpg 700w, /img/amp-600.jpg 600w, /img/amp-500.jpg 500w, /img/amp-400.jpg 400w,
/img/amp-300.jpg 300w, /img/amp-200.jpg 200w, /img/amp-100.jpg 100w"
alt="an image"></amp-img>

amp-img is builtin tag and imported via the AMP js.


amp-video is replacement of Html Video tag. It also lazy load video at runtime.

To use amp-video you must specify width, height and src attributes. It also support some more optional attributes poster, autoplay, controls, loop, muted. It also accept three unique HTML child nodes tag, placeholder before video start, and fallback.

Example of amp-video
<amp-video width=400 height=300 src=""
  <div fallback>
    <p>Your browser doesn’t support HTML5 video</p>
  <source type="video/mp4" src="foo.mp4">
  <source type="video/webm" src="foo.webm">

amp-video is in-builtn tag and imported via the AMP js.


amp-audio is replacement of HTML audio tag. It is use to embed audio file in amp pages.

To use amp-audio you must specify src, width and height attributes, amp-audio also have three more optional attribute autoplay, loop and muted.

  • src – audio file url.
  • autoplay – It will autoplay animated image.
  • loop – it will auto loop audio.
  • muted – muted audio by default.
Example of amp-audio
 <amp-audio width="400" height="300" src="">
  <div fallback>
    <p>Your browser doesn’t support HTML5 audio</p>
  <source type="audio/mpeg" src="foo.mp3">
  <source type="audio/ogg" src="foo.ogg">

To use amp-audio you have to include below script in <head> section

 <script async custom-element="amp-audio" src=""></script>


amp-accordion is use to implement accordion in amp pages. Accordion is mostly use in faq pages.

Amp-accordion can have one or more first child node <section> and each <section>contain 2 child node first one is heading and second node is content and clicking heading it will toggle display of content.

Below example of amp-accordion
  <section expanded>
    <h2>Section 1</h2>
    <p>Bunch of awesome content</p>
    <h2>Section 2</h2>
    <div>Bunch of awesome content</div>
    <h2>Section 3</h2>
    <amp-img src="/awesome.png" width="300" height="300"></amp-img>

amp-accordion also provides below attributes

  • disable-session-states – to disable preserving the collapsed/expanded state of the amp-accordion element
  • expanded – to set on any <section> expanded on page load.

To use amp-accordion you have to include below script in <head> section

<script async custom-element="amp-accordion" src=""></script>


amp-carousel tag to display content boxes horizontally. A carousel is set of number of items with optional navigational arrow. The carousel move items if user swipe, or use arrow key or use navigation arrow.

To use amp-carousel you must specify height attribute, it also provide more optional attributes controls, type, loop, autoplay, delay.

  • controls – to display navigation arrow
  • type – by default its value is carousel all slides are shown and scrollable. If type value is Slides, it will display singe silde at a time. With type slides you can use three more attribute loop, autoplay, delay.
Example of carousel
 <amp-carousel width=300 height=400>
  <amp-img src="my-img1.png" width=300 height=400></amp-img>
  <amp-img src="my-img2.png" width=300 height=400></amp-img>
  <amp-img src="my-img3.png" width=300 height=400></amp-img>

To use amp-audio you have to include below script in <head> section

<script async custom-element="amp-carousel" src=""></script>


amp-lightbox tag to implement light box interface. amp-lightbox will have to define child node
to display child node content in lightbox on tap or click event.

Example of amp-lightbox
 <button on="tap:my-lightbox">Open lightbox</button>
<amp-lightbox id="my-lightbox" layout="nodisplay">
  <div class="lightbox">
    <amp-img src="my-full-image.jpg" width=300 height=800 on="tap:my-lightbox.close">

To use amp-lightbox you have to include below script in <head> section

<script async custom-element="amp-lightbox" src=""></script>


amp-ad is use to display ads. amp-embed is an alias of the amp-ad and use amp-embed when logically more accurate. Your ad javascript will not run inside your amp page, AMP will loads an iframe on runtime and execute ad javascript inside iframe sandbox.

To use amp-ad you need to specify type, width, height attributes. Type is name of ad network to which your ad belong. All data-* attributes also depend on type of network.

Below example amp-ad of for different type of network

 <amp-ad width=300 height=250

<amp-ad width=320 height=140

<amp-embed width=400 height=300
    data-placement="Below Article Thumbnails">

To use amp-ad you have to include below script in <head> section

<script async custom-element="amp-ad" src=""></script>


amp-analytics is use to collect analytics data from an AMP page. Currently amp-analytics support below events:

  • Pageview
  • Anchor Clicks
  • Timer
  • Scrolling
  • AMP Carousel changes

To send data to analytcis server you need to specify json configuration object inside amp-analytics tag. Some vendor provide pre configure json configuration object. With type attribute you can set vendor and their json object.

Example for amp-analytics
<amp-analytics type=”abc”>
<script type="application/json">

To use amp-analytics you have to include below script in <head> section

<script async custom-element="amp-analytics" src=""></script>


amp-iframe to display an iframe in AMP pages. amp-iframe is more secure than html <iframe> tag.

To use amp-iframe you must follow these rules iframe must be at least 600px or 75% of the first viewport away from the top and can only request resources via HTTPS.

Example for amp-iframe
 <amp-iframe width="500"
      sandbox="allow-scripts allow-same-origin allow-popups"

To include an amp-iframe, first include the following script to the <head>

<script async custom-element="amp-iframe"

Amp also provide some more tags that we can use when require <amp-selector>, <amp-sidebar>,<amp-facebook>,<amp-instagram>,<amp-pinterest>,<amp-playbuzz>,<amp-twitter>,<amp-vine>,<amp-form>,<amp-font>,<amp-dynamic-css-classes>,<amp-anim>,<amp-app-banner> and more you can refer it on amp officia site.

Note: Also check AMP page example code

AMP (Accelerated Mobile Pages) Example Pages

AMP (Accelerated Mobile Pages) is a Google open source project to speed up page load in mobile devices.

AMP consist of three main parts

  • AMP HTML is HTML with custom AMP tags, properties and some restrictions like only subset of css and html are not allowed that slow down page loading. Only valid AMP HTML files will be shown in Google Search.
  • AMP JS library manage resource loading, provide custom tags, load external resources asynchronously so external resources should not block page rendering, pre-calculate layout of every element before any resources are loaded and it also disable slow CSS selectors.
  • Google AMP CACHE is a content delivery network. It fetches valid AMP HTML pages and cache them to improve page performance.

Sample AMP html

<!doctype html>
<html amp lang="en">
<meta charset="utf-8">
<script async src=""></script>
<title>Hello, AMPs</title>
<link rel="canonical" href="" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<script type="application/ld+json">
"@context": "",
"@type": "NewsArticle",
"headline": "Open-source framework for publishing content",
"datePublished": "2015-10-07T12:02:41Z",
"image": [
<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>
<h1>Welcome to the mobile web</h1>

Required markup for AMP HTML document

  • Start your document with the doctype <!doctype html>.
  • Below doctype <html > tag (<html amp> is accepted as well).
  • Require <head> and <body> tags
  • First tag after <head> is <meta charset=”utf-8″>
  • Include a <script async src=””></script> tag as the second child of their <head> tag (this includes and loads the AMP JS library).
  • <link rel=”canonical” href=”$SOME_URL” /> tag inside their <head> tag that points to the regular HTML version of the AMP HTML document or to itself if no such HTML version exists.
  • Add a <meta name=”viewport” content=”width=device-width,minimum-scale=1″> tag inside their <head> tag. It’s also recommended to include initial-scale=1.
  • Add the following in <head> tag:
    <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>

Optional meta-data

A definition in above sample code is optional. However you can use it, if you want to distribute your content in some places like google search news top stories, rich cards, critic review cards according to your content type.


As we learn about required syntax need to follow , when you create AMP web page make sure that is valid AMP. It should display correctly to mobile devices to users. You can validate your AMP pages at

Link AMP and non AMP pages

To make sure that search engines read (index) your we pages correctly. You need to add canonical link.

On normal web page –

<link rel="amphtml" href="amp-page-url" />

On AMP web page –

<link rel="canonical" href="none-amp-page-url" />


Non Amp page:
Amp Page:

Improved loading performance

Page load time, http request, page size all almost improved by more than 50%.

Note: In our next post we will going to write about AMP built-in and custom tags.

Gzip compression – to make website load faster

Now a days Gzip compression become popular for speed up website. It compresses webpage upto 60% to 80%. We know about zipping a file to make them use less space, today web servers can also compress the content before sending it to your browsers. It lower the bandwidth requirements of your server and speed up your site.


How Gzip works? Click Here to watch video


If mod_deflate and mod_gzip modules is enable on server, Here is the code you should added to your .htaccess file.

< ifModule mod_gzip.c >
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
< / ifModule >


If the above code did not seem to work, do not afraid there is other way to do it, remove above code from your .htaccess file and add this code in .htaccess file.

< IfModule mod_deflate.c >

# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css

# Level of compression (Highest 9 – Lowest 1)
DeflateCompressionLevel 9

# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html

< IfModule mod_headers.c >
# Make sure proxies don’t deliver the wrong content
Header append Vary User-Agent env=!dont-vary

< /IfModule >
< /IfModule >


Some hosting provider disable mod_deflate and mod_gzip modules, so above code will not work for you. Here is the solution.


1) Create file called headers.php and add the following code, upload to public_html or htdocs folder.

< ? php
if (isset($_SERVER['SCRIPT_FILENAME'])) {
$timestamp = filemtime(__FILE__);
header('Last-Modified: ' . $timestamp);
$expirestime = 60*60*24*30;
header("Pragma: public");
header("Cache-Control: maxage=".$expirestime);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expirestime) . ' GMT');
header('Vary: Accept-Encoding');
$pathinfo = pathinfo($_SERVER['SCRIPT_FILENAME']);
$fileextension = $pathinfo['extension'];
if ($fileextension == 'css') {
header('Content-type: text/css;
if ($fileextension == 'js') {
header('Content-type: text/javascript;
} ? >


2) Create another file and give the name php.ini and add following code in it.
auto_prepend_file=[PATH OF headers.php FILE]

if zlib.output_compression=1 is not work try utput_handler=ob_gzhandler instead.
Now you need to upload copy of php.ini file in every folder containing files you want to compress.


3) Now add below code in your .htaccess file
AddType x-mapp-php5 .php .shtml .html .htm .txt .js .css
if you have php4 then add x-mapp-php4 instead x-mapp-php5
if x-mapp-ph Continue reading Gzip compression – to make website load faster