Share links
Social media links for linking to or sharing the current page on social media.
The component will not process a URL into a share link itself. Pass complete share URLs to the component.
Note that the component automatically appends visually hidden text to the link (default: Share on <your text> (opens in a new tab)
). Consider this when setting the link text.
Real world examples:
How it looks (preview) (preview all)
How to call this component
<%= render "govuk_publishing_components/components/share_links", {
links: [
{
href: "/facebook-share-link",
text: "Facebook",
icon: "facebook",
data_attributes: {
}
},
{
href: "/twitter-share-link",
text: "Twitter",
icon: "twitter",
data_attributes: {
}
}
]
} %>
Accessibility acceptance criteria
The share link icons must be presentational and ignored by screen readers.
Links in the component must:
- accept focus
- be focusable with a keyboard
- be usable with a keyboard
- indicate when they have focus
- change in appearance when touched (in the touch-down state)
- change in appearance when hovered
- be usable with touch
- be usable with voice commands
- have visible text
- have meaningful text
Other examples
Right to left (preview)
<%= render "govuk_publishing_components/components/share_links", {
links: [
{
href: "/facebook-share-link",
text: "Facebook",
icon: "facebook"
},
{
href: "/twitter-share-link",
text: "Twitter",
icon: "twitter"
}
]
} %>
With data attributes (preview)
Data attributes can be added to both the parent element and the individual share links, as shown. Note that the component defaults to having a data-module
of ga4-link-tracker
if tracking is enabled, but this is preserved even if another value for module is passed.
<%= render "govuk_publishing_components/components/share_links", {
data_attributes: {
module: "example-passed-module"
},
links: [
{
href: "/facebook-share-link",
text: "Facebook",
icon: "facebook",
data_attributes: {
meeting: "hello"
}
},
{
href: "/twitter-share-link",
text: "Twitter",
icon: "twitter",
data_attributes: {
departing: "goodbye"
}
}
]
} %>
With title (preview)
<%= render "govuk_publishing_components/components/share_links", {
title: "Share this page",
links: [
{
href: "share",
text: "Share on Facebook",
hidden_text: "",
icon: "facebook"
}
]
} %>
With branding (preview)
Organisation colour branding can be added to the component as shown.
<%= render "govuk_publishing_components/components/share_links", {
brand: "attorney-generals-office",
links: [
{
href: "share",
text: "Follow the Attorney General on Twitter",
hidden_text: "",
icon: "twitter"
}
]
} %>
Track as sharing links (preview)
In GA4, when this is set to true, a JSON is added to a data-attribute called data-ga4-link, which is detected by ga4-link-tracker.js and pushed to the dataLayer. Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_extra_data object.
<%= render "govuk_publishing_components/components/share_links", {
track_as_sharing: true,
ga4_extra_data: {
optional_extra_values: "go here"
},
links: [
{
href: "share",
text: "Share on Facebook",
icon: "facebook"
},
{
href: "share",
text: "Share on Twitter",
icon: "twitter"
}
]
} %>
Track as follow links (preview)
Where the component is used to allow users to follow us on social media, tracking can be added. When this is set to true, a JSON is added to a data-attribute called data-ga4-link, which is detected by ga4-link-tracker.js and pushed to the dataLayer. Most of the tracking values are added by default, but if you need to add more GA4 values or override defaults, you can pass a ga4_extra_data object.
<%= render "govuk_publishing_components/components/share_links", {
track_as_follow: true,
ga4_extra_data: {
optional_extra_values: "go here"
},
links: [
{
href: "follow",
text: "Follow us on Facebook",
hidden_text: "",
icon: "facebook"
},
{
href: "follow",
text: "Follow us on Twitter",
hidden_text: "",
icon: "twitter"
}
]
} %>
Stack vertically (preview)
<%= render "govuk_publishing_components/components/share_links", {
stacked: true,
links: [
{
href: "/facebook-share-link",
text: "Facebook",
icon: "facebook"
},
{
href: "/twitter-share-link",
text: "Twitter",
icon: "twitter"
}
]
} %>
Arrange in columns (preview)
Share links are arranged in even columns that adjust according to the available space. Note that the column width is based on an assumed width, so if the link text is long it may wrap (the example below demonstrates this).
This option uses CSS grid, which is not fully supported in IE <= 11, so in those browsers the columns are floated.
<%= render "govuk_publishing_components/components/share_links", {
columns: true,
links: [
{
href: "/facebook-share-link",
text: "Facebook",
icon: "facebook"
},
{
href: "/twitter-share-link",
text: "Twitter",
icon: "twitter"
},
{
href: "/email-share-link",
text: "Email",
icon: "email"
},
{
href: "/flickr-share-link",
text: "Flickr",
icon: "flickr"
},
{
href: "/instagram-share-link",
text: "Instagram",
icon: "instagram"
},
{
href: "/linkedin-share-link",
text: "Linkedin",
icon: "linkedin"
}
]
} %>
With all icons (preview)
<%= render "govuk_publishing_components/components/share_links", {
stacked: true,
brand: "hm-treasury",
links: [
{
href: "/facebook-share-link",
text: "Facebook",
icon: "facebook"
},
{
href: "/twitter-share-link",
text: "Twitter",
icon: "twitter"
},
{
href: "/email-share-link",
text: "Email",
icon: "email"
},
{
href: "/flickr-share-link",
text: "Flickr",
icon: "flickr"
},
{
href: "/instagram-share-link",
text: "Instagram",
icon: "instagram"
},
{
href: "/linkedin-share-link",
text: "Linkedin",
icon: "linkedin"
},
{
href: "/whatsapp-share-link",
text: "WhatsApp",
icon: "whatsapp"
},
{
href: "/other-share-link",
text: "Anything else that might be included that could have quite a long name",
icon: "other"
},
{
href: "/youtube-share-link",
text: "YouTube",
icon: "youtube"
}
]
} %>