{"id":27788,"date":"2016-08-22T23:01:44","date_gmt":"2016-08-22T15:01:44","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=27788"},"modified":"2025-04-04T02:48:45","modified_gmt":"2025-04-03T18:48:45","slug":"important-amp-components","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/","title":{"rendered":"Top 10 Essential AMP Components for Mobile Optimization"},"content":{"rendered":"<p><strong><a href=\"https:\/\/www.ampproject.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Accelerated Mobile Pages<\/a><\/strong> or <strong>AMP<\/strong> is Google\u2019s initiative to <strong>make the mobile web faster<\/strong>. To achieve this goal, the AMP standards restrict how you can use HTML, CSS, and JavaScript, and <strong>manages the loading of external resources<\/strong>, such as images, videos, and ads <strong><a href=\"https:\/\/amp.dev\/documentation\/guides-and-tutorials\/learn\/spec\/amphtml\/?referrer=ampproject.org#amp-runtime\" target=\"_blank\" rel=\"noopener noreferrer\">via its own runtime<\/a><\/strong>.<\/p>\n<p>This entails that you <strong>cannot use<\/strong> either any custom (author-written or third-party) JavaScript or any resource-related HTML elements such as images and videos in your AMP documents.<\/p>\n<p>To bridge the gap between users\u2019 needs and best performance practices, AMP has <strong>specific Components<\/strong> you can <strong>use in place of these excluded elements<\/strong>.<\/p>\n<p>AMP Components are <strong>specific HTML tags<\/strong>. They behave similar to regular HTML tags: they have opening and closing tags, attributes, and most of them can be <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/spec\/amp-html-components.md#stylingtheming\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">styled with CSS<\/a>. They can be easily recognized, as they <strong>always start with the <code>amp-<\/code> prefix<\/strong>.<\/p>\n<p>There are two types of AMP Components: <strong><a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/developing.md\" target=\"_blank\" rel=\"noopener noreferrer\">built-in<\/a><\/strong> and <strong><a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/spec\/amp-html-components.md#extended-components\" target=\"_blank\" rel=\"noopener noreferrer\">extended<\/a><\/strong> Components.<\/p>\n<div class=\"ref-block ref-block--post\" id=\"ref-post-1\">\n\t\t\t\t\t<a href=\"https:\/\/www.hongkiat.com\/blog\/guide-to-accelerated-mobile-pages-amp\/\" class=\"ref-block__link\" title=\"Read More: Beginner\u2019s Guide to Accelerated Mobile Pages (AMP)\" rel=\"bookmark\"><span class=\"screen-reader-text\">Beginner\u2019s Guide to Accelerated Mobile Pages (AMP)<\/span><\/a>\n<div class=\"ref-block__thumbnail img-thumb img-thumb--jumbo\" data-img='{ \"src\" : \"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/guide-to-accelerated-mobile-pages-amp.jpg\" }'>\n\t\t\t\t\t\t\t<noscript>\n<style>.no-js #ref-block-post-27675 .ref-block__thumbnail { background-image: url(\"https:\/\/assets.hongkiat.com\/uploads\/thumbs\/250x160\/guide-to-accelerated-mobile-pages-amp.jpg\"); }<\/style>\n<\/noscript>\n\t\t\t\t\t\t<\/div>\n<div class=\"ref-block__summary\">\n<h4 class=\"ref-title\">Beginner\u2019s Guide to Accelerated Mobile Pages (AMP)<\/h4>\n<p class=\"ref-description\">\n\t\t\t\t\t\tAccelerated Mobile Pages is Google's initiative that intends to solve the biggest problem of the mobile web \u2013...\t\t\t\t\t\t<span>Read more<\/span><\/p>\n<\/div>\n<\/div>\n<h2><a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/developing.md#amp-html-built-in-components\" target=\"_blank\" rel=\"noopener noreferrer\">Built-In AMP Components<\/a><\/h2>\n<p><strong>Built-ins<\/strong> are built in to AMP\u2019s JavaScript runtime, so you don\u2019t have to separately include them.<\/p>\n<h3>1. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/builtins\/amp-img.md\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><code>amp-img<\/code><\/a><\/h3>\n<p><code>&lt;amp-img&gt;<\/code><strong>replaces the <code>&lt;img&gt;<\/code> tag<\/strong> in AMP HTML documents. You need to add the <code>src<\/code> and <code>alt<\/code> attributes just like when you work with the regular <code>&lt;img&gt;<\/code> element.<\/p>\n<p><code>&lt;amp-img&gt;<\/code> also has two other required attributes: you always need to <strong>specify the <code>width<\/code> and <code>height<\/code> attributes<\/strong> in integer pixel values, as this allows the AMP runtime to <strong>calculate the layout in advance<\/strong>.<\/p>\n<p>If you want to <strong>make the image responsive<\/strong>, add the <code>layout=\"responsive\"<\/code> attribute. The <a href=\"https:\/\/amp.dev\/documentation\/guides-and-tutorials\/develop\/style_and_layout\/control_layout\/?referrer=ampproject.org\" target=\"_blank\" rel=\"noopener noreferrer\"><code>layout<\/code><\/a> attribute <strong>controls the layout<\/strong> in AMP documents, and it can be added to any AMP Components (learn more about this on the <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/spec\/amp-html-format.md\" target=\"_blank\" rel=\"noopener noreferrer\">AMP Layout System<\/a>).<\/p>\n<pre>\r\n&lt;amp-img src=\"img.jpg\" width=\"350\" height=\"200\"\r\n    layout=\"responsive\" alt=\"My Image\"&gt;\r\n&lt;\/amp-img&gt;\r\n<\/pre>\n<p>You can also use the <code>srcset<\/code> attribute on the <code>&lt;amp-img&gt;<\/code> tag to <strong>specify different images<\/strong> for different viewports and pixel densities. It <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/img#Example_3_Using_the_srcset_attribute\" target=\"_blank\" rel=\"noopener noreferrer\">works the same way<\/a> as with non-AMP images.<\/p>\n<h3>2. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/builtins\/amp-video.md\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><code>amp-video<\/code><\/a><\/h3>\n<p><code>&lt;amp-video&gt;<\/code> can be used to <strong>directly embed HTML videos<\/strong> in AMP HTML documents. It replaces the <code>&lt;video&gt;<\/code> in AMP files. The <code>&lt;amp-video&gt;<\/code> tag <strong>lazy loads videos<\/strong> in order to optimize performance.<\/p>\n<p>The source of the video <strong>must be served via the HTTPS protocol<\/strong>. You\u2019re required to add the <code>width<\/code> and <code>height<\/code> attributes, just like with the <code>&lt;amp-img&gt;<\/code> component.<\/p>\n<p>The <code>&lt;amp-video&gt;<\/code> tag has many <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/builtins\/amp-video.md#attributes\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">optional attributes<\/a>, such as <code>autoplay<\/code> and <code>poster<\/code> which you can specify to fine-tune how your HTML5 video is displayed.<\/p>\n<p><code>&lt;amp-video&gt;<\/code> supports mp4, webm, ogg, and all the other formats <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Supported_media_formats\" target=\"_blank\" rel=\"noopener noreferrer\">supported by the HTML5 &lt;video&gt; tag<\/a>.<\/p>\n<p>If you want, you can also <strong>add fallback videos<\/strong> for users with browsers that don\u2019t support HTML5 videos, using the <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/spec\/amp-html-format.md#fallback\" target=\"_blank\" rel=\"noopener noreferrer\"><code>fallback<\/code><\/a> attribute and the <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/HTML\/Element\/source\" target=\"_blank\" rel=\"noopener noreferrer\"><code>&lt;source&gt;<\/code><\/a> HTML tag.<\/p>\n<pre>\r\n&lt;amp-video width=\"350\" height=\"250\"\r\n  src=\"https:\/\/example.com\/video.mp4\" layout=\"responsive\" autoplay&gt;\r\n  &lt;div fallback&gt;\r\n    &lt;p&gt;Your browser doesn't support HTML5 videos.&lt;\/p&gt;\r\n  &lt;\/div&gt;\r\n  &lt;source type=\"video\/mp4\" src=\"myvideo.mp4\"&gt;\r\n  &lt;source type=\"video\/webm\" src=\"myvideo.webm\"&gt;\r\n&lt;\/amp-video&gt;\r\n<\/pre>\n<h3>3. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-ad\/amp-ad.md\" target=\"_blank\" rel=\"noopener noreferrer\"><code>amp-ad<\/code><\/a> and <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/builtins\/amp-embed.md\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><code>amp-embed<\/code><\/a><\/h3>\n<p><code>&lt;amp-ad&gt;<\/code> provides you with <strong>iframe sandboxes<\/strong> in which you can <strong>display your ads<\/strong>. You must serve your ads <strong>via the HTTPS protocol<\/strong>.<\/p>\n<p>You cannot run scripts supplied by your ad network by yourself. Instead, the AMP runtime executes the JavaScript of the given network inside the sandbox. You <strong>only need to specify which network you use<\/strong>, and add your data.<\/p>\n<p>The <code>&lt;amp-ad&gt;<\/code> component requires you to <strong>add the dimensions of the ad<\/strong> using the <code>width<\/code> and <code>height<\/code> attributes.<\/p>\n<p>You can define the ad network you use with the <code>type<\/code> attribute. See the <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-ad\/amp-ad.md#supported-ad-networks\" target=\"_blank\" rel=\"noopener noreferrer\">list of supported ad networks<\/a>.<\/p>\n<p>Each ad network has its own <a href=\"https:\/\/www.hongkiat.com\/blog\/better-ux-html-data-attributes\/\"><code>data-*<\/code> attributes<\/a> you also need to add. To see which one you need, click on your ad network in the above list.<\/p>\n<pre>\r\n&lt;amp-ad width=\"300\" height=\"250\"\r\n    layout=\"responsive\" type=\"adsense\"\r\n    data-ad-client=\"ca-pub-2005682797531342\"\r\n    data-ad-slot=\"7046626912\"&gt;\r\n&lt;\/amp-ad&gt;\r\n<\/pre>\n<p><a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/builtins\/amp-embed.md\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><code>&lt;amp-embed&gt;<\/code><\/a> is the alias of <code>&lt;amp-ad&gt;<\/code>, the documentation doesn\u2019t say much about it other than it can be used instead of <code>&lt;amp-ad&gt;<\/code> when it\u2019s <q>semantically more accurate<\/q>. As Google promises to evolve ad-related AMP components over time, this may change in the future.<\/p>\n<h3>4. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/builtins\/amp-pixel.md\" target=\"_blank\" rel=\"noopener noreferrer nofollow\"><code>amp-pixel<\/code><\/a><\/h3>\n<p>With <code>&lt;amp-pixel&gt;<\/code>, you can <strong>add a <a href=\"http:\/\/digitalmarketing-glossary.com\/What-is-Pixel-tracking-definition\" target=\"_blank\" rel=\"noopener noreferrer\">tracking pixel<\/a><\/strong> to your AMP HTML documents to <strong>count page views<\/strong>. It has only one attribute, the required <code>src<\/code> attribute, in which you need to <strong>specify the URL belonging to the tracking pixel<\/strong>.<\/p>\n<p>The <code>&lt;amp-pixel&gt;<\/code> tag allows <strong>standard URL substitutions<\/strong>, which means you can <strong>generate a random URL value<\/strong> to track each impression.<\/p>\n<p>See AMP\u2019s <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/spec\/amp-var-substitutions.md\" target=\"_blank\" rel=\"noopener noreferrer\">URL Substitution Guide<\/a> if you want to use this component. Note that you cannot style the <code>&lt;amp-pixel&gt;<\/code> component.<\/p>\n<pre>\r\n&lt;amp-pixel src=\"https:\/\/example.com\/pixel?RANDOM\"&gt;&lt;\/amp-pixel&gt;\r\n<\/pre>\n<h2><a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/spec\/amp-html-components.md#extended-components\" target=\"_blank\" rel=\"noopener noreferrer\">Extended AMP Components<\/a><\/h2>\n<p>As extended AMP components <strong>aren\u2019t part of the JavaScript runtime<\/strong>, you <strong>always need to import them<\/strong> in the <code>&lt;head&gt;<\/code> section of the AMP page on which you want to use them.<\/p>\n<p>Note: component versions may change in the future, so don\u2019t forget to <strong>check the current version<\/strong> in the documentation.<\/p>\n<h3>5. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-audio\/amp-audio.md\" target=\"_blank\" rel=\"noopener noreferrer\"><code>amp-audio<\/code><\/a><\/h3>\n<p><code>&lt;amp-audio&gt;<\/code> replaces the <code>&lt;audio&gt;<\/code> HTML5 tag, and makes it possible to <strong>directly embed HTML5 audio files<\/strong> in AMP pages.<\/p>\n<p>To use it, you\u2019re required to specify the <code>src<\/code>, <code>width<\/code> and <code>height<\/code> attributes, and you can also add <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-audio\/amp-audio.md#attributes\" target=\"_blank\" rel=\"noopener noreferrer\">three optional attributes<\/a>: <code>autoplay<\/code>, <code>loop<\/code> and <code>muted<\/code>.<\/p>\n<p>It can also be a good idea to <strong>add fallback audio files<\/strong> for users with browsers that don\u2019t support HTML5. You can do this by using the <code>fallback<\/code> attribute and the <code>&lt;source&gt;<\/code> tag, just like with the aforementioned <code>&lt;amp-video&gt;<\/code> component.<\/p>\n<p>The <code>&lt;amp-audio&gt;<\/code> AMP component supports the <a href=\"https:\/\/www.w3schools.com\/html\/html5_audio.asp\" target=\"_blank\" rel=\"noopener noreferrer\">same audio formats<\/a> as the <code>&lt;audio&gt;<\/code> HTML5 tag.<\/p>\n<pre>\r\n&lt;amp-audio width=\"200\" height=\"100\"\r\n  src=\"https:\/\/example.com\/audio.mp3\"&gt;\r\n  &lt;div fallback&gt;\r\n    &lt;p&gt;Your browser doesn't support HTML5 audio.&lt;\/p&gt;\r\n  &lt;\/div&gt;\r\n  &lt;source type=\"audio\/mpeg\" src=\"mysong.mp3\"&gt;\r\n  &lt;source type=\"audio\/ogg\" src=\"mysong.ogg\"&gt;\r\n&lt;\/amp-audio&gt;\r\n<\/pre>\n<p>To use <code>&lt;amp-audio&gt;<\/code>, include the following script in the <code>&lt;head&gt;<\/code> section of your AMP document:<\/p>\n<pre>\r\n&lt;script async custom-element=\"amp-audio\"\r\n    src=\"https:\/\/cdn.ampproject.org\/v0\/amp-audio-0.1.js\"&gt;\r\n&lt;\/script&gt;\r\n<\/pre>\n<h3>6. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-iframe\/amp-iframe.md\" target=\"_blank\" rel=\"noopener noreferrer\"><code>amp-iframe<\/code><\/a><\/h3>\n<p><code>&lt;amp-iframe&gt;<\/code> <strong>displays an iframe<\/strong> in AMP documents. <code>&lt;amp-iframe&gt;<\/code> has been made to be more secure than regular HTML iframes. Therefore they are <strong><a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-iframe\/amp-iframe.md#sandbox\" target=\"_blank\" rel=\"noopener noreferrer\">sandboxed by default<\/a><\/strong>.<\/p>\n<p>There are <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-iframe\/amp-iframe.md#behavior\" target=\"_blank\" rel=\"noopener noreferrer\">some rules related to <code>&lt;amp-iframe&gt;<\/code><\/a> you must follow to pass validation.<\/p>\n<p class=\"recommended_top\">\n\t\t\t\t\t<strong>Read Also:<\/strong>\u00a0\n\t\t\t\t\t<a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/amp-page-validation\/\">How to Validate Accelerated Mobile Pages (AMP)<\/a>\n\t\t\t\t<\/p>\n<p>You must specify the <code>width<\/code>, <code>height<\/code>, and <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-iframe\/amp-iframe.md#sandbox\" target=\"_blank\" rel=\"noopener noreferrer\"><code>sandbox<\/code><\/a> attributes. The <code>sandbox<\/code> attribute is empty by default, but you can give it different values in order to <strong>modify the behaviour of the iframe<\/strong>, for instance<code>sandbox=\"allow-scripts\"<\/code>lets the iframe run JavaScript. You can use <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-iframe\/amp-iframe.md#src-srcdoc-frameborder-allowfullscreen-allowtransparency-referrerpolicy\" target=\"_blank\" rel=\"noopener noreferrer\">attributes of standard iframes<\/a> as well.<\/p>\n<pre>\r\n&lt;amp-iframe width=\"350\" height=\"250\"\r\n     layout=\"responsive\"\r\n     sandbox=\"allow-scripts allow-same-origin\"\r\n     allowfullscreen\r\n     src=\"https:\/\/example.com\/iframe\"&gt;\r\n &lt;\/amp-iframe&gt;\r\n<\/pre>\n<p>While the dimensions of <code>&lt;amp-iframe&gt;<\/code> are predefined by the <code>width<\/code> and <code>height<\/code> attributes, there\u2019s a way to <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-iframe\/amp-iframe.md#iframe-resizing\" target=\"_blank\" rel=\"noopener noreferrer\">resize it in runtime<\/a>. To use the <code>&lt;amp-iframe&gt;<\/code> component, add the following script to your AMP page:<\/p>\n<pre>\r\n&lt;script async custom-element=\"amp-iframe\"\r\n    src=\"https:\/\/cdn.ampproject.org\/v0\/amp-iframe-0.1.js\"&gt;\r\n&lt;\/script&gt;\r\n<\/pre>\n<h3>7. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-accordion\/amp-accordion.md\" target=\"_blank\" rel=\"noopener noreferrer\"><code>amp-accordion<\/code><\/a><\/h3>\n<p><strong>Accordions<\/strong> constitute a frequent UI pattern in mobile design, as they save space, but still displays the content in an accessible way. <code>&lt;amp-accordion&gt;<\/code> makes it possible to <strong>quickly add accordions<\/strong> to AMP pages.<\/p>\n<p>Sections of the accordion must use the <code>&lt;section&gt;<\/code> HTML5 tag, and need to be the <strong>direct children<\/strong> of the <code>&lt;amp-accordion&gt;<\/code> tag.<\/p>\n<p>Each section <strong>must have two direct children<\/strong>:<\/p>\n<ol>\n<li>one for the heading<\/li>\n<li>one for the content (the content can also be an image)<\/li>\n<\/ol>\n<p>Use the <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-accordion\/amp-accordion.md#attributes\" target=\"_blank\" rel=\"noopener noreferrer\"><code>expanded<\/code><\/a> attribute on any section you want to expand by default.<\/p>\n<pre>\r\n&lt;amp-accordion&gt;\r\n  &lt;section expanded&gt;\r\n    &lt;h3&gt;Section 1&lt;\/h3&gt;\r\n    &lt;div&gt;Content of Section 1&lt;\/div&gt;\r\n  &lt;\/section&gt;\r\n  &lt;section&gt;\r\n    &lt;h3&gt;Section 2&lt;\/h3&gt;\r\n    &lt;p&gt;Content of Section 2&lt;\/p&gt;\r\n  &lt;\/section&gt;\r\n  &lt;section&gt;\r\n    &lt;h3&gt;Section 3&lt;\/h3&gt;\r\n    &lt;figure&gt;\r\n      &lt;amp-img src=\"image.jpg\" width=\"350\" height=\"200\"\r\n          layout=\"responsive\" alt=\"Image for Section 3\"&gt;\r\n      &lt;\/amp-img&gt;\r\n      &lt;figcaption&gt;Image for Section 3&lt;\/figcaption&gt;\r\n    &lt;\/figure&gt;\r\n  &lt;\/section&gt;\r\n&lt;\/amp-accordion&gt;\r\n<\/pre>\n<p>To use the <code>&lt;amp-accordion&gt;<\/code> component in your AMP document, include the following script:<\/p>\n<pre>\r\n&lt;script async custom-element=\"amp-accordion\"\r\n    src=\"https:\/\/cdn.ampproject.org\/v0\/amp-accordion-0.1.js\"&gt;\r\n&lt;\/script&gt;\r\n<\/pre>\n<h3>8. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-lightbox\/amp-lightbox.md\" target=\"_blank\" rel=\"noopener noreferrer\"><code>amp-lightbox<\/code><\/a><\/h3>\n<p><code>&lt;amp-lightbox&gt;<\/code> <strong>adds a lightbox<\/strong> to different elements (in most cases, images) on Accelerated Mobile Pages.<\/p>\n<p>When the user interacts with the element, for example taps on it, the lightbox <strong>expands and fills the whole viewport<\/strong>. You need to <strong>add a button or another control<\/strong> which the user can tap on.<\/p>\n<p>Note that <code>amp-lightbox<\/code> can only be used with the <code>nodisplay<\/code> layout.<\/p>\n<pre>\r\n&lt;button on=\"tap:mylightbox\" role=\"button\" tabindex=\"0\"&gt;\r\n  Expand\r\n&lt;\/button&gt;\r\n\r\n&lt;amp-lightbox id=\"mylightbox\" layout=\"nodisplay\"&gt;\r\n  &lt;div class=\"lightbox\" on=\"tap:mylightbox.close\"\r\n      role=\"button\" tabindex=\"0\"&gt;\r\n      &lt;amp-img src=\"full-image.jpg\" width=\"375\" height=\"667\"\r\n      on=\"tap:my-lightbox.close\"&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/amp-lightbox&gt;\r\n<\/pre>\n<p>To use the <code>&lt;amp-lightbox&gt;<\/code> component, you need to import it with the following code:<\/p>\n<pre>\r\n&lt;script async custom-element=\"amp-lightbox\"\r\n    src=\"https:\/\/cdn.ampproject.org\/v0\/amp-lightbox-0.1.js\"&gt;\r\n&lt;\/script&gt;\r\n<\/pre>\n<h3>9. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-carousel\/amp-carousel.md\" target=\"_blank\" rel=\"noopener noreferrer\"><code>amp-carousel<\/code><\/a><\/h3>\n<p>Carousels are frequently used in mobile design, as they allow to <strong>display numerous similar elements<\/strong> (most frequently images) along the horizontal axis. AMP results are also presented in a carousel format in Google Search.<\/p>\n<p>The <code>&lt;amp-carousel&gt;<\/code> component enables you to add carousels to your site. The <strong>direct children<\/strong> of the <code>&lt;amp-carousel&gt;<\/code> component will be regarded as the <strong>items of the carousel<\/strong>. You must define the dimensions of the carousel with the <code>width<\/code> and <code>height<\/code> attributes.<\/p>\n<p>You can use the optional <code>type<\/code> attribute to determine <strong>how to display the carousel items<\/strong>. If the <code>type<\/code> attribute takes the <code>\"carousel\"<\/code> value, the items will be shown <strong>as a continuous strip<\/strong> (this is the default), while the <code>\"slides\"<\/code> value will display the items <strong>in slides format<\/strong>.<\/p>\n<p>The <code>&lt;amp-carousel&gt;<\/code> tag also has <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-carousel\/amp-carousel.md#attributes\" target=\"_blank\" rel=\"noopener noreferrer\">other optional attributes<\/a> that can help you fine-tune the result.<\/p>\n<p>In the example below, notice that both the carousel and all of its items <strong>use the same <code>width<\/code> and <code>height<\/code> values<\/strong>.<\/p>\n<pre>\r\n&lt;amp-carousel width=\"300\" height=\"400\" layout=\"responsive\"\r\n  type=\"slides\"&gt;\r\n  &lt;amp-img src=\"image1.jpg\" width=\"300\" height=\"400\"&gt;&lt;\/amp-img&gt;\r\n  &lt;amp-img src=\"image2.jpg\" width=\"300\" height=\"400\"&gt;&lt;\/amp-img&gt;\r\n  &lt;amp-img src=\"image3.jpg\" width=\"300\" height=\"400\"&gt;&lt;\/amp-img&gt;\r\n&lt;\/amp-carousel&gt;\r\n<\/pre>\n<p>The <code>&lt;amp-carousel&gt;<\/code> component requires the addition of the following script:<\/p>\n<pre>\r\n&lt;script async custom-element=\"amp-carousel\"\r\n    src=\"https:\/\/cdn.ampproject.org\/v0\/amp-carousel-0.1.js\"&gt;\r\n&lt;\/script&gt;\r\n<\/pre>\n<h3>10. <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-analytics\/amp-analytics.md\" target=\"_blank\" rel=\"noopener noreferrer\"><code>amp-analytics<\/code><\/a><\/h3>\n<p><code>&lt;amp-analytics&gt;<\/code> can be used to <strong>collect analytics data<\/strong> on AMP pages. Currently, <code>&lt;amp-analytics&gt;<\/code> <strong>supports four types of tracking events<\/strong>, however this can change in the future:<\/p>\n<ol>\n<li>Pageview<\/li>\n<li>Anchor Clicks<\/li>\n<li>Timer<\/li>\n<li>Scrolling<\/li>\n<\/ol>\n<p>To use <code>&lt;amp-analytics&gt;<\/code>, you need to <strong>add a JSON configuration object<\/strong> inside a <code>&lt;script&gt;<\/code> tag, in which you can configure what you want to track.<\/p>\n<p>Luckily, Google teamed up with many analytics vendors who <strong>provide pre-configured JSON scripts<\/strong> you only need to copy-paste into your site. See the <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-analytics\/amp-analytics.md#analytics-vendors\" target=\"_blank\" rel=\"noopener noreferrer\">list of available analytics vendors<\/a>.<\/p>\n<p>To use the pre-configured scripts, you need to <strong>add the name of the analytics vendor<\/strong> in the <code>type<\/code> attribute.<\/p>\n<p>The <code>&lt;amp-analytics&gt;<\/code> tag also has some <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/extensions\/amp-analytics\/amp-analytics.md#attributes\" target=\"_blank\" rel=\"noopener noreferrer\">optional attributes<\/a> you can use to further configure how you track your site.<\/p>\n<pre>\r\n&lt;amp-analytics&gt;\r\n  &lt;script type=\"application\/json\"&gt;\r\n  {\r\n    \/\/ ...\r\n  }\r\n  &lt;\/script&gt;\r\n&lt;\/amp-analytics&gt;\r\n<\/pre>\n<p>Add the following script to the <code>&lt;head&gt;<\/code> section of your AMP HTML page to import the <code>&lt;amp-analytics&gt;<\/code> component:<\/p>\n<pre>\r\n&lt;script async custom-element=\"amp-analytics\"\r\n    src=\"https:\/\/cdn.ampproject.org\/v0\/amp-analytics-0.1.js\"&gt;\r\n&lt;\/script&gt;\r\n<\/pre>\n<h2>Final Words<\/h2>\n<p>In this post, we had a look at all built-in AMP components, and some of the extended ones. As Accelerated Mobile Pages is still new, many things can change in the future, so it\u2019s worth to keep an eye on the documentation either <a href=\"https:\/\/github.com\/ampproject\/amphtml\" target=\"_blank\" rel=\"noopener noreferrer\">on Github<\/a> or on the <a href=\"https:\/\/amp.dev\/documentation\/components\/?referrer=ampproject.org\" target=\"_blank\" rel=\"noopener noreferrer\">official AMP site<\/a>.<\/p>\n<p>As these AMP components are open source, you can also <a href=\"https:\/\/github.com\/ampproject\/amphtml\/blob\/main\/docs\/spec\/amp-html-components.md#contributing-components\" target=\"_blank\" rel=\"noopener noreferrer\">contribute to the development<\/a>, even <strong>creating your own component<\/strong>. If you want to see how a complete AMP page looks like with different components, you can check out <a href=\"https:\/\/github.com\/ampproject\/amphtml\/tree\/main\/examples\" target=\"_blank\" rel=\"noopener noreferrer\">these few examples<\/a> on Github.<\/p>","protected":false},"excerpt":{"rendered":"<p>Accelerated Mobile Pages or AMP is Google\u2019s initiative to make the mobile web faster. To achieve this goal, the AMP standards restrict how you can use HTML, CSS, and JavaScript, and manages the loading of external resources, such as images, videos, and ads via its own runtime. This entails that you cannot use either any&hellip;<\/p>\n","protected":false},"author":146,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3399],"tags":[3882],"topic":[4521],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Top 10 Essential AMP Components for Mobile Optimization - Hongkiat<\/title>\n<meta name=\"description\" content=\"Accelerated Mobile Pages or AMP is Google&#039;s initiative to make the mobile web faster. To achieve this goal, the AMP standards restrict how you can use\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Top 10 Essential AMP Components for Mobile Optimization\" \/>\n<meta property=\"og:description\" content=\"Accelerated Mobile Pages or AMP is Google&#039;s initiative to make the mobile web faster. To achieve this goal, the AMP standards restrict how you can use\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2016-08-22T15:01:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-03T18:48:45+00:00\" \/>\n<meta name=\"author\" content=\"Anna Monus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anna Monus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/\"},\"author\":{\"name\":\"Anna Monus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/a601053a0ab457901e00cdc83bd5359e\"},\"headline\":\"Top 10 Essential AMP Components for Mobile Optimization\",\"datePublished\":\"2016-08-22T15:01:44+00:00\",\"dateModified\":\"2025-04-03T18:48:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/\"},\"wordCount\":1476,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"Accelerated Mobile Pages\"],\"articleSection\":[\"Mobile\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/\",\"name\":\"Top 10 Essential AMP Components for Mobile Optimization - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2016-08-22T15:01:44+00:00\",\"dateModified\":\"2025-04-03T18:48:45+00:00\",\"description\":\"Accelerated Mobile Pages or AMP is Google's initiative to make the mobile web faster. To achieve this goal, the AMP standards restrict how you can use\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/important-amp-components\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Top 10 Essential AMP Components for Mobile Optimization\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/a601053a0ab457901e00cdc83bd5359e\",\"name\":\"Anna Monus\",\"description\":\"Anna is Technical Editor and Writer for Hongkiat.com. She mainly covers front-end frameworks, web standards, accessibility, WordPress development, and UX design.\",\"sameAs\":[\"https:\\\/\\\/www.annalytic.com\\\/\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/anna_monus\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Top 10 Essential AMP Components for Mobile Optimization - Hongkiat","description":"Accelerated Mobile Pages or AMP is Google's initiative to make the mobile web faster. To achieve this goal, the AMP standards restrict how you can use","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/","og_locale":"en_US","og_type":"article","og_title":"Top 10 Essential AMP Components for Mobile Optimization","og_description":"Accelerated Mobile Pages or AMP is Google's initiative to make the mobile web faster. To achieve this goal, the AMP standards restrict how you can use","og_url":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2016-08-22T15:01:44+00:00","article_modified_time":"2025-04-03T18:48:45+00:00","author":"Anna Monus","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Anna Monus","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/"},"author":{"name":"Anna Monus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/a601053a0ab457901e00cdc83bd5359e"},"headline":"Top 10 Essential AMP Components for Mobile Optimization","datePublished":"2016-08-22T15:01:44+00:00","dateModified":"2025-04-03T18:48:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/"},"wordCount":1476,"commentCount":6,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["Accelerated Mobile Pages"],"articleSection":["Mobile"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/important-amp-components\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/","url":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/","name":"Top 10 Essential AMP Components for Mobile Optimization - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2016-08-22T15:01:44+00:00","dateModified":"2025-04-03T18:48:45+00:00","description":"Accelerated Mobile Pages or AMP is Google's initiative to make the mobile web faster. To achieve this goal, the AMP standards restrict how you can use","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/important-amp-components\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/important-amp-components\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Top 10 Essential AMP Components for Mobile Optimization"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/a601053a0ab457901e00cdc83bd5359e","name":"Anna Monus","description":"Anna is Technical Editor and Writer for Hongkiat.com. She mainly covers front-end frameworks, web standards, accessibility, WordPress development, and UX design.","sameAs":["https:\/\/www.annalytic.com\/"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/anna_monus\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-7ec","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/27788","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/146"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=27788"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/27788\/revisions"}],"predecessor-version":[{"id":73731,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/27788\/revisions\/73731"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=27788"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=27788"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=27788"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=27788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}