How to guides

Making labels and legends headings

Whenever you design a form, you should start by splitting it across multiple pages with each page containing just one thing, for example:

  • one piece of information you’re telling a user
  • one decision they have to make
  • one question they have to answer

This helps users focus and understand what’s being asked of them.

When you’re asking just one question on a page, you can make the question the page’s heading. Your page heading will then most likely be the same as the <label> or <legend> for the input.

For example, on a page that only asks users for their postcode, the question ‘What is your postcode’ would be both the page heading and the most logical <label> for your text input.

To avoid repetition, one option is to use a visually hidden <label> or <legend>.

However, this option only removes visual duplication and will not help users of screen readers. They will still hear both the page heading and the visually hidden <label> or <legend>.

To prevent this, set the contents of the <label> or <legend> as the page heading (except if you're asking more than one question on the page).

Labels as page headings

To set the contents of a label as the page heading, you need to put the <label> tag inside the <h1> tag. You can either do this in HTML, or by using the Nunjucks macro and setting isPageHeading: true.

You then need to apply classes to the <label> to make it look like a heading.

<div class="app-example app-example--tabs">
  <div class="app-example__toolbar">
    <a href="/get-started/labels-legends-headings/label-h1/index.html" class="app-example__new-window" target="_blank">
      Open this
      <span class="govuk-visually-hidden">labels as page headings - making labels and legends headings</span>
      example in a new tab
    </a>
  </div>
  <iframe title="Labels as page headings - Making labels and legends headings example" data-module="app-example-frame" class="app-example__frame app-example__frame--resizable" src="/get-started/labels-legends-headings/label-h1/index.html" frameBorder="0" loading="lazy"></iframe>
</div>

<span id="options-labels-as-page-headings-making-labels-and-legends-headings-example"></span>
<ul class="app-tabs" role="tablist">
  <li class="app-tabs__item js-tabs__item" role="presentation"><a href="#labels-as-page-headings-making-labels-and-legends-headings-example-html" role="tab" aria-controls="labels-as-page-headings-making-labels-and-legends-headings-example-html" data-track="tab-html">HTML</a></li>
  <li class="app-tabs__item js-tabs__item" role="presentation"><a href="#labels-as-page-headings-making-labels-and-legends-headings-example-nunjucks" role="tab" aria-controls="labels-as-page-headings-making-labels-and-legends-headings-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></li>
</ul>

  <div class="app-tabs__heading js-tabs__heading"><a href="#labels-as-page-headings-making-labels-and-legends-headings-example-html" aria-controls="labels-as-page-headings-making-labels-and-legends-headings-example-html" data-track="tab-html">HTML</a></div>

<div class="app-tabs__container js-tabs__container" id="labels-as-page-headings-making-labels-and-legends-headings-example-html" role="tabpanel">
  <div class="app-example__code">
    <pre data-module="app-copy" tabindex="0"><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;govuk-form-group&quot;</span>&gt;</span>

<h1 class="govuk-label-wrapper"> <label class="govuk-label govuk-label--l" for="example"> govuk-label--l </label> </h1> <div id="example-hint" class="govuk-hint"> This example shows an &lt;h1&gt; around a &lt;label&gt; with the class of govuk-label--l </div> <input class="govuk-input" id="example" name="example" type="text" aria-describedby="example-hint"> </div>

  <div class="app-tabs__heading js-tabs__heading"><a class="app-tabs__heading-link" href="#labels-as-page-headings-making-labels-and-legends-headings-example-nunjucks" aria-controls="labels-as-page-headings-making-labels-and-legends-headings-example-nunjucks" data-track="tab-nunjucks">Nunjucks</a></div>
<div class="app-tabs__container js-tabs__container" id="labels-as-page-headings-making-labels-and-legends-headings-example-nunjucks" role="tabpanel"><div class="app-example__code">
    <pre data-module="app-copy" tabindex="0"><code class="hljs js">{% <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;govuk/components/input/macro.njk&quot;</span> <span class="hljs-keyword">import</span> govukInput %}

{{ govukInput({ label: { text: "govuk-label--l", classes: "govuk-label--l", isPageHeading: true }, hint: { text: "This example shows an <h1> around a <label> with the class of govuk-label--l" }, id: "example", name: "example" }) }}