开发者

In HTML5, is it better to use <section> and <h1> instead of <h2>–<h6>?

In studying up on HTML5's new section tag, I'm wondering about the handling of h1, h2, h3, h4, h5, and h6 tags...

The HTML5 specification says that "[h1, h2, etc.] elements represent headings for their sections" (http://www.w3.org/TR/html5/sections.html#the-h1-h2-h3-h4-h5-and-h6-elements). Further in the spec's "4.4.11 Headings and sections" section, there are cu开发者_如何学运维rrently three examples of structuring a document about apples.

If we follow the first specification, which states that heading elements "should represent headings for their sections," it seems the third apple example is the most correct structure (i.e., using h1 tags for the heading in each section and subsection). Using this logic it seems that the h2, h3, h4, h5, and h6 tags would be used rarely, if at all.

This is what I'm wondering: should h2, h3, h4, h5, or h6 tags really be used if, in reality, they are basically marking up subsections? Does it not make more sense to use section tags to separate sections, each with their own header, rather than relying on h2, h3, etc. to start implicit sections? (The "Headers and sections" section also talks about the sections implied by using h2, h3, etc.)

Perhaps it's my relational database knowledge causing a bias, but creating multiple header tags with numbers (h 1, h 2, h 3) seems like bad practice, when technically they are each heading their own section or subsection.

What are your thoughts?


It seems that the spec even states that h1 has preference over all the others:

Sections may contain headings of any rank, 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.

What disturbs me however is this:

Authors are also encouraged to explicitly wrap sections in elements of sectioning content, instead of relying on the implicit sections generated by having multiple headings in one element of sectioning content.

Now it is wonderful that we got section, article, nav and aside to use to prevent div-itis. But if we need to explicitly use a section element for each section than we end up with more section elements then we ever had divs. I feel a strong case of section-itis coming on.


I agree with @Robert. It sounds to me like a case for an "h" tag for use within sections, or h1..n tags for implied sections. Allowing hn in a section is just redundant.


There is an implied hierarchy when you use these tags. h2 sections are below h1; h3 is below h2, etc. They are sub-sections sub-sections. I'm not sure why this causes a disconnect. If you only ever have one level of sub-sections then you would only ever use h1.

I think what you are objecting to is the <section> tag can provide similar hierarchical functionality, but the <section> tag is new to HTML and (as is often the case) just because there is another way to do it does not mean the specification changes to break the old ways.


This may just be my interpretation of the new specs, but... it seems to me that the <h1>-<h6> tags are starting to be relegated to the duty of typographical hierarchy rather than true sectioning tag.

whatwg.org does clearly specify that the section tag can start with an H1 tag, which kind of flies in the face of what I have come to know of SEO best practices- only defining one per page.

This leads me to believe that this is the direction html could be moving... <section> is the "machine" readable component for a section and the heading tags will be the human friendly element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜