When do I put <h1>-<h6> inside an <header> element?

和自甴很熟 提交于 2019-12-11 04:15:54

问题


When do I put headings inside a header element? I can't understand it, sometimes it seems to me that each heading has to be between header tags.

Let's take this sidebar as example :


How to code it?

<aside>
  <header>
    <h1>How to format</h1>
  </header>
</aside>

or

<aside>
  <h1>How to format</h1>
</aside>

回答1:


See the specification of the header element:

A header element is intended to usually contain the section's heading (an h1–h6 element), but this is not required. The header element can also be used to wrap a section's table of contents, a search form, or any relevant logos.

So you can have many header elements in a page (it's not limited to the top of the page), and you can use it around headings, but it's optional. This means both of your examples are correct.




回答2:


<header> give us some great added semantic value in order to describe the head of a section. You can use multiple headers in a web page, each of which will then become the <header> for that section of the document. So, using a <header> depends on the complexity of the section. The more complex it is, the more necessary the header element becomes. a <header> typically contains at least (but not restricted to) one heading tag (<h1> – <h6>).

hope it helps




回答3:


The header tag is for what displays at the top of the page of the page-what is sometimes called the banner. So put your h1-h6 tags in it when they are in the banner of your page.

Tags like header and footer are basically just div's renamed for organizational sanity. In the future search engines and browsers may look for header and footer tags to help them process and display information better. For now, it lets you avoid staring at a bunch of div tags.

<html>
<head>
</head>
<body>
    <header> Web page Banner</header>
    <div>Content</div>
    <footer>Web page bottom </footer> 
<body>
</html>

Instead of this...

<html>
<head>
</head>
<body>
    <div> Web page Banner</div>
    <div>Content</div>
    <div>Web page bottom </div> 
<body>
</html>


来源:https://stackoverflow.com/questions/25099551/when-do-i-put-h1-h6-inside-an-header-element

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