Skip to main content
  1. X-GOVUK projects
  2. GOV.UK Components
  3. Visually hidden text

Visually hidden text

Most of the time content should be both visible on the screen and available to screen readers. However, sometimes when space is at a premium, we may want to hide text that would clutter the screen. This puts users of assistive technology like screen readers at a disadvantage.

We can hide content but make it available to users of assistive technology using the govuk-visually-hidden class. This library provides a helper method which makes hiding content easier.

Setting visually hidden text with an argument

Input

p Regular text

= govuk_visually_hidden("This content is visually hidden")

p More regular text
<p>Regular text
</p>
<%= govuk_visually_hidden("This content is visually hidden") %>
<p>More regular text</p>

Output

Regular text

This content is visually hidden

More regular text

<p>
  Regular text
</p>
<span class="govuk-visually-hidden">
  This content is visually hidden
</span>
<p>
  More regular text
</p>

Setting visually hidden text with a block

Input

p Regular text

= govuk_visually_hidden do
  p This paragraph is visually hidden

p More regular text
<p>Regular text
</p>
<%= govuk_visually_hidden do %>
  <p>This paragraph is visually hidden
  </p>
<% end %>
<p>More regular text</p>

Output

Regular text

This paragraph is visually hidden

More regular text

<p>
  Regular text
</p>
<span class="govuk-visually-hidden">
  <p>
    This paragraph is visually hidden
  </p>
</span>
<p>
  More regular text
</p>