Skip to main content
2 of 10
edited tags
mu is too short
  • 436.6k
  • 71
  • 863
  • 822

What does "for" attribute do in label tags?

I wonder what is the difference between these two codes:

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

and

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

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?

jeff
  • 13.8k
  • 32
  • 86
  • 139