{"id":78,"date":"2015-10-12T11:53:00","date_gmt":"2015-10-12T06:23:00","guid":{"rendered":"https:\/\/www.swaragh.com\/blog\/?p=78"},"modified":"2023-03-10T14:12:44","modified_gmt":"2023-03-10T08:42:44","slug":"grouping-content-in-html5-article-or-div-or-section","status":"publish","type":"post","link":"https:\/\/www.swaragh.com\/blog\/grouping-content-in-html5-article-or-div-or-section\/","title":{"rendered":"GROUPING CONTENT IN HTML5 \u2013 ARTICLE OR DIV OR SECTION?"},"content":{"rendered":"\n<p>HTML5 was a stepping stone to follow the usage of semantic code. It became a champion on how your page was structured and tags you use convey the meaning to browsers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overview of The Elements<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">div<\/h3>\n\n\n\n<p>The &lt;div&gt; element is the most general-purpose element. It has no special meaning. Its purpose is to group content that is not semantically related. Because it is essentially meaningless to screen readers, it should be sparingly used.<\/p>\n\n\n\n<p>Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable.<\/p>\n\n\n\n<p><a href=\"http:\/\/www.w3.org\/TR\/html5\/grouping-content.html#the-div-element%E2%80%9D%20target=%E2%80%9C_blank\" target=\"_blank\" rel=\"noopener\">W3C Recommendation<\/a><\/p>\n\n\n\n<p>The &lt;div&gt; element, therefore, is mainly used to group content for targeting with CSS. For example, as a styling container for other elements.<\/p>\n\n\n\n<p>&lt;div class=\u201dmodal-container\u201d&gt;<\/p>\n\n\n\n<p>&lt;section class=\u201dmodal\u201d&gt;<\/p>\n\n\n\n<p>&lt;h1&gt;Modal Title&lt;\/h1&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Text goes here&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p>&lt;\/div&gt;<\/p>\n\n\n\n<p><strong>section<\/strong><\/p>\n\n\n\n<p>The &lt;section&gt; element is slightly more specific that a &lt;div&gt;. It is applied to a generic section of content that <em>can<\/em> be grouped together in a semantically meaningful way.<\/p>\n\n\n\n<p>A general thumb rule is that the section element is appropriate only if the element\u2019s contents are listed explicitly in the document\u2019s outline.<\/p>\n\n\n\n<p><a href=\"http:\/\/www.w3.org\/TR\/html5\/sections.html#the-section-element%E2%80%9D%20target=%E2%80%9C_blank\" target=\"_blank\" rel=\"noopener\">W3C Recommendation<\/a><\/p>\n\n\n\n<p>Because the contents of a &lt;section&gt; are meaningful when grouped together, they should have a \u201ctheme\u201d. A &lt;section&gt;\u2019s \u201ctheme\u201d should be defined by including a heading element within the element, often immediately after the opening tag.<\/p>\n\n\n\n<p>&lt;section class=\u201dcontact\u201d&gt;<\/p>\n\n\n\n<p>&lt;h1&gt;Enter Your Details&lt;\/h1&gt;<\/p>\n\n\n\n<p>&lt;form&gt; &lt;!\u2013 \u2026 \u2013&gt; &lt;\/form&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p><strong>article<\/strong><\/p>\n\n\n\n<p>The &lt;article&gt; element is even more specific than a &lt;section&gt;. It is also applied to a section of content that is semantically related, and should also have a heading. However, this section of content should additionally be \u201cself-contained\u201d. This means that the contents of an &lt;article&gt; should be able to be isolated from the rest of the page and still be meaningful.<\/p>\n\n\n\n<p>One common purpose for an &lt;article&gt; is in marking content for syndication. For example, marking a blog post.<\/p>\n\n\n\n<p>&lt;article class=\u201dblog\u201d&gt;<\/p>\n\n\n\n<p>&lt;h1&gt;Blog Detail&lt;\/h1&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit\u2026&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Quae similitudo in genere etiam humano apparet. Est, ut dicis, inquam\u2026&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/article&gt;<\/p>\n\n\n\n<p><strong>div or article or section?<\/strong><\/p>\n\n\n\n<p>So which should you use and when?<\/p>\n\n\n\n<p>If the content within the element is not <strong>semantically related<\/strong>, then use a &lt;div&gt;. If the semantically related content is also able to be <strong>self-contained<\/strong>, then use an &lt;article&gt;. Otherwise, use a &lt;section&gt;.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/TX3_VeYYuLPbeML5m9AopFLf0qoWTuBjbw9OpwlmGM6c7pKUEPXIVIhv0YWZaUUA8dNUJIe6oQeYLH2atFJ2UatdK_c7h43pk7-0XK192lhnaBEdMSi8MZUrR0UEeUX4roIiK6v0\" alt=\"html5 section article div\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Combining the Elements<\/strong><\/h2>\n\n\n\n<p>Where things can get a bit complicated is when we try to combine the different elements together.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Articles within an Article<\/strong><\/h3>\n\n\n\n<p>We can nest &lt;article&gt; elements within each other. Although still self-contained, inner &lt;article&gt;s are assumed to be related to the contents of the outer &lt;article&gt;.<\/p>\n\n\n\n<p>For example, if there is a long excerpt within a blog post that is written by another person, it could be contained in its own &lt;article&gt;.<\/p>\n\n\n\n<p>&lt;article&gt;<\/p>\n\n\n\n<p>&lt;h1&gt;Article Title&lt;\/h1&gt;<\/p>\n\n\n\n<p>&lt;p class=\u201dauthor\u201d&gt;John Smith&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;article&gt;<\/p>\n\n\n\n<p>&lt;h2&gt;Another Article&lt;\/h2&gt;<\/p>\n\n\n\n<p>&lt;p class=\u201dauthor\u201d&gt;Jane Doe&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/article&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/article&gt;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Articles within a Section<\/strong><\/h3>\n\n\n\n<p>We can also have multiple &lt;article&gt; elements within a &lt;section&gt; element. A good example of this is a blog homepage showing the latest posts. The container for all the latest posts would be a &lt;section&gt;, whereas each individual post excerpt could be an &lt;article&gt;.<\/p>\n\n\n\n<p>&lt;section&gt;<\/p>\n\n\n\n<p>&lt;h1&gt;Latest Blog Posts&lt;\/h1&gt;<\/p>\n\n\n\n<p>&lt;article&gt;<\/p>\n\n\n\n<p>&lt;h2&gt;Blog Post Title&lt;\/h2&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. &lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/article&gt;<\/p>\n\n\n\n<p>&lt;article&gt;<\/p>\n\n\n\n<p>&lt;h2&gt;Blog Post Title&lt;\/h2&gt;<\/p>\n\n\n\n<p>&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. &lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/article&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Sections within an Article<\/strong><\/h3>\n\n\n\n<p>Each individual &lt;article&gt; may also have &lt;section&gt; elements within it. For example, this particular post could be written like this \u2013<\/p>\n\n\n\n<p>&lt;article&gt;<\/p>\n\n\n\n<p>&lt;h1&gt;Sectioning Content in HTML5 \u2013 div or section or article?&lt;\/h1&gt;<\/p>\n\n\n\n<p>&lt;section&gt;<\/p>\n\n\n\n<p>&lt;h2&gt;Overview of the Elements&lt;\/h2&gt;<\/p>\n\n\n\n<p>&lt;section&gt;<\/p>\n\n\n\n<p>&lt;h3&gt;div&lt;\/h3&gt;<\/p>\n\n\n\n<p>&lt;p&gt;The div element is the most general purpose element.&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p>&lt;section&gt;<\/p>\n\n\n\n<p>&lt;h3&gt;section&lt;\/h3&gt;<\/p>\n\n\n\n<p>&lt;p&gt;The section element is slightly more specific that a div&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p>&lt;section&gt;<\/p>\n\n\n\n<p>&lt;h3&gt;article&lt;\/h3&gt;<\/p>\n\n\n\n<p>&lt;p&gt;The article element is even more specific than a section&lt;\/p&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p>&lt;section&gt;<\/p>\n\n\n\n<p>&lt;h2&gt;div or section or article?&lt;\/h2&gt;<\/p>\n\n\n\n<p>&lt;!\u2013 \u2026 \u2013&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p>&lt;section&gt;<\/p>\n\n\n\n<p>&lt;h2&gt;Combining the Elements&lt;\/h2&gt;<\/p>\n\n\n\n<p>&lt;!\u2013 \u2026 \u2013&gt;<\/p>\n\n\n\n<p>&lt;\/section&gt;<\/p>\n\n\n\n<p>&lt;\/article&gt;<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML5 was a stepping stone to follow the usage of semantic code. It became a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":171,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-78","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5"],"_links":{"self":[{"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/comments?post=78"}],"version-history":[{"count":3,"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":172,"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/posts\/78\/revisions\/172"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/media\/171"}],"wp:attachment":[{"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/media?parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/categories?post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.swaragh.com\/blog\/wp-json\/wp\/v2\/tags?post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}