<label> Tag in HTML

The <label> tag in HTML is used to define a label for an <input>, <textarea>, <select>, or other form elements. It helps in providing a user-friendly description of the input field and improves form accessibility by associating a text description with a form control.

Key Points on <label> Tag:

Syntax of <label> Tag:

Syntax Example

<label for="elementID">Label Text</label>

Example of <label> Tag in HTML:

This example demonstrates the use of the <label> tag to associate labels with input elements.

Code Example

<form>
            <label for="username">Username:</label>
            <input type="text" id="username" name="username">
            <br>
            <label for="password">Password:</label>
            <input type="password" id="password" name="password">
        </form>

Output


Attributes of <label> Tag:

The <label> tag is important for accessibility, ensuring that form inputs are clearly described and easy to interact with. It is especially useful when the input fields are complex or when the form is intended to be used by individuals with disabilities.