问题
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 section, nav, article and body (There are probably some more too).
So, I have a couple of navigation areas and my question is; would it be wise to have a heading but just hide it from the browser?
回答1:
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.
来源:https://stackoverflow.com/questions/23756361/html-5-document-outlining-algorithm