HTML label tag
HTML

HTML label tag

Mishel Shaji
Mishel Shaji

The HTML label tag defined caption for an element. It is typically used with HTML forms to provide a description for a form element.

Usage

  • If an element is associated with the label, you can click on the label to activate the element.
  • The label text is not only visually and programmatically associated with the corresponding element. This means that for example a screenreader will read out the label when the user is focused on the form input, making it easier to understand what data should be entered.

Attribute

AttributeDescription
forSpecifies the input control that this label is for.
formSpecifies one or more forms the label belongs to

This element supports HTML Global attributes.

Example

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>  
    <h5>Checkbox with no label:</h5>
    <div>
        <span>Select me</span>
        <input type="checkbox" name="cheese" id="chkboxsp">
    </div>
    <h5>Checkbox with label — Click the label to active the element:</h5>
    <div>
        <label for="chkboxlb">Select me</label>
        <input type="checkbox" name="peas" id="chkboxlb">
    </div>
</body>
</html>

Output

Checkbox with no label:
Select me
Checkbox with label — Click the label to focus the element: