Language

HTML Label Element


The label element is used because it helps the user understand the purpose of the input field. The label element is associated with the input field, which helps the user understand where and what to write.


The for attribute is an important aspect of the label element. The id value of the input field is used in the for attribute. This way, the label element will be connected to the input field, so clicking on the label element will activate the input field.

HTML label element explained with examples.

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
   
    <form>
        <label for="fullName">Full Name</label>
        <input type="text" id="fullName">
    </form>  
</body>
</html>