Skip to main content
  1. Home
  2. Link helpers

Link helpers

In addition to the components, this gem also comes with link helpers that are often reimplemented across projects.

Regular links are just plain anchor elements with the govuk-link class.

Input

Output

Use inverse hyperlinks on dark backgrounds.

Input

Output

Input

Output


Class helpers

Rails has lots of link helpers and only the most frequently used are wrapped by this library. If you need to use another variant, like link_to_if, you can use the govuk_link_classes and govuk_button_classes helpers to ensure the correct classes are assigned.

Using the class helpers

When no arguments are provided to govuk_link_classes, only the default govuk-link will be added. Alternate styles can be passed in as a snake cased array of variants.

Input

p
  = link_to_if(true,
    'A regular link generated by Rails',
    '#',
    class: govuk_link_classes)

p
  = link_to_if(true,
    'A muted and not underlined link generated by Rails',
    '#',
    class: govuk_link_classes(:muted, :no_underline))
<p>
  <%= link_to_if(true, 'A regular link generated by Rails', '#', class: govuk_link_classes) %>
</p>
<p>
  <%= link_to_if(true, 'A muted and not underlined link generated by Rails', '#', class: govuk_link_classes(:muted, :no_underline)) %>
</p>

Output

<p>
  <a class="govuk-link" href="#">
    A regular link generated by Rails
  </a>
</p>
<p>
  <a class="govuk-link govuk-link--muted govuk-link--no-underline" href="#">
    A muted and not underlined link generated by Rails
  </a>
</p>