HTML 5 Document Outlining Algorithm

前端 未结 1 782
孤街浪徒
孤街浪徒 2021-01-06 07:58

I am building a new site and I have recently started looking at the Document Outlining Algorithm. It states that all sections should have a header, sections include

相关标签:
1条回答
  • 2021-01-06 08:09

    Every sectioning content element "longs" for a heading element (h1-h6). But you are not required to provide one.

    If you don’t provide a heading element for a section, this section will have an implied heading. HTML5 outline tools might display those implied headings as "Untitled section" or "Empty title".

    So when you always use sectioning content elements where possible, your document outline will be correct even if you don’t provide a single heading element (of course this is not recommended; headings are very useful!).

    These two documents will have the same outline hierarchy:

    <!-- DOCUMENT A -->
    <body>
      <article>
      </article>
      <nav>
      </nav>
    </body>
    
    <!-- DOCUMENT B -->
    <body>
      <h1>site title</h1>
      <article><h1>main content title</h1></article>
      <nav><h1>navigation title</h1></nav>
    </body>
    
    Outline for DOCUMENT A       Outline for DOCUMENT B
    1. untitled (body)           1. "site title" (body)
      1. untitled (article)        1. "main content title" (article)
      2. untitled (nav)            2. "navigation title" (nav)
    

    So it’s fine to use nav without any heading. But if you think a heading might be useful for consumers without CSS support (e.g., screen reader users or search engines), you can provide a heading and hide it visually.

    0 讨论(0)
提交回复
热议问题