From a presentation perspective, if I write a text between a <label>
tag it looks identical as to if I hadn't.
So, why do we use this tag at all?
See Question&Answers more detail:osFrom a presentation perspective, if I write a text between a <label>
tag it looks identical as to if I hadn't.
So, why do we use this tag at all?
See Question&Answers more detail:osHTML is not about presentation. It is a way of describing data. If you have some text that represents a label for an input, you wrap it in label tags not for presentation but because that's what it is. Without the label tag, that text is almost meaningless. With the label tag and its for
attribute (or not*) you are providing meaning and structure and forming a relationship between your markup that can be better understood by computers/parsers/browsers/people.
* you don't necessarily need the for
if you wrap the label around the input:
<label>My input
<input type="text" id="my-input" />
</label>