Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it important to use <label> in HTML?

Excuse me for the maybe very stupid question, but my curiosity is killing me, and plus I'm new to this, but are using labels important in your markup, and why?

i.e.

<label for="birthdate">Birthdate:</label>
<input type="text" id="birthdate" name="birthdate" />

Why must I label this input, why is it beneficial to the user, why is going to be beneficial for future use, or is it search engine optimization thing. That's what I really wanna know :)

like image 458
getaway Avatar asked Oct 08 '10 18:10

getaway


2 Answers

It's important for a number of reasons:

  • Clicking the label focuses on the
    text field, which is something a lot of users expect.
  • It's helpful for the accessibility reasons.
  • How else is the user going to know which field is which? You could use just text or a span or something, but why would you?
  • It leads to a more semantic markup.
like image 114
GSto Avatar answered Nov 13 '22 04:11

GSto


It helps for accessibility, e.g. screen-readers.

Also for things like checkboxes it allows the user to click on the label and not just the checkbox itself (Try it!).

like image 14
Adam Avatar answered Nov 13 '22 03:11

Adam