You can label an input field with a <label>
tag like this:
<label for="username">Username:</label>
<input id="username" name="username" type="text">
But why?
Is it effective for SEO? Or browser rendering? Or better support for mobile or other devices?
The label
tag supports with a click the focus on the input
element where id
attribute equals labels for
attribute.
If you have e.g. a checkbox you can choose this one also with a click 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's easier to select than a small checkbox element
<label for="myCheckbox">My Checkbox</label>
The primary benefits are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With