HTML5 标签顺序



你用哪个顺序写HTML5标签重要吗?

例如,nav 可以写在标题之前或部分写在导航之前吗?

我会说是的,因为标签本身表明它不是订单。

有兴趣听听其他人的想法,尤其是在SEO方面。

导航可以写在

标题之前还是部分写在导航之前吗?

是的。这是HTML5的改进之一:由于分段元素和大纲算法,我们不必再单独依赖标题(见下面的示例(。

但是,如果您并不总是(如果适用(使用分段元素并header/footer,则顺序在某些情况下可能很重要(例如HTML 4.01中的情况(。

SEO方面是一个完全不同的问题,一般无法回答,因为有无数的搜索引擎,他们可能会每天改变他们的解释。更好的地方可能是网站管理员SE。


以下示例创建相同的文档大纲:

<article id="example-1">
  <nav>…</nav> <!-- before the article heading -->
  <h1>My article</h1>
  <h2>Foo is great</h2>
  <p>…</p>
  <h2>Bar, too</h2>
  <p>…</p>
</article>
<article id="example-2">
  <h1>My article</h1>
  <nav>…</nav> <!-- after the article heading -->
  <h2>Foo is great</h2>
  <p>…</p>
  <h2>Bar, too</h2>
  <p>…</p>
</article>

相应的大纲是:

1. "My article" (article, h1)
  1.1 untitled (nav, no heading)
  1.2 "Foo is great" (implicit section; h2)
  1.3 "Bar, too" (implicit section; h2)

本示例创建一个不同的文档大纲,但文档含义(或者更好的是本质(是相同的:

<article id="example-3">
  <h1>My article</h1>
  <h2>Foo is great</h2>
  <p>…</p>
  <h2>Bar, too</h2>
  <p>…</p>
  <!-- article’s end --> <nav>…</nav>
</article>

大纲将是:

1. "My article" (article, h1)
  1.1 "Foo is great" (implicit section; h2)
  1.2 "Bar, too" (implicit section; h2)
  1.3 untitled (nav, no heading)

只要您不将nav嵌套在另一个分割元素中,它就可以出现在此article中的任何位置。


当然,除了header/footer和分段元素之外,顺序(嗯,内容顺序(是有意义的。

明显的例子:

<ol>
  <li>Foo</li>
  <li>Bar</li>
</ol>
<p>Then I danced.</p>
<p>Then I woke up.</p>
<h4>Noodle soup</h4>
<h3>Dreams</h3>

等。

像html,head和body这样的主要结构标签需要始终保持正确的顺序。但所有其他元素都无关紧要。您不应将网站内容放在 head 或 html 标记之前。将您的网站内容始终放在<body>...</body>部分。

就SEO而言,最好的做法始终是用干净,正确的代码编写网站,其中包含独特而良好的内容。

最新更新