I'm currently cleaning up my personal blog and I'm trying to make the HTML adhere correctly to HTML standards. The blog structure is simple. I have a home page that links to blog posts and a page for each blog post.
For the blog post pages. I'm not sure if I should use the <main>
or <article>
tag to wrap all of the content.
I would either use
<html>
<body>
{ heading, navigation, etc. }
<main>
<h1>{title}</h1>
<time datetime="{publish date}">{human readable publish date}</time>
{content}
</main>
</body>
</html>
or
<html>
<body>
{ heading, navigation, etc. }
<article>
<h1>{title}</h1>
<time datetime="{publish date}">{human readable publish date}</time>
{content}
</article>
</body>
</html>
If I read the HTML specification for <article>
correctly,
using <main>
seems to be the better option because <article>
is meant to separate independent self-contained parts of an HTML document while <main>
is meant to indicate where the main part of the document or meat of the document.
The reason I'm hesitating is because <article>
works with the <time>
element to allow me to specify when the post was published.
From MDN (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article):
The publication date and time of an element can be described using the datetime attribute of a element. Note that the pubdate attribute of is no longer a part of the W3C HTML 5 standard.
(Note that your two examples create a different document outline.)
Use both. The elements serve different purposes and work fine together.
<main>
<article>
</article>
</main>
If you can only use one element for some reason, go with main
, because the use of the heading creates an implicit section (where article
would make this section explicit), and all article
-related features (like address
and bookmark
) also work if the body
is the nearest section. Note that there is no time
-related feature for article
anymore (early HTML5 drafts had the pubdate
attribute, which offered such a feature, but it got removed).