Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using section element for stylistic layout and wrappers

I often use divs for stylistic layouts(pieces of markup with no content, specifically focused on the design) and wrappers on sites. With that said, Why should sections not be used for this task?

Does a section by itself have an inherent semantic meaning that discourages it being used for wrappers?

Almost every page I use has some wrapper or stylistic layout of some sort. Wanting to phase out divs, I wonder, if sections can be used for wrappers and still be semantically correct.

like image 451
Conqueror Avatar asked Sep 16 '13 23:09

Conqueror


People also ask

What is the purpose of the section element?

The section element is a generic semantic element, that can be used to combine portions of a document together into discrete units that are related in some way.

What is a wrapper element?

A wrapper has no semantic meaning. It simply holds all visual elements and content on the page. It's just a generic container. In terms of semantics, <div> is the best choice. The <div> also has no semantic meaning and it just a generic container.

What is a section element?

The <section> HTML element represents a generic standalone section of a document, which doesn't have a more specific semantic element to represent it. Sections should always have a heading, with very few exceptions.

What is the purpose of section in HTML?

What is a section in HTML? In HTML, a section is a semantic element for creating standalone sections in a web page. These sections should be made up of related content, like contact information. The section element should only be used if there isn't a more specific element to represent the related content.


1 Answers

Yes, the section element has an "inherent semantic meaning". See the definitions in the HTML5 spec:

  • div element:

    The div element has no special meaning at all.

  • section element:

    The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading.

To understand what this meaning is about, see my answer on the question HTML5 section tag meanings?.

The most important argument for not using section as a wrapper for CSS/JS is: each section creates an entry in the outline of your document.

Don’t use section as a wrapper in the way you described it. Use div (resp. span) instead.

If you use section appropriately, you can of course use it as selector for CSS/JS in addition, so you don’t need to add another div for this.

like image 190
unor Avatar answered Sep 21 '22 20:09

unor