AMP HTML Cheat Sheet
AMP HTML Cheat Sheet
Hello World 👶
<!doctype html>
Important ‼ <html amp lang="en">
<head>
<meta charset="utf-8">
Define AMP page location on Desktop site <script async src="https://cdn.ampproject.org/
<link rel="amphtml" <title>Hello World!</title>
href="https://htmlcheatsheet.com/m/"> <link rel="canonical" href="https://htmlcheats
<meta name="viewport" content="width=device-wi
Link back to Desktop from AMP <script type="application/ld+json">
<link rel="canonical" {
href="https://htmlcheatsheet.com/"> "@context": "http://schema.org",
"@type": "NewsArticle",
Image tag "headline": "Hello World",
<amp-img src="/m/cheatsheet.jpg" alt="Cheat "datePublished": "2018-08-08T12:02:41Z",
Sheet" layout="responsive" height="200" "image": [
width="300"></amp-img> "logo.jpg"
]
Keep in mind! }
</script>
Don't use !important CSS
<style amp-boilerplate>body{-webkit-animation
https:// highly recommended
<style amp-custom>
No custom .JS files
Only 50Kb inline style allowed in <style amp- p {
custom> </style> margin: 1em;
}
Common attributes </style>
</head>
fallback, heights, layout, media, noloading, on, placeholder,
sizes, width and height <body>
<h1>Hello World</h1>
Useful Links 🔗
</body>
</html>
Simple AMP Template
Quick overview Validator
Structured data testing tool
Project Home Page Simple template Images 🖼
AMP for WordPress plugin Examples
Templates Basic syntax
<amp-img src="/m/cheatsheet.jpg" alt="Cheat
Sheet" height="200" width="300"></amp-img>
Video 📼 Responsiveness
<amp-img
Include src="/narrow.jpg"
srcset="/wide.jpg 640w,
<script async custom-element="amp-video" /narrow.jpg 320w"
src="https://cdn.ampproject.org/v0/amp-video- width="1200"
0.1.js"></script> height="800"
layout="responsive"
Example
alt="demo image">
<amp-video controls </amp-img>
width="600"
height="400" Layout types
layout="responsive"
poster="geekprank.png"> nodisplay – works like display: none style.
<source src="geekprank.webm" fixed – fixed width & height
type="video/webm" /> responsive – fills container automatically to aspec
<source src="geekprank.mp4" ratio
type="video/mp4" /> fixed-height – keeps the specified height unchang
<div fallback> fill – fills available height & width
<p>Video element not supported.</p> container – lets its children define its size, like a
</div> normal div
</amp-video> flex-item – works like display:flex style
intrinsic – responsive until it reaches its height and
Attributes width
src, poster, autoplay, controls, controlsList, loop, crossorigin, CSS media queries
disableremoteplayback, noaudio, rotate-to-fullscreen
@media screen and (max-width: 720px) {
artwork, artist, album, title p { font-size: 0.9em; }
}
Youtube Video
Element media queries:
<script async custom-element="amp-youtube"
<amp-img
src="https://cdn.ampproject.org/v0/amp-youtube-
media="(min-width: 720px)"
0.1.js"></script>
src="demo.jpg"
<amp-youtube width=300
data-videoid="VeeFwwAz7no" height=200
layout="responsive" layout="responsive">
width="480" height="270"></amp-youtube> </amp-img>
Actions, events 🤹
Placeholder
Shows a placeholder while the element is being loaded:
amp-bind
AdSense 💰
<script async custom-element="amp-bind"
src="https://cdn.ampproject.org/v0/amp-bind- Include
0.1.js"></script>
Button changes 'World' to 'John': <script async custom-element="amp-auto-ads"
<p [text]="'Hello ' + str">Hello World</p> src="https://cdn.ampproject.org/v0/amp-auto-ad
<button on="tap:AMP.setState({str: 'John'})"> 0.1.js"></script>
HTML Cheat Sheet is using cookies to collect anonymous visitor statistics and to show better ads. | Terms and Conditions, Privacy Policy
© HTMLCheatSheet.com