W3C validation says h1 in article is invalid

那年仲夏 提交于 2019-12-03 23:41:18

问题


I'm running my website through the W3C validation service. I'm getting an error message for the following HTML:

<section class="about">
  <article>
    <header>
    <h1>Mission</h1>
    </header>
    <div class="content">
      <p>bla bla bla</p>
    </div>
    <aside>
      <img src='/images/logo-hse-250x250.png' />
    </aside>
  </article>
</section>

The W3C validation error is:

Consider using the h1 element as a top-level heading only (all h1 elements are treated as top-level headings by many screen readers and other tools).

<h1>Mission</h1>

I thought with HTML5, it was allowed to use more than one h1 tag on a page. And that h1 tags could be used inside article elements.

Does anyone have a clue why W3C isn't validating this HTML?


回答1:


It is valid to use h1 there.

The W3C Markup Validator does report a warning, not an error. You can ignore warnings if you like to.

The HTML5 spec "encourages" authors to use "headings of the appropriate rank" instead of h1 everywhere. But an encouragement is not a normative requirement.




回答2:


<h1> Tag must be used as top-level heading, i.e, as page heading/tittle. Here you are the W3C Reference

That's is because SEO purposes; ensuring content is formatted in the best way possible to aid search engine indexing; and because technical correctness; ensuring that markup is written in accordance with the appropriate W3C spec.

Depending on the strucutre of your page, you can use more than one perhaps, but it's better not tu use more than one <h1> tag



来源:https://stackoverflow.com/questions/25996074/w3c-validation-says-h1-in-article-is-invalid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!