A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/html/html-label-tag/ below:

HTML <label> Tag - GeeksforGeeks

HTML <label> Tag

Last Updated : 11 Jul, 2025

The <label> HTML element represents a caption for a form element in a user interface. It improves accessibility by linking text to form elements. When a user clicks on the label, it automatically focuses on or activates the associated input, such as text fields, checkboxes, or radio buttons. This helps make forms more user-friendly and easier to navigate.

The <label> tag can be used in two ways:

HTML Inputs and Labels

In HTML, the <label> tag works hand-in-hand with input elements. It allows users to click on the label, which then selects or focuses on the associated input field. This connection between inputs and labels enhances both usability and accessibility for forms, making it easier to interact with them.

Supported Tags

The <label> tag can be defined with the following Tags:

Syntax
<label> form content... </label>
Attribute Value

Attribute Value

Descriptions

for

It refers to the input control that this label is for. Its value must be the same as the value of the input control's "id" attribute.

form

It refers to the form to which the label belongs to.

HTML <label> Tag Examples

Here are some examples of how labeling can be used:

Example 1: Using the <label> Tag with the For Attribute

This example illustrates the basic usage of the <label> tag in HTML. Here, we will use the <input> tag outside of the <label> tag.

html
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML label Tag
    </title>
</head>

<body>

    <strong>HTML label Tag</strong>
    <br><br>
    <form>

        <!-- Starts label tags from here -->
        <label for="student">
            Student
        </label>
        <input type="radio" 
               name="Occupation" 
               id="student" 
               value="student"><br>

        <label for="business">
            Business
        </label>
        <input type="radio" 
               name="Occupation" 
               id="business" 
               value="business"><br>

        <label for="other">
            Other
        </label>
        <!-- Ends label tags here -->

        <input type="radio" 
               name="Occupation" 
               id="other" 
               value="other">
    </form>
</body>

</html>

Output: 

HTML label Tag Example Output Example 2: Using the <input> Tag Inside the <label> Tag

In this example, we will demonstrate how to use the <input> tag inside the <label> tag.

html
<!DOCTYPE html>
<html>

<body>
    <strong> HTML label Tag</strong>
    <br><br>
    <form>
      
        <!-- label tag starts from here -->
        <label>
            Male
            <input type="radio" 
                   name="gender"
                   id="male" 
                   value="male" />
        </label><br />

        <label>
            Female
            <input type="radio" 
                   name="gender"
                   id="female" 
                   value="female" />
        </label><br />

        <label>
            Other
            <input type="radio"
                   name="gender" 
                   id="other" 
                   value="other" />
        </label>
      
        <!-- label tag ends from here -->
    </form>
</body>

</html>

Output: 

HTML label Tag Example Output Supported Browsers

Here are the browsers that support the <label> tag:

Note: Internet Explorer is not supported.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4