HTML label attribute
label
The purpose of the HTML label attribute is to specify a label for options or option groups within a pull-down menu.
Supported elements
HTML label attribute supports option and optgroup elements.
Syntax
<ElementName label="value" >.....</ElementName>
Where ElementName is any supported elements.
Type of value
Text.
Value
Text.
Default value
There is no default value of HTML label attribute.
Supported doctypes
HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.
Example of HTML label attribute with option and optgroup
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML label attribute with option and optgroup</title>
</head>
<body>
<form name="Fav_Sport" >
<label>Favorite Sports </label>
<select name="favoritesports" id="favoritesports">
<optgroup label="Sports">
<option label="Soccer">Soccer</option>
<option label="Hockey">Hockey</option>
<option label="Tennis">Tennis</option>
<option label="Golf">Golf</option>
</optgroup>
</select>
</form>
</body>
</html>
Result

View this example in a separate browser window
Example of HTML label attribute with option and optgroup
Previous: HTML ismap attribute
Next: lang and dir attribute of HTML
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join