Htmlcheatsheet Com Amp
Htmlcheatsheet Com Amp
Important ‼ ? ↖ x
Image tag
<amp‐img src="/m/cheatsheet.jpg" alt="Cheat Sheet" layout="responsive" height="200"
width="300"></amp‐img>
Keep in mind!
Common attributes
fallback, heights, layout, media, noloading, on, placeholder, sizes, width and height
Ads ? ↖ x
Useful Links ὑ ? ↖ x
Images Ὓ ? ↖ x
Basic syntax
<amp‐img src="/m/cheatsheet.jpg" alt="Cheat Sheet" height="200" width="300"></amp‐img>
Responsiveness
<amp‐img
src="/narrow.jpg"
srcset="/wide.jpg 640w,
/narrow.jpg 320w"
width="1200"
height="800"
layout="responsive"
alt="demo image">
</amp‐img>
Layout types
Placeholder
Shows a placeholder while the element is being loaded:
<amp‐anim src="animation.gif"
layout="responsive"
width="300"
height="200">
<amp‐img placeholder
src="demo.jpg"
layout="fill">
</amp‐img>
</amp‐anim>
Fallback
When an element is not supported:
<amp‐img alt="Demo"
width="300"
height="200"
layout="responsive"
src="videofile.webp">
<amp‐img alt="Demo"
fallback
width="300"
height="200"
layout="responsive"
src="image.jpg"></amp‐img>
</amp‐img>
Include
<script async custom‐element="amp‐video" src="https://cdn.ampproject.org/v0/amp‐video‐0.1.js">
</script>
Example
<amp‐video controls
width="600"
height="400"
layout="responsive"
poster="geekprank.png">
<source src="geekprank.webm"
type="video/webm" />
<source src="geekprank.mp4"
type="video/mp4" />
<div fallback>
<p>Video element not supported.</p>
</div>
</amp‐video>
Attributes
src, poster, autoplay, controls, controlsList, loop, crossorigin, disableremoteplayback, noaudio, rotatetofullscreen
Youtube Video
<script async custom‐element="amp‐youtube" src="https://cdn.ampproject.org/v0/amp‐youtube‐
0.1.js"></script>
<amp‐youtube
data‐videoid="VeeFwwAz7no"
layout="responsive"
width="480" height="270"></amp‐youtube>
Actions, events ᾓ ? ↖ x
Syntax
eventName:targetId[.methodName[(arg1=value, arg2=value)]]
Example
on="submit‐success:lightbox1;submit‐error:lightbox2"
<div id="cookie‐consent">The site is using Cookies!</div>
<button on="tap:cookie‐consent.hide">OK, I understand!</button>
Events
ampbind
<script async custom‐element="amp‐bind" src="https://cdn.ampproject.org/v0/amp‐bind‐0.1.js">
</script>
Button changes 'World' to 'John':
<p [text]="'Hello ' + str">Hello World</p>
<button on="tap:AMP.setState({str: 'John'})">
ampstate
Initialize state:
<amp‐state id="thisState">
<script type="application/json">
{
"foo": "bar"
}
</script>
</amp‐state>
thisState.foo == "bar"
Update state with AMP.setState()
<button on="tap:AMP.setState({foo: 'bar', baz: myAmpState.someVariable})"></button>
<input type="range" on="change:AMP.setState({myRangeValue: event.value})">
AMP.pushState
<button on="tap:AMP.pushState({foo: '123'})">Set 'foo' to 123</button>
Ads ? ↖ x
Google Analytics Ὄ ? ↖ x
Include
<script async custom‐element="amp‐analytics" src="https://cdn.ampproject.org/v0/amp‐analytics‐
0.1.js"></script>
AdSense Ὃ ? ↖ x
Include
<script async custom‐element="amp‐auto‐ads" src="https://cdn.ampproject.org/v0/amp‐auto‐ads‐
0.1.js"></script>
Include
<script async custom‐element="amp‐sidebar" src="https://cdn.ampproject.org/v0/amp‐sidebar‐
0.1.js"></script>
Custom CSS:
.sidebar {padding: 10px;margin: 0;color: #FFF;font‐weight:bold;}
#sidebar1{background: #CE5937;}
.sidebar > li {list‐style: none;margin‐bottom:10px;}
.sidebar a {text‐decoration: none;color: #FFF;}
.close‐sidebar {font‐size: 1.5em;padding: 5px 15px;cursor: pointer;color: #FFFFFF;}
.headerbar {background: #CE5937;color: #FFF;line‐height: 30px;position: fixed;top: 0;left:
0;right: 0;height: 40px;z‐index: 1000;}
.headerbar a {text‐decoration: none;color: #FFF;}
ampsidebar
<header class="headerbar">
<div role="button" on="tap:sidebar1.toggle" tabindex="0" class="hamburger">☰</div>
<a href="/" class="site‐name">MySite</a>
</header>
<amp‐sidebar id="sidebar1" layout="nodisplay" side="left">
<div role="button" aria‐label="close sidebar" on="tap:sidebar1.toggle" tabindex="0"
class="close‐sidebar">✕</div>
<ul class="sidebar">
<li><a href="https://htmlg.com/">Editor</a></li>
<li><a href="https://html5‐templates.com/">Templates</a></li>
<li><a href="https://htmlcheatsheet.com/">Cheat Sheet</a></li>
</ul>
</amp‐sidebar>
Facebook like ὄ ? ↖ x
Include
<script async custom‐element="amp‐facebook‐like" src="https://cdn.ampproject.org/v0/amp‐
facebook‐like‐0.1.js"></script>
Code
<amp‐facebook‐like width=90 height=20
layout="fixed"
data‐layout="button_count"
data‐href="https://www.facebook.com/htmlcoding/">
</amp‐facebook‐like>
Ads ? ↖ x
Facebook comments Ὂ ? ↖ x
Include
<script async custom‐element="amp‐facebook‐comments" src="https://cdn.ampproject.org/v0/amp‐
facebook‐comments‐0.1.js"></script>
Code
<amp‐facebook‐comments width="300"
height="350"
layout="responsive"
data‐numposts="5"
data‐colorscheme="dark"
data‐locale="es_ES"
data‐order‐by="time"
data‐href="https://htmlcheatsheet.com/">
</amp‐facebook‐comments>
iFrame Ὓ ? ↖ x
Include
<script async custom‐element="amp‐iframe" src="https://cdn.ampproject.org/v0/amp‐iframe‐
0.1.js"></script>
Include
<script async custom‐element="amp‐social‐share" src="https://cdn.ampproject.org/v0/amp‐social‐
share‐0.1.js"></script>
Code
<amp‐social‐share type="facebook" width="30" height="30"
data‐param‐text="HTML Cheat Sheet"
data‐param‐url="https://htmlcheatsheet.com">
</amp‐social‐share>
<amp‐social‐share type="twitter" width="30" height="30"
data‐param‐text="HTML Cheat Sheet"
data‐param‐url="https://htmlcheatsheet.com">
</amp‐social‐share>
<amp‐social‐share type="gplus" width="30" height="30"
data‐param‐text="HTML Cheat Sheet"
data‐param‐url="https://htmlcheatsheet.com">
</amp‐social‐share>
Accordion menu Ὗ ? ↖ x
Include
<script async custom‐element="amp‐accordion" src="https://cdn.ampproject.org/v0/amp‐accordion‐
0.1.js"></script>
Example
<amp‐accordion>
<section expanded>
<h4>Title 1</h4>
<p>Add any text.</p>
</section>
<section>
<h4>Title 2</h4>
<div>Add any <strong>HTML</strong> content.</div>
</section>
<section>
<h4>Title 3</h4>
<figure>
<amp‐img src="/demo.jpg"
width="400"
height="200"
layout="responsive"
alt="description"></amp‐img>
<figcaption>This is an image</figcaption>
</figure>
</section>
</amp‐accordion>
Carousel Ἲ ? ↖ x
Include
<script async custom‐element="amp‐carousel" src="https://cdn.ampproject.org/v0/amp‐carousel‐
0.1.js"></script>
Code
<amp‐carousel width="300"
height="200"
layout="responsive"
type="slides">
<amp‐img src="/img1.jpg"
width="300"
height="200"
layout="responsive"
alt="a demo image"></amp‐img>
<amp‐img src="/img2.jpg"
width="300"
height="200"
layout="responsive"
alt="another cool image"></amp‐img>
<amp‐img src="/img3.jpg"
width="300"
height="200"
layout="responsive"
alt="and the last one"></amp‐img>
</amp‐carousel>
HTML Preview
1
p
I have already written a short article reviewing and discussing the benefits of
why you should implement this technology in your online projects.
Make sure you save this link to help your next project.
HTML Cheat Sheet is using cookies to collect anonymous visitor statistics and to show better ads. | PDF | Terms and
Conditions, Privacy Policy
© HTMLCheatSheet.com