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

北城以北 提交于 2019-12-01 11:08:54

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.

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.

unor

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.

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