HTML Tutorial
The <legend>
tag defines a caption or label for groups of controls, such as <fieldset>
elements.
<!-- Fieldset with legend -->
<fieldset>
<legend>Personal Details</legend>
<label for="name">Name:</label>
<input type="text" id="name">
<label for="email">Email:</label>
<input type="email" id="email">
</fieldset>
<!-- Right-aligned legend -->
<fieldset>
<legend align="right">Shipping Address</legend>
...
</fieldset>
<!-- Legend with keyboard shortcut -->
<fieldset>
<legend accesskey="d">Details</legend>
...
</fieldset>
Simple HTML Example:
<!DOCTYPE html>
<html>
<head>
<title>Exploring the <legend> Tag</title>
</head>
<body>
<fieldset>
<legend>Contact Information</legend>
<label for="name">Name:</label>
<input type="text" id="name">
<label for="email">Email:</label>
<input type="email" id="email">
</fieldset>
</body>
</html>
accesskey
attribute to provide a keyboard shortcut for users with motor impairments.