1. Component Guide
  2. Share links
Component

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:

Search for usage of this component on GitHub.

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 gem-track-click, 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"
    }
  ]
} %>

With custom visually hidden text (preview)

Use this option to specify a visually hidden text for screenreaders to prepend to the link text.

If omitted, the default text used will be ‘Share on’.

<%= render "govuk_publishing_components/components/share_links", {
  links: [
    {
      href: "share",
      text: "Facebook",
      hidden_text: "Download from",
      icon: "facebook"
    }
  ]
} %>

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"
    }
  ]
} %>