--- title:
HTML <h1>
–<h6>
标题(Heading)元素呈现了六个不同的级别的标题,<h1>
级别最高,而 <h6>
级别最低。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
内容类别 | 流式内容, 标题内容,可触知的内容。 |
---|---|
允许内容 | 短语内容 |
标签省略 | {{no_tag_omission}} |
允许的父元素 | 任何接受流内容的元素;不要把它作为 {{HTMLElement("hgroup")}} 元素的子元素, 这种做法已经被废弃了。 |
允许的 ARIA roles | {{ARIARole("tab")}}, {{ARIARole("presentation")}} |
DOM 接口 | {{domxref("HTMLHeadingElement")}} |
该元素包含所有全局特性。
align属性已废弃;不要继续使用它。
<h1>
开始,接下来依次使用 <h2>
等等。<h2>
。详情请参考 {{SectionOnPage("/zh-CN/docs/Web/Guide/HTML/Using_HTML_sections_and_outlines", "Defining sections")}}。
下面的代码展示了所有可用的标题级别。
<h1>一级标题</h1> <h2>二级标题</h2> <h3>三级标题</h3> <h4>四级标题</h4> <h5>五级标题</h5> <h6>六级标题</h6>
下面是这些代码的结果:
{{ EmbedLiveSample('All_headings', '280', '300', '') }}
下面的代码展示了几个具有部分内容的标题。
<h1>Heading elements</h1> <h2>Summary</h2> <p>Some text here...</p> <h2>Examples</h2> <h3>Example 1</h3> <p>Some text here...</p> <h3>Example 2</h3> <p>Some text here...</p> <h2>See also</h2> <p>Some text here...</p>
下面是代码的运行结果:
{{ EmbedLiveSample('Example_page', '280', '480', '') }}
A common navigation technique for users of screen reading software is jumping from heading to heading to quickly determine the content of the page. Because of this, it is important to not skip one or more heading levels. Doing so may create confusion, as the person navigating this way may be left wondering where the missing heading is.
<h1>Heading level 1</h1> <h3>Heading level 3</h3> <h4>Heading level 4</h4>
<h1>Heading level 1</h1> <h2>Heading level 2</h2> <h3>Heading level 3</h3>
Headings may be nested as subsections to reflect the organization of the content of the page. Most screen readers can also generate an ordered list of all the headings on a page, which can help a person quickly determine the hierarchy of the content:
h1
Beetles
h2
Etymologyh2
Distribution and Diversityh2
Evolution
h3
Late Paleozoich3
Jurassich3
Cretaceoush3
Cenozoich2
External Morphology
h3
Head
h4
Mouthpartsh3
Thorax
h4
Prothoraxh4
Pterothoraxh3
Legsh3
Wingsh3
AbdomenWhen headings are nested, heading levels may be "skipped" when closing a subsection.
Another common navigation technique for users of screen reading software is to generate a list of sectioning content and use it to determine the page's layout.
Sectioning content can be labeled using a combination of the aria-labelledby
and {{htmlattrxref("id")}} attributes, with the label concisely describing the purpose of the section. This technique is useful for situations where there is more than one sectioning element on the same page.
<header> <nav aria-labelledby="primary-navigation"> <h2 id="primary-navigation">Primary navigation</h2> <!-- navigation items --> </nav> </header> <!-- page content --> <footer> <nav aria-labelledby="footer-navigation"> <h2 id="footer-navigation">Footer navigation</h2> <!-- navigation items --> </nav> </footer>
In this example, screen reading technology would announce that there are two {{HTMLElement("nav")}} sections, one called "Primary navigation" and one called "Footer navigation". If labels were not provided, the person using screen reading software may have to investigate each nav
element's contents to determine their purpose.
规范 | 状态 | 注释 |
---|---|---|
{{SpecName('HTML WHATWG', 'sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements', '<h1>, <h2>, <h3>, <h4>, <h5>, and <h6>')}} | {{Spec2('HTML WHATWG')}} | |
{{SpecName('HTML5 W3C', 'sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements', '<h1>, <h2>, <h3>, <h4>, <h5>, and <h6>')}} | {{Spec2('HTML5 W3C')}} | |
{{SpecName('HTML4.01', 'struct/global.html#h-7.5.5', '<h1>, <h2>, <h3>, <h4>, <h5>, and <h6>')}} | {{Spec2('HTML4.01')}} |
{{Compat("html.elements.h1")}}