Component

Print link

A link with a print icon to help users print the current page

This component renders two different outputs depending on whether a href is specified. By default, when no href is given, the component renders as a button and triggers a print action via JavaScript. In this case the component is hidden in environments where JavaScript is disabled and can be used as a progressive enhancement. When a href is specified the component renders as an anchor tag and navigates to that href without JavaScript, suitable for applications which have paths that trigger a print event on load.

Search for usage of this component on GitHub.

How it looks (preview) (preview all)

How to call this component

<%= render "govuk_publishing_components/components/print_link", {
} %>

Accessibility acceptance criteria

  • The print icon 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

Standard options

This component uses the component wrapper helper. It accepts the following options and applies them to the parent element of the component. See the component wrapper helper documentation for more detail.

  • id - accepts a string for the element ID attribute
  • data_attributes - accepts a hash of data attributes
  • aria - accepts a hash of aria attributes
  • classes - accepts a space separated string of classes, these should not be used for styling and must be prefixed with js-
  • margin_bottom - accepts a number from 0 to 9 (0px to 60px) using the GOV.UK Frontend spacing scale
  • role - accepts a space separated string of roles
  • lang - accepts a language attribute value
  • open - accepts an open attribute value (true or false)
  • hidden - accepts an empty string, ‘hidden’, or ‘until-found’
  • tabindex - accepts an integer. The integer can also be passed as a string
  • dir - accepts ‘rtl’, ‘ltr’, or ‘auto’
  • type - accepts any valid type attribute e.g. ‘button’, ‘submit’, ‘text’
  • rel - accepts any valid rel attribute e.g. ‘nofollow’
  • target - accepts a valid target attribute e.g. ‘_blank’
  • title - accepts any string
  • draggable - accepts a draggable attribute value (“true” or “false”)

With different text (preview)

<%= render "govuk_publishing_components/components/print_link", {
  text: "Print this manual"
} %>

With different href (preview)

You can specify a alternative href URL that will override the default behaviour. When a href is specified the print link will render as an anchor tag and be displayed even when JavaScript is disabled.

<%= render "govuk_publishing_components/components/print_link", {
  href: "/print"
} %>

With child data attributes (preview)

Data attributes can be passed to the link/button as shown.

Note that the component does not include built in tracking. If this is required consider using the GA4 link tracker.

<%= render "govuk_publishing_components/components/print_link", {
  child_data_attributes: {
    an_attribute: "some_value"
  }
} %>