TSEP · Source conservée
W3C WAI — Labeling Controls
Vue texte dérivée de la capture ; le document original reste la preuve.
Affirmations et preuves · Télécharger l’original gzip · Source de l’éditeur
Origine et méthode
- SHA-256
7ffbc180ad5978a398d6f98162f11fe461c5f317c66f39e6f16554e578486b22- Capture
- Collecte
anonymous_http_response_body- Vue texte
- Extraction du texte du DOM ; scripts, styles et contenus intégrés omis
L’empreinte des octets décompressés a été vérifiée avant cet affichage. Le texte est échappé ; aucun script ni ressource du document source n’est exécuté. La présentation, les images et l’ordre de lecture peuvent différer de l’original.
Texte de la source éditrice : W3C WAI — Labeling Controls. Reproduit pour vérification ; les droits et licences d’origine restent applicables. Demande de retrait : agence@edikka.com.
Passage référencé
#associating-labels-explicitly — Associating labels explicitly; #labeling-buttons — Labeling buttons
AIA-topic-html-accessibility-1
Extrait du nœud HTML portant l’identifiant cité et, pour un titre, de sa section.
Associating labels explicitly
Whenever possible, use the label element to associate text with form elements explicitly. The for attribute of the label must exactly match the id of the form control.
Example
First name:
Subscribe to newsletter
Code Snippet
<label for="firstname">First name:</label>
<input type="text" name="firstname" id="firstname"><br>
<input type="checkbox" name="subscribe" id="subscribe">
<label for="subscribe">Subscribe to newsletter</label>
Hiding label text
A label for a form control helps everyone better understand its purpose. In some cases, the purpose may be clear enough from the context when the content is rendered visually. The label can be hidden visually, though it still needs to be provided within the code to support other forms of presentation and interaction, such as for screen reader and speech input users. The method used in this tutorial to hide an element visually but make it available for assistive technologies is explained in Note on hiding element.
In the example below, the search field is positioned directly beside the search button. The purpose of the text input field is evident from the context in most situations.
Example
Search:
Search
Hiding the label element
In this approach, the <label> element is provided to identify a form control within the code, but it is visually hidden to avoid redundancy for users who can derive the purpose from the visual cues.
Code Snippet
<label for="search" class="visuallyhidden">Search: </label>
<input type="text" name="search" id="search">
<button type="submit">Search</button>
Using aria-label
The aria-label attribute can also be used to identify form controls. This approach is well supported by screen readers and other assistive technology, but, unlike the title attribute (see below), the information is not conveyed to visual users. The approach should therefore only be used when the label of the control is clear from the surrounding content, like the button in the example below.
Code Snippet
<input type="text" name="search" aria-label="Search">
<button type="submit">Search</button>
Using aria-labelledby
The aria-labelledby attribute can also be used to identify form controls. This approach is well supported by screen readers and other assistive technology, but, unlike the title attribute (see below), the information is not conveyed to visual users. The approach should therefore only be used when the label of the control is clear from the surrounding content, like the button in the example below.
The id of the element containing the label text is used as the value of the aria-labelledby attribute.
Code Snippet
<input type="text" name="search" aria-labelledby="searchbutton">
<button id="searchbutton" type="submit">Search</button>
Using the title attribute
The title attribute can also be used to identify form controls. This approach is generally less reliable and not recommended because some screen readers and assistive technologies do not interpret the title attribute as a replacement for the label element, possibly because the title attribute is often used to provide non-essential information. The information of the title attribute is shown to visual users as a tool tip when hovering over the form field with the mouse.
Example
Search
Code Snippet
<input title="Search" type="text" name="search">
<button type="submit">Search</button>
Note on hiding elements
Screen readers and other assistive technology, just as web browsers, hide elements from their users when they are styled using display: none; and visibility: hidden;.
The common approach used to hide information visually but keep them available to screen reader and other assistive technology users is to use CSS that will keep the information technically visible but practically hidden. For example, presenting the label in a 1-by-1 pixel area, as demonstrated with the CSS class visuallyhidden (do not confuse with CSS visibility: hidden) below:
Code Snippet
.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
Note that interactive elements are still active when using this code, so it is not suitable to hide other parts of forms but the labels.
---
Labeling buttons
The label of a <button> element is set inside the element and can include markup. This allows more advanced accessibility hints to be included, like marking up language change. When using the <input> element to create buttons, the label is set in the value attribute of the element.
Example
<button type="submit">Submit</button>
<button type="button">Cancel</button>
<input type="submit" value="Submit">
<input type="button" value="Cancel">
Note
If the image button (<input type="image">) is used, the label is set in the alt attribute, for example:
<input type="image" src="searchbutton.png" alt="Search">. See Functional Images for more information on how to describe images in buttons.
Texte de la capture
Skip to Content
Change Text Size or Colors
All Translations
Strategies, standards, resources to make the Web accessible to people with disabilities
Menu
Get Involved
About W3C WAI
Search:
Accessibility Fundamentals
Planning & Policies
Design & Develop
Test & Evaluate
Teach & Advocate
Standards/Guidelines
Home
Design & Develop
Tutorials
Forms
Labeling Controls
Design & Develop
Tips for Writing
Tips for Designing
Tips for Developing
Audio & Video Media
User Needs
Planning
Audio Content & Video Content
Description
Captions/Subtitles
Transcripts
Transcribing Audio to Text
Sign Languages
Media Player
Tutorials
Page Structure
Page Regions
Labeling Regions
Headings
Content Structure
Full Example
Menus
Structure
Styling
Fly-Out Menus
Application Menus
Application Menu Example & Code
Images
Informative Images
Decorative Images
Functional Images
Images of Text
Complex Images
Groups of Images
Image Maps
An alt Decision Tree
Tips and Tricks
Tables
One Header
Two Headers
Irregular Headers
Multi-level Headers
Caption & Summary
Tips and Tricks
Forms
Labeling Controls
Grouping Controls
Form Instructions
Validating Input
User Notifications
Multi-page Forms
Custom Controls
Carousels
Structure
Functionality
Animations
Styling
Working Example
Complete Code
Labeling Controls
in Forms Tutorial
Overview
Provide labels to identify all form controls, including text fields, checkboxes, radio buttons, and drop-down menus. In most cases, this is done by using the <label> element.
Page Contents
Associating labels explicitly
Hiding label text
Hiding the label element
Using aria-label
Using aria-labelledby
Using the title attribute
Note on hiding elements
Associating labels implicitly
Labeling buttons
Visual position of label text
Form field controls for mobile
Labels need to describe the purpose of the form control. This section of the tutorial describes how to provide labels that are properly associated with form controls. Later sections explain how to provide instructions, validate user input, and provide feedback to help users complete your form.
A label and a form control should be associated with each other either implicitly or explicitly. Web browsers provide the label as a larger clickable area, for example, to select or activate the control. It also ensures that assistive technology can refer to the correct label when presenting a form control.
Associating labels explicitly
Whenever possible, use the label element to associate text with form elements explicitly. The for attribute of the label must exactly match the id of the form control.
Example
First name:
Subscribe to newsletter
Code Snippet
<label for="firstname">First name:</label>
<input type="text" name="firstname" id="firstname"><br>
<input type="checkbox" name="subscribe" id="subscribe">
<label for="subscribe">Subscribe to newsletter</label>
Hiding label text
A label for a form control helps everyone better understand its purpose. In some cases, the purpose may be clear enough from the context when the content is rendered visually. The label can be hidden visually, though it still needs to be provided within the code to support other forms of presentation and interaction, such as for screen reader and speech input users. The method used in this tutorial to hide an element visually but make it available for assistive technologies is explained in Note on hiding element.
In the example below, the search field is positioned directly beside the search button. The purpose of the text input field is evident from the context in most situations.
Example
Search:
Search
Hiding the label element
In this approach, the <label> element is provided to identify a form control within the code, but it is visually hidden to avoid redundancy for users who can derive the purpose from the visual cues.
Code Snippet
<label for="search" class="visuallyhidden">Search: </label>
<input type="text" name="search" id="search">
<button type="submit">Search</button>
Using aria-label
The aria-label attribute can also be used to identify form controls. This approach is well supported by screen readers and other assistive technology, but, unlike the title attribute (see below), the information is not conveyed to visual users. The approach should therefore only be used when the label of the control is clear from the surrounding content, like the button in the example below.
Code Snippet
<input type="text" name="search" aria-label="Search">
<button type="submit">Search</button>
Using aria-labelledby
The aria-labelledby attribute can also be used to identify form controls. This approach is well supported by screen readers and other assistive technology, but, unlike the title attribute (see below), the information is not conveyed to visual users. The approach should therefore only be used when the label of the control is clear from the surrounding content, like the button in the example below.
The id of the element containing the label text is used as the value of the aria-labelledby attribute.
Code Snippet
<input type="text" name="search" aria-labelledby="searchbutton">
<button id="searchbutton" type="submit">Search</button>
Using the title attribute
The title attribute can also be used to identify form controls. This approach is generally less reliable and not recommended because some screen readers and assistive technologies do not interpret the title attribute as a replacement for the label element, possibly because the title attribute is often used to provide non-essential information. The information of the title attribute is shown to visual users as a tool tip when hovering over the form field with the mouse.
Example
Search
Code Snippet
<input title="Search" type="text" name="search">
<button type="submit">Search</button>
Note on hiding elements
Screen readers and other assistive technology, just as web browsers, hide elements from their users when they are styled using display: none; and visibility: hidden;.
The common approach used to hide information visually but keep them available to screen reader and other assistive technology users is to use CSS that will keep the information technically visible but practically hidden. For example, presenting the label in a 1-by-1 pixel area, as demonstrated with the CSS class visuallyhidden (do not confuse with CSS visibility: hidden) below:
Code Snippet
.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
Note that interactive elements are still active when using this code, so it is not suitable to hide other parts of forms but the labels.
Associating labels implicitly
In some situations, form controls cannot be labeled explicitly. For example, a content author might not know the id of a form field generated by a script, or that script might not add an id at all. In this case, the label element is used as a container for both the form control and the label text, so that the two are associated implicitly. Generally, explicit labels are better supported by assistive technology.
Code Snippet
<label>
First name:
<input type="text" name="firstname">
</label>
<br>
<label>
<input type="checkbox" name="subscribe">
Subscribe to newsletter
</label>
Labeling buttons
The label of a <button> element is set inside the element and can include markup. This allows more advanced accessibility hints to be included, like marking up language change. When using the <input> element to create buttons, the label is set in the value attribute of the element.
Example
<button type="submit">Submit</button>
<button type="button">Cancel</button>
<input type="submit" value="Submit">
<input type="button" value="Cancel">
Note
If the image button (<input type="image">) is used, the label is set in the alt attribute, for example:
<input type="image" src="searchbutton.png" alt="Search">. See Functional Images for more information on how to describe images in buttons.
Visual position of label text
In left-to-right languages, it is customary to visually position labels to the right of radio buttons and checkboxes, and to the left or directly above other form fields. Maintaining this practice increases predictability and understandability of your form for all users.
In general, placing labels above the form fields helps reduce horizontal scrolling for people with low vision and mobile device users. However, the usefulness of this approach depends on other design aspects, such as the proximity of other nearby form fields and content, and needs to be assessed individually. The aim should be to maintain a close and distinct visual relationship between the label and the form control.
Form field controls for mobile
When HTML5 form fields are used, a virtual keyboard appears making it easier to input data.
For example, a number field shows a numeric keyboard, a date field a native date picker.
Sometimes designers propose not including visual field labels. However, most users prefer or even need visible labels to understand the form.
Related WCAG resources
These tutorials provide best-practice guidance on implementing accessibility in different situations. This page combined the following WCAG success criteria and techniques from different conformance levels:
Success Criteria:
1.3.1 Info and Relationships
(Level A)
2.4.6 Headings and Labels
(Level AA)
3.3.2 Labels or Instructions
(Level A)
4.1.2 Name, Role, Value
(Level A)
Techniques:
ARIA14: Using aria-label to provide an accessible name where a visible label cannot be used
ARIA16: Using aria-labelledby to provide a name for user interface controls
G17: Ensuring that a contrast ratio of at least 7:1 exists between text (and images of text) and background behind the text
G18: Ensuring that a contrast ratio of at least 4.5:1 exists between text (and images of text) and background behind the text
G131: Providing descriptive labels
G162: Positioning labels to maximize predictability of relationships
G167: Using an adjacent button to label the purpose of a field
H44: Using label elements to associate text labels with form controls
H65: Using the title attribute to identify form controls when the label element cannot be used
Previous:
Forms Tutorial
Next:
Grouping Controls
Help improve this page
Please share your ideas, suggestions, or comments via e-mail to the publicly-archived list wai@w3.org or via GitHub.
E-mailFork & Edit on GitHubNew GitHub Issue
Back to Top
Status:
Updated
13 May 2024
Editors:
Eric Eggert
Shadi Abou-Zahra
Contributors:
see Acknowledgements
Developed by the Education and Outreach Working Group (EOWG). Developed with support from the WAI-ACT project, co-funded by the European Commission IST Programme.
W3C Web Accessibility Initiative (WAI)
Strategies, standards, resources to make the Web accessible to people with disabilities
Get News in Email
LinkedIn
Mastodon
YouTube
Home
Contact
Site map
Support WAI
News
Accessibility statement
All Translations
Resources for roles
Copyright © 2026 World Wide Web Consortium.
W3C®
liability,
trademark and
permissive license
rules apply unless otherwise noted. See Permission to Use WAI Material.