amp-social-share
Introduction
The amp-social-share component provides a common interface for share buttons, styled to complement each other.
Setup
Import the amp-social-share component in the header.
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
Ensure you've configured your canonical URL.
<link rel="canonical" href="https://amp.dev/documentation/examples/components/amp-social-share/index.html">
Styling
Custom styling for <amp-social-share>.
<style amp-custom>
:root {
--color-primary: #005AF0;
--color-text-light: #fff;
}
/* a custom sharing icon */
amp-social-share.custom-style {
background-color: #008080;
background-image: url('https://raw.githubusercontent.com/google/material-design-icons/master/social/1x_web/ic_share_white_48dp.png');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
/* blue icons with rounded corners */
amp-social-share.rounded {
border-radius: 50%;
background-size: 60%;
color: var(--color-text-light);
background-color: var(--color-primary);
}
</style>
Basic usage
Embed the amp-social-share widget choosing a share type from the supported types.
amp-social-share with type="facebook" requires to specify the facebook app id via data-attribution.
<amp-social-share type="email" aria-label="Share by email"></amp-social-share>
<amp-social-share type="facebook" aria-label="Share on Facebook" data-param-app_id="254325784911610"></amp-social-share>
<amp-social-share type="linkedin" aria-label="Share on LinkedIn"></amp-social-share>
<amp-social-share type="pinterest" aria-label="Share on Pinterest" data-param-media="https://amp.dev/static/samples/img/amp.jpg"></amp-social-share>
<amp-social-share type="tumblr" aria-label="Share on Tumblr"></amp-social-share>
<amp-social-share type="twitter" aria-label="Share on Twitter"></amp-social-share>
<amp-social-share type="whatsapp" aria-label="Share on WhatsApp"></amp-social-share>
<amp-social-share type="line" aria-label="Share on Line"></amp-social-share>
Configuration
Embed the amp-social-share widget choosing a type, then configure the actions.
width, default 60px.height, default 44px.data-param-textis the text to include in the share.data-param-urlis the URL to share, current URL by default.data-param-attributionis where the share is attributed to.
All