对于同时也是文章的页面的主要内容,使用 <main> 或 <article> 哪个更正确?

Is it more correct to use <main> or <article> for the main content of a page which is also an article?

我目前正在清理我的个人博客,并努力使 HTML 正确遵守 HTML 标准。博客结构简单。我有一个链接到博客 post 的主页和每个博客的页面 post.

对于博客 post 页。我不确定是否应该使用 <main><article> 标签来包装所有内容。

我会使用

<html>
<body>
  { heading, navigation, etc. }
  <main>
    <h1>{title}</h1>
    <time datetime="{publish date}">{human readable publish date}</time>

    {content}
  </main>
</body>
</html>

<html>
<body>
  { heading, navigation, etc. }
  <article>
    <h1>{title}</h1>
    <time datetime="{publish date}">{human readable publish date}</time>

    {content}
  </article>
</body>
</html>

如果我正确阅读 <article>HTML specification, 使用 <main> 似乎是更好的选择,因为 <article> 用于分隔 HTML 文档的独立自包含部分,而 <main> 用于指示主要部分的位置文档或文档的内容。

我犹豫的原因是 <article><time> 元素一起使用,允许我指定 post 的发布时间。

来自 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.

文章 - https://www.w3schools.com/tags/tag_article.asp

The article tag specifies independent, self-contained content.

An article should make sense on its own and it should be possible to distribute it independently from the rest of the site.

Potential sources for the article element:

Forum post, Blog post, News, story and Comment

主要 - https://www.w3schools.com/tags/tag_main.asp

The main tag specifies the main content of a document.

The content inside the main element should be unique to the document. It should not contain any content that is repeated across documents such as sidebars, navigation links, copyright information, site logos, and search forms.

Note: There must not be more than one main element in a document. The main element must NOT be a descendant of an article, aside, footer, header, or nav element.

如果你像博客一样重复post我个人会使用文章标签

The main content section consists of content that is directly related to or expands upon the central topic of a document or central functionality of an application.

来源:https://www.w3.org/TR/2012/WD-html-main-element-20121217

这基本上是: Main 标签就是您要查找的内容,因为它包装了您页面上的所有内容。文章标签确实在这个里面。 (您可以查看该来源中的示例 link)。

但不要将此作为一般规则。文章标签也可能工作正常,如此处所述

来源:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article

这完全取决于你的html结构

(请注意,您的两个示例创建了不同的文档大纲。)

两者都用。这些元素有不同的用途,并且可以很好地协同工作。

<main>
  <article>
  </article>
</main>

如果出于某种原因只能使用一个元素,请使用 main,因为使用标题会创建一个隐式部分(其中 article 会使该部分显式),并且所有如果 body 是最近的部分,article 相关功能(如 address and bookmark)也有效。请注意,article 不再有与 time 相关的功能(早期的 HTML5 草稿具有 pubdate 属性,它提供了这样的功能,但已被删除)。