Is it necessary to have a heading of <section> in HTML5

妖精的绣舞 提交于 2019-12-01 08:53:18

问题


Is it necessary to have a heading of <section> in HTML5 like mentioned here http://blog.whatwg.org/is-not-just-a-semantic

Sometime on a page we have some elements which are related and can be combined in a <section id="semantic name"> instead <div id="semantic name"> But we don't have any Heading for that..

Is it OK to use <section> without having <h1>, <h2>, <h3> inside


回答1:


According to the HTML5 Doctor, you should not use <section> if there is no natural heading for it. Also, they say:

The section element represents a generic document or application section…The section element is not a generic container element. When an element is needed for styling purposes or as a convenience for scripting, authors are encouraged to use the div element instead.

Also, check out this nifty flowchart to decide what element is best to use in your situations.




回答2:


Its only necessary if it wont [validate] (http://validator.w3.org)

The use of section tags is to convey the structure of your content, like a book is split into chapters, paragraphs, etc

If your page is mash of images to look like a magazine cover you may not have a need for adding any sections. You'll most likely still want structure for navigation but that's not done using sections.

I would say any page containing chunks of text (most pages) should use a section tag rather than a div. keep the divs for controlling layout only.

My best advice is to see how your site looks in a text only browser, or other accessible client. It amazing how rubbish most sites are designed for accessibility. My take is that section tags are an attempt to improve that.




回答3:


No, it is not required.

You can easily check this by reading the definition of the section element ("should" is not "must") or by validating your HTML.

The W3C validator will report a warning when no heading is used, but a warning is not an error.



来源:https://stackoverflow.com/questions/8544671/is-it-necessary-to-have-a-heading-of-section-in-html5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!