What does “for” attribute do in HTML tag?

I wonder what is the difference between the following two code snippets:

<label>Input here : </label>
<input type="text" name="theinput" id='theinput'/>

and

<label for="theinput">Input here : </label>
<input type="text" name="theinput" id='theinput'/>

I’m sure it does something when you use a special JavaScript library, but apart from that, does it validate the HTML or required for some other reason?

7 Answers
7

Leave a Comment