Reputation: 7325
I have a page made up of various "sections" like videos, a newsfeed etc.. I am a bit confused how to represent these with HTML. Currently I have them as HTML <section>
s, but on further inspection it looks they the more correct tag would be <article>
. Could anyone shed some light on this for me?
None of these things are blog posts or "documents" in the true sense of the word so it's kind of hard to see which element to apply.
Upvotes: 284
Views: 211011
Reputation: 29
Since no one mentioned this, in all those years.
Except Nick Manning who no one upvoted for some weird reason.
There is a document outline H1 ... H6.
Each section start it's own outline.
Article is a section, just a more specified one. It helps search engines and screen readers.
Section and article is basically an isolated outlining.
They are NOT for layout.
This means that article is self-contained with it's own outlining.
If you then put a section inside an article or even another article inside, you start a whole new outlining.
You need a very good reason for that. I can't give a single one yet.
I find it article breaking and I think screen readers and search engines also will.
If you think you need an article split into sections, you properly have either:
At the moment https://www.w3schools.com/html/html5_semantic_elements.asp is doing it wrong.
<article class="all-browsers">
<h1>Most Popular Browsers</h1>
<article class="browser">
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google, released in 2008. Chrome is the world's most popular web browser today!</p>
</article>
<article class="browser">
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by Mozilla. Firefox has been the second most popular web browser since January, 2018.</p>
</article>
<article class="browser">
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015. Microsoft Edge replaced Internet Explorer.</p>
</article>
</article>
Should be
<section class="all-browsers">
<h1>Most Popular Browsers</h1>
<article class="browser">
<h1>Google Chrome</h1>
<p>Google Chrome is a web browser developed by Google, released in 2008. Chrome is the world's most popular web browser today!</p>
</article>
<article class="browser">
<h1>Mozilla Firefox</h1>
<p>Mozilla Firefox is an open-source web browser developed by Mozilla. Firefox has been the second most popular web browser since January, 2018.</p>
</article>
<article class="browser">
<h1>Microsoft Edge</h1>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015. Microsoft Edge replaced Internet Explorer.</p>
</article>
</section>
I have not worked much with SR and SEO, so pls correct me if they just love articles consisting of multiple articles and not being their own unit.
Chapters of articles are placed in p tags and are divided by H2 or lower outline.
If you put chapters in each own section, as flowchart from HTML5 Doctor suggests (answer from Captain Sensible), they are no longer related.
Not to the article and not to each other. Not in semantics anyway.
Upvotes: 0
Reputation: 18585
Markup the sections of your webpage using <section>
elements. Articles lend themselves to the schema.org microdata vocabulary as a CreativeWork
subtype or are indicated for use as widget containers.
<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.. source
The published example use cases are (1) widget containers and (2) blog posts.
It is noted that
Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the element. source
<section>
The section element represents a generic section of a document or application. source
Upvotes: 0
Reputation: 5037
The flowchart below can be of help when choosing one of the various semantic HTML5 elements:
Image courtesy of @riddle & @boblet HTML5 Doctor
Upvotes: 38
Reputation: 12447
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.
Now, I'm not sure what you have in your videos, news feed etc, but here's an example (there's no REAL right or wrong, just a guideline of how I use these tags):
<article>
<h1>People</h1>
<p>text about people</p>
<section>
<h1>fat people</h1>
<p>text about fat people</p>
</section>
<section>
<h1>skinny people</p>
<p>text about skinny people</p>
</section>
</article>
<article>
<h1>Cars</h1>
<p>text about cars</p>
<section>
<h1>Fast Cars</h1>
<p>text about fast cars</p>
</section>
</article>
As you can see, the sections are still relevant to each other, but as long as they're inside a block that groups them. Sections DON'T have to be inside articles. They can be in the body of a document, but I use sections in the body, when the whole document is one article.
e.g.
<body>
<h1>Cars</h1>
<p>text about cars</p>
<section>
<h1>Fast Cars</h1>
<p>text about fast cars</p>
</section>
</body>
Upvotes: 50
Reputation: 2363
Section
mid
,left
,right
,etc..Article
Use this where you have independent content which make sense on its own .
Article has its own complete meaning.
Upvotes: 8
Reputation: 2989
A section is basically a wrapper for h1
(or other h
tags) and the content that corresponds to this. An article
is essentially a document within your document that is repeated or paginated...like each blog post on your document can be an article, or each comment on your document can be an article.
Upvotes: 6
Reputation: 27331
In the W3 wiki page about structuring HTML5, it says:
<section>
: Used to either group different articles into different purposes or subjects, or to define the different sections of a single article.
And then displays an image that I cleaned up:
It also describes how to use the <article>
tag (from same W3 link above):
<article>
is related to<section>
, but is distinctly different. Whereas<section>
is for grouping distinct sections of content or functionality,<article>
is for containing related individual standalone pieces of content, such as individual blog posts, videos, images or news items. Think of it this way - if you have a number of items of content, each of which would be suitable for reading on their own, and would make sense to syndicate as separate items in an RSS feed, then<article>
is suitable for marking them up.In our example,
<section id="main">
contains blog entries. Each blog entry would be suitable for syndicating as an item in an RSS feed, and would make sense when read on its own, out of context, therefore<article>
is perfect for them:
<section id="main">
<article>
<!-- first blog post -->
</article>
<article>
<!-- second blog post -->
</article>
<article>
<!-- third blog post -->
</article>
</section>
Simple huh? Be aware though that you can also nest sections inside articles, where it makes sense to do so. For example, if each one of these blog posts has a consistent structure of distinct sections, then you could put sections inside your articles as well. It could look something like this:
<article>
<section id="introduction">
</section>
<section id="content">
</section>
<section id="summary">
</section>
</article>
Upvotes: 239
Reputation: 390
My interpretation is: I think of YouTube it has a comment-section, and inside the comment-section there are multiple articles (in this case comments).
So a section is like a div-container that holds articles.
Upvotes: 2
Reputation: 17743
Sounds like you should wrap each of the "sections" (as you call them) in <article>
tags and entries in the article in <section>
tags.
The HTML5 spec says (Section):
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. [...]
Examples of sections would be chapters, the various tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page could be split into sections for an introduction, news items, and contact information.
Note: Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the element.
And for Article
The article element represents a 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.
I think what you call "sections" in the OP fit the definition of article as I can see them being independently distributable or reusable.
Update: Some minor text changes for article
in the latest editors draft for HTML 5.1 (changes in italic):
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.
Also, discussion on the Public HTML mailing list about article
in January and February of 2013.
Upvotes: 138
Reputation: 8153
also, for syndicated content "Authors are encouraged to use the article element instead of the section element when it would make sense to syndicate the contents of the element."
Upvotes: 2
Reputation: 8068
I like to stick with the standard meaning of the words used: An article
would apply to, well, articles. I would define blog posts, documents, and news articles as articles
. Sections on the other hand, would refer to layout/ux items: sidebar, header, footer would be sections. However this is all my own personal interpretation -- as you pointed out, the specification for these elements are not well defined.
Supporting this, the w3c defines an article
element as a section of content that can independently stand on its own. A blog post could stand on it's own as a valuable and consumable item of content. However, a header would not.
Here is an interesting article about one mans madness in trying to differenciate between the two new elements. The basic point of the article, that I also feel is correct, is to try and use what ever element you feel best actually represents what it contains.
What’s more problematic is that article and section are so very similar. All that separates them is the word “self-contained”. Deciding which element to use would be easy if there were some hard and fast rules. Instead, it’s a matter of interpretation. You can have multiple articles within a section, you can have multiple sections within and article, you can nest sections within sections and articles within sections. It’s up to you to decide which element is the most semantically appropriate in any given situation.
Here is a very good answer to the same question here on SO
Upvotes: 26