HTML label Attribute

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The label attribute supplies a human-readable name for an <optgroup>, <option>, or <track>. Browsers show that text in select lists and in video/audio caption menus.

It is not the <label> element (which captions a form control, often with for). Same word, different job.

Baseline · Widely available.

Not deprecated and not experimental. Stable on optgroup, option, and track across modern browsers.

Required on optgroup.

In normal HTML, optgroup must have a label (unless a child <legend> is used in a customizable select). Empty groups confuse users.

HTML Syntax

syntax.html
<optgroup|option|track label=" text">

text is any user-facing string (for example Theropods or English Captions).

Attribute Values

A single text string. Meaning depends on the element:

ElementWhat label doesTry it
<optgroup>Name of the option group in the select UI (required in typical use)Try it
<option>Text shown for the option; if omitted or empty, the option’s text content is usedTry it
<track>Title listed in the player’s captions/subtitles menuTry it

Live Preview

Edit the group label, then open the select — the heading text updates immediately.

This is the label attribute on <optgroup>, not a <label> element.

Select

First group label="Theropods"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Group Options with optgroup

Name each group so the select list is easy to scan.

HTML
<label for="dino-select">Choose a dinosaur:</label>
<select id="dino-select">
  <optgroup label="Theropods">
    <option>Tyrannosaurus</option>
    <option>Velociraptor</option>
  </optgroup>
  <optgroup label="Sauropods">
    <option>Diplodocus</option>
    <option>Apatosaurus</option>
  </optgroup>
</select>
Try It Yourself

How It Works

  1. Wrap related options. Each <optgroup> holds a set of <option>s.
  2. Name the group. label="Theropods" is the heading the browser shows (not selectable itself).
  3. Caption the control. The <label for> element is separate — it names the whole select.
  4. Keep groups flat. Do not nest optgroup elements.

Example 2 — Different Display Text on option

Use label when the visible text should differ from the option’s content or value.

HTML
<label for="size">T-shirt size:</label>
<select id="size" name="size">
  <option value="s" label="Small (S)">S</option>
  <option value="m" label="Medium (M)">M</option>
  <option value="l" label="Large (L)">L</option>
</select>
Try It Yourself

How It Works

  1. value is what the form submits (s, m, l).
  2. label is the intended display string when the attribute is set and non-empty.
  3. Fallback. If label is missing or empty, the option’s text content is used.
  4. Prefer clear text. For most selects, putting the full phrase in the option body is enough — use label when you need the split.

Example 3 — Caption Menu Title on track

Players list tracks by label, not by the srclang code alone.

HTML
<video controls width="320">
  <source src="/video/count.mp4" type="video/mp4">
  <track
    kind="captions"
    src="/video/count.vtt"
    srclang="en"
    label="English Captions"
    default>
  <track
    kind="subtitles"
    src="/video/count_es.vtt"
    srclang="es"
    label="Español">
  Your browser does not support HTML video.
</video>
Try It Yourself

How It Works

  1. kind classifies the track; label names it in the UI.
  2. srclang is the language code; users usually prefer the friendly label.
  3. Keep combinations unique. Do not reuse the same kind + srclang + label on one media element.
  4. Write for people. Prefer English Captions over bare en.

Edge Cases & Pitfalls

Most confusion is mixing up the attribute with the <label> element, or skipping required group names.

compare

Attribute ≠ <label> element

Use <label> / for to name form controls. Use the label attribute on optgroup, option, and track.

required

Always name optgroup

MDN/HTML: label is mandatory for normal optgroup use. Groups without a name are hard to understand.

option

Empty option label falls back

If the attribute is missing or empty, display uses the option’s text content. Do not rely on exotic label/text splits without testing browsers.

track

Unique track identity

A media element cannot have two tracks with the same kind, srclang, and label. Change the label when you add another track of the same kind/language.

nesting

No nested optgroup

Option groups cannot nest. Use flat groups with clear label text instead.

Browser Support

label is an HTML attribute on form and media elements in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

label

Widely supported on optgroup and option since early HTML, and on track with HTML5 text tracks (about July 2015+). Safe for production selects and caption menus.

98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer optgroup/option; track IE10+
Supported
label attribute Widely supported

Bottom line: Use freely for optgroup and track titles. Test option label vs text if you need them to differ.

Key Takeaways

  • Role: human-readable name for optgroup, option, or track.
  • Not the element: form captions use <label> / for instead.
  • optgroup: always provide a clear group label.
  • track: menu titles come from label, not from srclang alone.

One line: the label attribute names groups, options, and tracks in the UI — do not confuse it with the <label> tag.

Frequently Asked Questions

It gives a human-readable name to an optgroup, an option, or a track. Browsers show that text in select lists and caption/subtitle menus.
No. The label attribute names optgroup/option/track items. The label element associates caption text with a form control (often with the for attribute).
Mainly optgroup (required in normal use), option (optional; falls back to the option’s text), and track (title in the media player’s track list).
Yes in typical HTML: the label attribute must be specified unless a child legend is used in a customizable select. Without a name, the group has nothing useful to show.
The browser uses the option’s text content as the displayed label. Set label when you want a different display string than the text or value.
Players list tracks by label (for example English Captions), not by the srclang code. Clear labels help users pick the right captions or subtitles.

Next: lang

Learn the lang attribute for declaring the language of page content.

lang tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful