HTML HTML Forms Choosing Options Radio Buttons

Paula Mourad
Paula Mourad
5,154 Points

Labels vs Paragraphs

Hi!

Why do you use "labels" instead of a "p"? For example, in the radio button, instead of creating a label that says "Over 13 or older", can you just have a <p>Over 13 or Older</p>?

Thanks! :)

2 Answers

Belve Marks
Belve Marks
7,331 Points

Brendon is on the right track, but HTML should also be semantic. Meaning that the tags you use should express their function in the document. The <label> tag is just that, while the p tag is just a text dump. This not only makes the HTML easier to understand, but also makes it easier to style: instead of creating a classed <p>, you can simply target <label> in the CSS.

Brendon Butler
Brendon Butler
4,232 Points

I don't know for sure, since I never really use forms. But I think the reason being is that -- for one, paragraph tags have formatting pre-defined, where as with the label tag, you're essentially left with raw text (I could be wrong with this). Also, with labels you can define what css attribute it is linked to.

Source: HTML label tag

Paula Mourad
Paula Mourad
5,154 Points

Thanks Brendon :)