What is a <label> tag?

Experience Level: Junior
Tags: HTML

Answer

The <label> tag is used to render a label of an input element.

Imagine you have a form with two text fields - first name and last name. Each text field is be defined by <input type="text"/ > tag. How will the user know what to enter into each text field when it isn't labeled?

The solution is to use the <label> tag.

You could obviously use <span> but <label> is better for usability, because the screen readers can understand that <label> is labeling some field whereas <span> is understood to be just some text.

Example
<html>
<head>...</head>
<body>

    <label for="email">Email</label>
    <input type="text" id="email" name="email"> 
    
</body>
</html>
Related HTML job interview questions

Comments

No Comments Yet.
Be the first to tell us what you think.
HTML for beginners
HTML for beginners

Are you learning HTML ? Try our test we designed to help you progress faster.

Test yourself