Legend and Label elements

Can someone please explain the difference between legend and label elements?

label is used for a specific element (like a radio button or check box)
legend is used to label a group or set of elements as a block/whole.

Hi, hbar1st

Thank you. I also tried it on w3school.com, changed <legend> to <label> and I realised that the <label> does not allow the element content to be displayed.

Not sure what you mean by that.


Hi, lasjorg

Thank you for your contribution. Sorry I meant to say it does not display correctly. If you try it on w3school, you will realise that it changing <legend> to <label> make the content to be displayed inline with the first radio button, making it look like the label for that button whereas it is the label for the entire input field.

Well you have to have a fieldset as the parent element for the <legend> element as they work together.

But yes, the two elements (legend and label) are not interchangeable and are used for different things.