User...">

Why should you use the <label> tag and the 'for' attribute?

You can mark the input field with the <label> as follows:

 <label for="username">Username:</label> <input id="username" name="username" type="text"> 

But why?

Is it effective for SEO? Or browser rendering? Or is it better to support mobile or other devices?

+6
source share
2 answers

The label tag supports clicking focus on the input element, where the id attribute is equal to for methods. If you have, for example, a flag can also be selected by clicking on the label.

Example:

 <input type="checkbox" value="1" id="myCheckbox"/> // A click here set the focus on the according checkbox without javascript things // And it easier to select than a small checkbox element <label for="myCheckbox">My Checkbox</label> 
+10
source

Main advantages:

  • Accessibility - this allows screen readers to know what form the text control applies to, this allows them to tell the user exactly what they should enter in the field
  • Click on targets - clicking on a label has the same effect as clicking on a form control; larger click targets are easier to hit, especially when the input signal is smaller than the radio button
+6
source

Source: https://habr.com/ru/post/971971/


All Articles