Proper use of HTML heading tags

前端 未结 6 1209
天命终不由人
天命终不由人 2020-12-21 16:53

I\'m having trouble understanding the proper usage of HTML headings. I\'m using books and online resources to self-learn but there are slight discrepancies on how to use the

6条回答
  •  我在风中等你
    2020-12-21 17:10

    For HTML5:

    1. Decide which outline your document should have.
    2. Use heading elements (h1-h6) and sectioning content elements (section, article, aside, nav) to achieve this outline.

    Both statements you quoted are not correct or complete:

    • Regarding [1]: The h1 doesn’t have to be used only once per document (and it doesn’t have to be used for the "main heading").
    • Regarding [2]: The spec defines the heading rank, which doesn’t necessarily have to be importance.

    When you always wrap sections in a sectioning content element (the spec encourages to do this), so every section has one heading at maximum, then it doesn’t matter which heading rank you choose, but:

    […] authors are strongly encouraged to either use only h1 elements, or to use elements of the appropriate rank for the section's nesting level

    When you don’t always use sectioning content elements where appropriate, so a section has more than one heading, skipping heading levels (or using them for specifying "importance") can lead to an incorrect outline.

提交回复
热议问题