Recently the AMP project becomes more and more popular, especially considering it's being powered by Google and the pages created with following the Accelerated Mobile Pages requirements will display much faster on the mobile devices, get favored by the search engine and be placed higher in the search results. But what actually is the AMP HTML? What stands behind the abbreviation and all the noise? Let's take a look.
AMP HTML is actually a part of HTML for writer material web pages such as news articles in a way that prove special baseline functioning qualities.
Being a part attributed to HTML, it keeps a few limits on the complete collection of tags and functionality attainable with HTML however it does not really involve the growth of new rendering engines: existing user agents are able to render AMP HTML the same as all of the various other HTML.
Aiming to speed up the web pages and providing better performance the AMP project basically strips the regular HTML code down to what's known as AMP HTML. Along with some regular HTML tags get replaced by AMP-ed ones which get particularly served over the page load by the only one script on page acceptable – the AMP library (you've guessed it). Another major stripping down feature is no external style sheets are allowed – all the custom styling gets placed in a style tag inside the <head>
.
A key feature of the AMP HTML project is that the pages utilizing it should be independent of the project itself, so also providing a regular version of the page is advised but not mandatory. A good thing is the companies like Google, Pinterest and Twitter will most probably cache your amp pages and display them from their own cache.
AMP HTML data can surely be loaded to a net server and delivered much like any different HTML file; no exclusive composition for the web server is required. But yet, they are in addition built to get optionally presented via specialised AMP providing systems which proxy AMP documents. These particular data serve them through their unique beginning and are permitted to utilize modifications to the document that supply additional performance profits. An unaccomplished selection of optimizations such a serving program might actually handle is:
- Switch out pic references with images scaled to the customer's viewport.
- Inline images which are visible over the fold.
- Inline CSS variables.
- Preload enhanced items.
- Lessen HTML and CSS.
AMP HTML applies a package of contributed but centrally controlled as well as organized custom-made components to incorporate highly developed performance such as image galleries that can be spotted in an AMP HTML document. While it does permit styling the document employing custom made CSS, it does not let publisher written JavaScript beyond what is presented throughout the customized materials to achieve its action aims.
By utilizing the AMP format, material creators are building the web content in AMP files accessible to be crawled ( based on robots.txt rules), cached, and revealed by third parties.
In order to be an AMP, a web page's mark-up should follow some requirements:
It should start with <!doctype html>
directly followed by <html amp>
or it alternative where html gets followed by a weird Unicode lightning-like character.
The AMP page should mandatory contain <head>
and <body>
tags which in general HTML are considered optional to be explicitly defined. As a first child of the <head>
tag <meta charset="utf-8">
should be defined.
Also a <link rel="canonical" href=" ~ some kind of URL here including the present one if there isn't a regular (non AMP page) ~ " />
, followed by <meta name="viewport" content="width=device-width,minimum-scale=1">
tag where they also recommend additionally assigning initial-scale=1
attribute but not as a must.
Check this handy list of requirements down below:
AMP HTML data conditions
All of the scripts included in an AMP page should be loaded asynchronously – meaning they should be carrying the async
attribute. There is a strict restriction regarding scripts in AMP – including them is almost prohibited. The only exclusions are the AMP scripts themselves – the core script:
<script async src="https://cdn.ampproject.org/v0.js"></script>
which should take place in the <head>
in order the AMP runtime to be loaded, the AMP extended components and eventually – scripts from the type of application/ld+json
That's pretty much it – everything else is strictly prohibited. So if you are going to make an AMP page – forget your favorite scripts – either replace the functionality they provide with one from the AMP extended components, or find a way dealing without them. JavaScript in any form is prohibited in link's targets as well.
And since we're talking about forgetting – forget external style sheets. Linking them in an AMP page based on AMP eCommerce Template is prohibited – all the styling takes place inline. There also is a restriction of the <style>
tags allowed. There must be a specific style tag called <style amp-boilerplate>
with s fixed content (you can easily find it in the AMP documentation page) and a single <style amp-custom>
tag in which you should place all the custom styling you eventually might need to add to your pages created with AMP One Page Template. That's it.
Open Graph metadata isn't a mandatory part of the AMP pages but they strongly encourage the developers adding it – in other words – it's not on the TO DO list.
Some HTML tags are forbidden in AMP and some of the most commonly used are replaced by their own like <div class="img"><img></div>
gets <amp-img>
. iframe, video
and audio
get amp-
prefixes as well. If there is a link with the target
attribute – its value should be _blank
HTML attributes starting with the prefix on
are not allowed. Only pure on
is allowed (no suffixes) and as been said before - AMP forbids <style>
tags as well. (You will find full list of replaced HTML Tags below in this article)
No fonts libraries for you in your AMP pages except for the so-called whitelisted font providers which at this time are Google fonts (of course), Fonts.com and Font awesome. Otherwise you may self host your fonts and include them in your styling via @font-face
but not with @import
- this is restricted as well.
Predictable working is certainly a vital layout target when it comes to AMP HTML. Fundamentally we are fixing at lessening the period of time til the web content of a page can be consumed/ handled by the customer. By detailed terms, this stuff signifies that:
- HTTP requests essential to render and fully layout the file should be lessened.
- Resources, for example, images or else ads needs to only be launched on the assumption that they are actually most likely to get observed by visitor.
- Web browsers should really have the capacity to calculate the area required by every resource on the web page without delivering that resource.
Sample document
This is truly suggested that AMP HTML data are annotated having standardized metadata: Open Graph Protocol, Twitter Cards, etc.
Strongly recommended that AMP HTML pages are labelled up by using schema.org/CreativeWork or any one of its more specific sorts, for example, schema.org/NewsArticle or schema.org/BlogPosting. (You can certainly discover all websites on the official AMP internet site - https://www.ampproject.org).
HTML tags can be applied unaltered within AMP HTML. Several tags come with equivalent customized tags ( for example <div class="img"><img></div>
and <amp-img>
) and other tags are outright forbidden:
Validator utilizations need to operate a whitelist formed on the HTML5 spec with the mentioned above tags taken down. Look at AMP Tag Addendum.
Conditional HTML Relative HTML comments are not enabled.
Attribute names starting off with on
( like onclick or else onmouseover
) are denied within AMP HTML. The feature having the literal name on
(no suffix) is permitted.
The style
attribute must not be applied.
XML-related characteristics, as xmlns
, xml: lang
, xml: base
, and xml: space
are denied within AMP HTML.
Inner AMP attributes prefixed having i-amp-
are prohibited in AMP HTML.
Internal AMP class names prefixed having -amp-
and i-amp-
are disallowed within AMP HTML.
Visit AMP information for significance of class names prefixed using amp-
. The operation of these kinds of classes is permitted and signified to grant the modification of a number of characteristics of AMP runtime and extensions.
All other written class names are enabled in AMP HTML markup.
Inner AMP IDs prefixed with -amp-
and i-amp-
are forbidden in AMP HTML.
See AMP information for certain extensions before using amp-
and AMP IDs to steer clear of conflict with the features ensured by these types of additions, such as amp-access
.
All alternative authored IDs are allowed in AMP HTML markup.
The javascript:
scheme is excluded.
Significant semantic tags, as well as the AMP custom features, possess default looks to generate authoring a responsive documentation reasonably easy. An alternative to opt out of default varieties can be provided in the possible future.
The following @- rules are really granted in stylesheets:
@font- face<code>, <code>@keyframes<code>, <code>@media<code>, <code>@supports<code>.
<code>@import<code> will certainly not be let. Additional can be provided in the coming future.
<h3>Author stylesheets</h3>
Creators can bring in custom-made formats to a file operating an individual <code><style amp-custom><code> tag in the heading of the document.
<h3>Selectors</h3>
The following restrictions apply to selectors in author style sheets:
<h4>Class and tag names</h4>
Class names, IDs, tag names and features, inside of author stylesheets, may not really initiate with the string <code>-amp-
and i-amp-
. These particular are reserved for inner usage due to the AMP runtime. It follows, that the user's stylesheet can not really stating CSS selectors for -amp-
classes, i-amp-
IDs and i-amp-
tags and characteristics. These classes, IDs and tag/attribute names are not actually denoted to get customed by authors. Creators, though, can easily override formats of amp-
classes along with tags for any kind of CSS characteristics not explicitly denied by these components' spec.
To prevent consumption of attribute selectors to get around class name limits it is commonly not allowed for CSS selectors to include tokens and strings setting up with -amp-
plus i-amp-
.
Handling of the ! important
adverb is not admitted. This is a required condition to make it easy for AMP to perform its own aspect sizing regular.
These types of CSS capabilities are entirely banished :
- behavior
- -moz-binding
The next properties are at the moment excluded because of functionality concerns:
- filter
AMP solely enables changes and animations of attributes that can be GPU increased in common web browsers. Current whitelist: opacity
, transform
(also - vendorPrefix-transform
). Within the following illustrations <property>
ought to be within the whitelist mentioned earlier.
- transition <property>
(also -vendorPrefix-transition)
- @keyframes name from: <property>: value to <property: value>
(also @-vendorPrefix-keyframes
)
overflow
(and overflow-y
, overflow-x
) may not be designated as "auto" or else "scroll". No user defined material within an AMP document may obtain a scrollbar.
It is really a validation mistake whenever the author stylesheet is higher than 50,000 bytes.
Writers can involve stylesheets for custom-made font styles. The 2 provided approaches are attach tags indicating whitelisted font dealers and @font- face
introduction.
Good example:
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Tangerine">
Font dealers can easily be whitelisted if they sustain CSS-only integrations and offer over HTTPS. The following origins are generally supported for font presenting by means of web link tags:
- Fonts.com: https://fast.fonts.net
- Google Fonts: https://fonts.googleapis.com
- Font Awesome: https://maxcdn.bootstrapcdn.com
IMPLEMENTERS NOTE: Putting in this specific list needs a switch to the AMP Cache CSP rule. Writers are actually free to provide all of the custom fonts through an @font-face
CSS direction through their custom CSS. Fonts utilized through @font-face
must be obtained via the HTTP or HTTPS scheme.
The AMP runtime is simply a part of JavaScript which functions in any AMP file. It delivers implementations for AMP custom components, deals with material launching and prioritization and additionally provides a runtime validator for AMP HTML for operation while improvement.
The AMP runtime is installed by the mandatory <script src="https://cdn.ampproject.org/v0.js"></script>
tag inside of the AMP document <head>
.
The AMP runtime may be set into a development state for any kind of page. Development form will lead to AMP approval on the planted web page, which in turn will discharge the affirmation state and any type of glitches to the JavaScript developer control console. Development form can be actually caused via adding #development= 1
to the WEBSITE ADDRESS of the web page.
Resources such as pictures, video recordings, sound recording files or else commercials have to be featured into an AMP HTML file through custom made features just like <amp-img>
. It is titled "controlled materials" simply because whether and when they will certainly be installed and promoted to the user is selected by AMP runtime.
There are absolutely no certain guarantees as to the loading behavior of the AMP runtime, however it must usually make every effort to load sources quickly enough, to ensure they are installed by the time the user would love to see them preferably. The runtime really should differentiate materials presented in the viewport and effort to forecast modifications to the viewport and preload sources accordingly.
The AMP runtime may at any time make a decision to unload sources which are not generally in the viewport or else reuse the useful resource packages for instance, iframes to lower entire RAM utilization.
AMP HTML applies custom made elements knowned as "AMP elements" to replace embedded resource-loading tags just like <div class="img"><img></div>
and <video>
and to execute elements with complex communications like illustration lightboxes or else carousels.
View the AMP component specifications for aspects of supported elements.
There are simply 2 types of upheld AMP elements:
1. Built-in
2. Increased
Inbuilt items are typically available inside of an AMP file and have a specific custom-made element like <amp-img>
. Expanded components must be explicitly provided within the document.
layout
, width
, height
, media
, placeholder
, fallback
These features determine the layout of an element. The important aim here is simply to ensure that the element is able to be shown and its own area can be appropriately reserved right before any of the JavaScript or distant useful resources have been downloaded.
View the AMP Layout System for detailed information regarding the design system.
on
The on
characteristic is utilized to install event handlers on components. The situations that are maintained according to the feature.
The value for the format is actually a plain domain special language of the form:
eventName:targetId[.methodName[(arg1=value, arg2=value)]]
For example: on="tap:fooId.showLightbox"
In the case that methodName
is passed over the default solution is executed if defined for the feature . An example: on=" tap: fooId"
Several practices, if logged , can admit arguments. The arguments are characterized between parentheses in key= value
notation. The approved values are:
- plain unquoted strings: simple-value
;.
- quoted strings: " string value"
or ' string value'
;.
- boolean values: true
or else false
;.
- numbers: 11
or 1.1
.
You can surely give attention to multiple events on an element with splitting the two activities by using a semicolon ;
.
Good example: on=" submit-success: lightbox1; submit-error: lightbox2"
View more about AMP Actions and Events on the official web-site.
Expanded components are simply components which do certainly not necessarily ship with the AMP runtime. Actually, they must be clearly provided in the file.
Extensive components are loaded by providing a <script>
tag in the head of the document similar to this:
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
The <script>
tag must definitely have an async
attribute and ought to have a custom-element
characteristic referencing the title of the component.
Runtime implementations may employ the name to make placeholders for these types of components.
The script WEBSITE ADDRESS must start with "https://cdn.ampproject.org" and needs to follow a pretty exact standard of / v \ d+/ [a-z-] +-( latest | \ d+ | \ d+. \ d+). js.
The ADDRESS for extended components is of the form:
https://cdn.ampproject.org/$RUNTIME_VERSION/$ELEMENT_NAME-$ELEMENT_VERSION.js
See the AMP versioning practice.
Templates deliver HTML material based on the language-specific template and given JSON data.
View the AMP template specification for aspects regarding supported templates.
Expanded templates are not actually transported with the AMP runtime and have to be downloaded exactly as with expanded features. Expanded components are loaded simply by involving a <script>
tag in the head of the file this way:
<script async custom-template="amp-mustache" src="https://cdn.ampproject.org/v0/amp-mustache-0.1.js"></script>
The <script>
tag must have an async
feature and ought to have a custom-template
attribute referencing the sort of the template. The script URL must begin with "https://cdn.ampproject.org" and must follow a very strict pattern of / v \ d+/ [a-z-] +-( latest | \ d+ | \ d+. \ d+). js
.
The templates are claimed inside of the document just as following:
<template type="amp-mustache" id="template1">
Hello you!
</template>
The type
attribute is demanded and ought to note a stated custom-template
script.
The id
attribute is alternative. Specific AMP features identify their own templates. Standard situations would include an AMP element hunting for a <template>
either among its own children or else referenced by ID.
To learn about the format and rules for an extended template, head to the extensive template's information.
The URL for expanded components is of the form:
https://cdn.ampproject.org/$RUNTIME_VERSION/$TEMPLATE_TYPE-$TEMPLATE_VERSION.js
Notice versioning of custom elements for more details.
AMP HTML forms should not activate glitches once presented by a Content Security Policy that does not provide the keywords unsafe-inline and unsafe-eval.
The AMP HTML configuration is produced thus that is actually regularly the case.
All of AMP template components ought to go through AMP security examination well before they have the ability to be submitted in to AMP database.
Currently, the following SVG features are approved:
In addition to these particular features:
"xlink:href": only URIs starting with "#" are allowed
"style"
The technique detailed here supplies a standardized technique for software to find if an AMP variation exists for a canonic document.
In the case that an AMP document exists that is another illustration of a canonical document, then the legal document ought to indicate the AMP file with a link
tag with the connection "amphtml".
An example:
<link rel="amphtml" href="https://www.example.com/url/to/amp/document.html">
The AMP document itself is expected to point back to its canonical document via a link tag with the relation "canonical".
An example:
<link rel="canonical" href="https://www.example.com/url/to/canonical/document.html">
( On the occasion that a single material is simultaneously the AMP and the legal file, the approved association ought to aim to itself-- no "amphtml" relation is expected.).
Note that for best compatibility with AMP-consuming systems, it must be feasible to read the "amphtml" association without performing JavaScript. (That is, the tag needs to be present in the raw HTML, and not injected by JavaScript.).
Basically, that's pretty much the way AMP HTML should be organized. It consists of quite a few strict rules and restrictions but hopefully following them we'll get fast performing alternatives on our mobiles. Additionally as we mentioned above you're not bound to using the AMP standard only – it is a good practice to have a regular normal web page to get displayed on computer containing a <link rel="amphtml" href="~ the address of your AMP page ~ ">
tag in its <head>
this is the one canonical link from the AMP page should point to in turn. So if the visitor tries accessing your content from a stronger device all the goodies get loaded and if the page is being viewed on the go – nothing to stand between the content and the reader.