With the HTML label tag, you improve your website’s usability and ac­cess­ib­il­ity. label can be used for input fields, check­boxes, and radio buttons, among other things. It works with global at­trib­utes, event at­trib­utes, as well as for and form.

Web hosting
The hosting your website deserves at an un­beat­able price
  • Loading 3x faster for happier customers
  • Rock-solid 99.99% uptime and advanced pro­tec­tion
  • Only at IONOS: up to 500 GB included

What is the HTML label tag used for?

For improved clarity and website ac­cess­ib­il­ity, the HTML label tag plays a key role. It is used in forms to provide clear de­scrip­tions for elements such as input fields, radio buttons, and check­boxes.

This is es­pe­cially important for two use cases:

  • It makes website nav­ig­a­tion easier for visitors who have dif­fi­culty in­ter­act­ing with small clickable areas. Because the clickable area is larger, form elements are easier to select and use.
  • For users who rely on a screen reader, the HTML label tag ensures that form labels are read aloud correctly. This improves usability for all visitors to your website.

WCAG relevance of the label tag

HTML forms should not only be visually easy to un­der­stand, but also comply with the current standards for digital ac­cess­ib­il­ity. The WCAG (Web Content Ac­cess­ib­il­ity Guidelines) 2.2 require, for example, that all input fields be labelled or provided with clear in­struc­tions (Success Criterion 3.3.2 ‘Labels or In­struc­tions’). This ensures that people with cognitive or visual impair­ments un­der­stand what input is expected.

In addition, WCAG Success Criterion 2.5.3 ‘Label in Name’ ensures that the visible label is also included in the program code as an ac­cess­ible name. This is important for users who rely on assistive tech­no­lo­gies or voice control.

Note

In the United Kingdom, digital ac­cess­ib­il­ity re­quire­ments are primarily governed by the Equality Act 2010 and the Public Sector Bodies (Websites and Mobile Ap­plic­a­tions) (No. 2) Ac­cess­ib­il­ity Reg­u­la­tions 2018. Under these reg­u­la­tions, many digital offerings, including online forms, must be designed to be ac­cess­ible and usable for people with dis­ab­il­it­ies. In practice, WCAG guidelines serve as the technical standard used to assess whether digital content meets these legal ac­cess­ib­il­ity re­quire­ments.

How is the label tag in HTML used?

The label tag in HTML can be used in two different ways. Both methods ensure that assistive tech­no­lo­gies such as screen readers correctly associate the label with its form control and allow users to click the label to focus the cor­res­pond­ing input field.

Explicit as­so­ci­ation (with for and id)

With the explicit method, you separate the label and the form field in the HTML, but link them using the for attribute with the input field’s id value. This option provides the best support from browsers and assistive tech­no­lo­gies. For this reason, it is generally re­com­men­ded as a best practice.

<p>
    <input type="checkbox" name="read" id="read" value="yes" />
    <label for="read">I have read the terms and conditions</label>
</p>
html

It’s important that the value of the for attribute matches the id attribute of the input field exactly.

Implicit as­so­ci­ation (input inside the label)

Al­tern­at­ively, you can place the input field inside the <label> element. In this case, the as­so­ci­ation is created auto­mat­ic­ally without needing to set for and id. This option is also valid HTML, but it is not supported by all devices.

<p>
    <label>
        <input type="checkbox" name="read" value="yes" />
         I have read the terms and conditions
    </label>
</p>
html

Which elements are as­so­ci­ated with the HTML tag for label?

To enable ac­cess­ible access to your page for users with screen readers, for example, you should label the following elements in HTML with an HTML label (the label tag in HTML) in par­tic­u­lar:

  • Input fields: <input type="text" />, <input type="password" />, <textarea>
  • Check­boxes: <input type="checkbox" />
  • Radio buttons: <input type="radio" />
  • Drop-down lists: <select>
  • Upload fields: <input type="file" />

Which at­trib­utes does the label tag in HTML support?

The HTML label supports all global HTML at­trib­utes as well as all event at­trib­utes. In addition, the following at­trib­utes can be as­so­ci­ated with the HTML label:

  • for: The for attribute specifies the ID of the input element that the label should be as­so­ci­ated with. The value of for must exactly match the value of the id attribute of another form control in the same document.
  • form: The form attribute can be useful in complex layouts where a label and its as­so­ci­ated form control are not located within the same form element. In most ac­cess­ible forms, however, it is not required. The re­com­men­ded as­so­ci­ation is done using for / id or by nesting the input inside the label. The form attribute is not part of the standard at­trib­utes typically used with the HTML label tag in the HTML spe­cific­a­tion.
<form id="participant">
    <label for="first-name">First name</label>
    <input name="first-name" id="first-name" maxlength="25">
    <label for="last-name">Last name</label>
    <input name="last-name" id="last-name" maxlength="30">
    <button>Confirm details</button>
</form>
html
Go to Main Menu