What are the advantages of using the fieldset tag?

Diego picture Diego · Jun 29, 2011 · Viewed 13.3k times · Source

What are the advantages of using the <fieldset> tag?

I don't really get what it is used for.

Answer

Jamie Dixon picture Jamie Dixon · Jun 29, 2011

Forms are often broken up into various sets of fields.

The fieldset tag allows you to logically group sets of fields in order that your forms be more descriptive.

You'll also note that you can use the fieldset to style your forms and display those logical associations between fields.

Just like forms you find in the "real" world.

The "advantages" of using a fieldset are that they allow you to mark up your data (in this case a form) in the most semantic way available. Consider that placing your fields in a fieldset is more descriptive than placing your fields in a div. The div tells you nothing about the relationship between the fields, a fieldset tells you there is a relationship.

It's a similar principle to many of the new HTML5 tagsets. <footer> for example tells you more about the meaning of the data inside it compared to an ambiguous <div>.