Differences between Div section article in HTML5

Source: Internet
Author: User
When I first started to access HTML5, I was not very comfortable with its labels, and I was a little disgusted. Especially for the DIV, section, and Article labels, it is hard to figure out where to use them. Div

Html spec: "The DIV element has no special meaning at all ."

This tag is the most common and useful one. It does not have any semantics and is used as a hook for layout and styling or script ).

Section

Html spec: "The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading ."

Compared with Div's Silent Meaning, section is simply a div with semantics, but never think it is so simple. Section indicates a topic. It generally has a title. Here, we may think of a blogArticleOr can a single comment use section? Next, let's see:

"Authors are encouraged to use the article element instead of the section element when it wocould make sense to syndicate the contents of the elemen ."

When the element content is aggregated to be more explicit, use article to replace the section.

So when should the Section be used? Next, let's see:

"Examples of sections wocould be chapters, the varous tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page cocould be split into sections for an introduction, news items, and contact information."

Typical scenarios of section applications include the Chapter of the article, the tab in the tag dialog box, or the numbered part in the paper. The home page of a website can be divided into several parts: Overview, news, and contact information. In fact, I am very interested in the information here, because I feel that section and the artilce to be introduced below are more suitable for modular applications. This topic will be discussed in a special article later, and I will skip it for the time being.

Note that W3C also warned:

"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. A general rule is that the section element is appropriate only if the element's contents wocould be listed explicitly in the document's outline."

Section is not just a common container label. Div should be used when a label is used only for styling or convenient script usage. In general, when the element content explicitly appears in the document outline, section is applicable.

<Article>  
Article

Html spec: "The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication."

Article is a special section label. It has more explicit semantics than section. It represents an independent and complete related content block. In general, article includes the title part (usually included in the header) and sometimes footer. Although section is also a topic content, in terms of structure and content, article itself is independent and complete.

In the HTML spec, some articles are further described. "This cocould be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content ."

When articles are embedded with articles, in principle, the content of internal articles is related to the content of outer articles. For example, in a blog post, articles containing comments submitted by users should be included in articles containing blogs.

The question is, how does one calculate "complete independent content "? The simplest way to determine the content is to check whether it is complete in the RSS feed. Check whether the content is complete and independent from the context.

Example:

 
<Article>  
 
   
    
    

the very first rule of life

if there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. seriously.

...

comments

posted: george Washington

Yeah! Especially when talking about your lobbyist friends!

posted by: George Hammond

Hey, you have the same first name as me.

Summary

Div section article, the semantics is gradually enhanced from nothing. Div does not have any semantics and is only used as a styling or scripted hook. For a topic content, section is applicable. If this content can be separated from the context, as a complete piece of independent content, article is applicable. In principle, you can also use section when you can use article. But in fact, if you use article more appropriately, do not use section. The same is true for the use of nav and aside. These two labels are also special sections. If nav and aside are more suitable, do not use them.

It is easier to differentiate between Div, section, article, and other labels. It is difficult to differentiate section and article. In fact, the focus is to see if the content is separated from the whole content and can still exist as a complete and independent content, the focus here is on completeness. In fact, the content contained in a section can also be regarded as an independent part, but it can only be regarded as a part of the whole, and article is a complete whole.

In fact, sometimes everyone has their own opinions, so it is difficult to decide what to do?

One of the HTML5 design principles is specifically designed to solve similar situations:

Priority of constituencies)

"In case of conflict, consider users over authors over implementors over specifiers over theoretical purity. "In the event of a conflict, end users are given priority, followed by authors, followed by implementers, followed by standard makers, and finally theoretically completed.

We recommend that you read the HTML5 design principles several times. This is the final promise behind the numerous worlds.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.