Despite reading pages upon pages about the <article>
and <section>
tags I really don't understand how to apply them to my site.
I have a product page with related products at the end of the page. First I thought about doing something like this:
<section>
<header><h1>Product title</h1><header>
<img src="image.jpg"/>
<p>Description</p>
<p>Price</p>
<p><a href="...">Order</a></p>
</section>
<section>
<header><h1>Related products</h1></header>
<article>
<a href="..."><img src="image1.jpg"><br/>Product 1</a><br/>Price
</article>
<article>
<a href="..."><img src="image2.jpg"><br/>Product 2</a><br/>Price
</article>
<article>
<a href="..."><img src="image3.jpg"><br/>Product 3</a><br/>Price
</article>
</section>
But, then I read some other blogs and it occured to me that maybe I should replace the <section>
tags with <article>
tags.
Which is right and why? Thanks.
I'd use <article> for a text block that is totally unrelated to the other blocks on the page. <section> , on the other hand, would be a divider to separate a document which have are related to each other.
The article tag is used for wrapping an autonomous content on a page. A content is autonomous if it can be removed from the page and put on some another page. The section tag is similar to the div tag, but it is more meaningful since it wraps logical groups of related content (e.g. a chapter of an article).
The section tag is used when requirements of two headers or footers or any other section of documents needed. Section tag grouped the generic block of related contents. The main advantage of the section tag is, it is a semantic element, which describes its meaning to both browser and developer.
A section is the distinct and numbered subdivisions in legal codes, statutes, and textbooks. An article is a separate and distinct part of a written instrument, such as a contract, statute, or constitution, that is often divided into sections.
Section
The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content. The theme of each section should be identified, typically by including a heading (h1-h6 element) as a child of the section element.
Article
The article element represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
When article elements are nested, the inner article elements represent articles that are in principle related to the contents of the outer article. For instance, a blog entry on a site that accepts user-submitted comments could represent the comments as article elements nested within the article element for the blog entry.
Straight from the W3 http://www.w3.org/html/wg/drafts/html/master/sections.html
In their example, they have an article
nested within a section
within an article
. I would say you are definitely using it correctly.
<article>
<header></header>
<section>
<h1></h1>
<article></article>
<article></article>
</section>
</article>
<article>
is for an independent piece of content that should make sense even if all of it's surrounding content is stripped away. <section>
is more of a generic container that's quite similar to div tag and mostly used for content structuring. So the right code should be like this:
<article>
<header><h1>Product title</h1><header>
<img src="image.jpg"/>
<p>Description</p>
<p>Price</p>
<p><a href="...">Order</a></p>
</article>
<article>
<header><h1>Related products</h1></header>
<section>
<a href="..."><img src="image1.jpg"><br/>Product 1</a><br/>Price
</section>
<section>
<a href="..."><img src="image2.jpg"><br/>Product 2</a><br/>Price
</section>
<section>
<a href="..."><img src="image3.jpg"><br/>Product 3</a><br/>Price
</section>
</article>
Also HTML 5 doctor's got a great Flowchart if you get confused picking the right HTML5 semantic element for your need. You can give it a try and see if it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With