HTML label Attribute
Description
The HTML label attribute is used to define a label for several elements. However, its association and behavior differ based on the specific elements it is used with, such as <option>, <optgroup>, and <track>. Below is an explanation of how the label attribute functions when used with these three tags:
<option>tag: When used with the<option>element within a<select>dropdown list, thelabelattribute specifies the label to be shown for the option. This can be particularly useful for providing a more readable or descriptive label for the options presented to the user, especially when the option's value might be an identifier or code that is not inherently descriptive.<optgroup>tag: The<optgroup>element is used to group together options within a<select>list, making it easier for users to navigate large lists of options. Thelabelattribute is required for<optgroup>and specifies the label for the group of options. This label is typically displayed in a manner that visually differentiates it from the options, often as non-selectable text that is styled differently (such as being bolded).<track>tag: The<track>element is used with<audio>and<video>elements to specify text tracks for media elements, such as captions, subtitles, or descriptions. Thelabelattribute for<track>provides a title for the text track. This title can be displayed by media players in their track selection menus, allowing users to choose between different text tracks based on their description. This is particularly useful for providing multiple language options for subtitles or for distinguishing between different kinds of text tracks (for example, standard subtitles versus descriptive subtitles for the hearing impaired).
In summary, the label attribute serves as a way to provide a descriptive or readable name for elements or groups of elements within HTML forms and media elements, enhancing usability and accessibility for users.
Syntax
<tagname label="text">
Values
- textTitle of a track or short label of the text.
Applies To
Example
Browser Support
The following information will show you the current browser support for the HTML label attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.
This attribute is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 29th March 2024
