A Look Into: HTML5 <article> and <section> Elements

HTML5 comes with a bunch of new elements with more to be recommended in the future. However, there are some elements that might be a little confusing in their implementation, including the following two new elements: &lt;article&gt; and &lt;section&gt;.

Some most frequently asked questions I found in the forums are: In what circumstances should we use these elements? And similarly, How do we use these elements correctly?

A Look Into Proper HTML5 Semantics

A Look Into Proper HTML5 Semantics

If you carefully plan the structure of your HTML documents, you can help computers make sense of the... Read more

&lt;section&gt; Element

This is probably one of the most ambiguous elements. All these years, we have used &lt;div&gt; element for sectioning in our web structure. So the question arises as how is it different than &lt;div&gt; element and when should we use this element apart from &lt;div&gt; element.

To demystify it, we need to refer to the official documentation. According to WHATWG documentation, the &lt;section&gt; is described as follows:

“The &lt;section&gt; element represents a generic section of a document or application. ~ WHATWG”

From that description we can conclude that the &lt;section&gt; element is definitely intended for sectioning, more or less like a &lt;div&gt; element. But there is an exception to it. The documentation added some specific extra note that said:

“When an element is needed only 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 would be listed explicitly… ~ WHATWG”

At this point, things got lighter, and we can summarize that description in two points:

  1. Although the section element is technically styleable, it is suggested to use &lt;div&gt; instead when we are more likely to apply heavy styles or script to the element.
  2. Similar to &lt;li&gt; element, the general idea of section element is to list content.

So in real cases, one of the sensible reason to use &lt;section&gt; element is to structure list of blog post content, as shown in the following code snippet:

&lt;div class="blog"&gt;
	&lt;section class="post"&gt;
		&lt;h2 class="post-title"&gt;Blog Post Title&lt;/h2&gt;
		&lt;p class="post-excerpt"&gt;Ice cream tart powder jelly-o. 
		Gummies chocolate cake ice cream cookie halvah tiramisu jelly-o.&lt;/p&gt;
	&lt;/section&gt;
	&lt;section class="post"&gt;
		&lt;h2 class="post-title"&gt;Blog Post Title&lt;/h2&gt;
		&lt;p class="post-excerpt"&gt;Ice cream tart powder jelly-o. 
		Gummies chocolate cake ice cream cookie halvah tiramisu jelly-o.&lt;/p&gt;
	&lt;/section&gt;
	&lt;section class="post"&gt;
		&lt;h2 class="post-title"&gt;Blog Post Title&lt;/h2&gt;
		&lt;p class="post-excerpt"&gt;Ice cream tart powder jelly-o. 
		Gummies chocolate cake ice cream cookie halvah tiramisu jelly-o.&lt;/p&gt;
	&lt;/section&gt;
&lt;/div&gt;

This is just an example; we can use this element for other purposes.

&lt;article&gt; Element

The name itself is quite self-explanatory, but let’s see how the official documentation describes it:

“A self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g., in syndication. This could 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.

From the above explanation, we can conclude that &lt;article&gt; element is exclusively recommended to be used for structuring articles, especially the article that we are likely to syndicate, such as a blog post, page content, or forum posts.

The following example shows how we structure a blog post content with &lt;article&gt;.

&lt;article class="post"&gt;
	&lt;header&gt;
	&lt;h1&gt;This is Blog Post Title&lt;/h1&gt;
	&lt;div class="post-meta"&gt;
		&lt;ul&gt;
			&lt;li class="author"&gt;Author Name&lt;/li&gt;
			&lt;li class="categories"&gt;Save in Categories&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
	&lt;/header&gt;

	&lt;div class="post-content"&gt;
		Sweet roll halvah biscuit toffee liquorice tart pudding sesame snaps. 
		Biscuit powder jelly-o fruitcake faworki chocolate bar. Pudding oat 
		cake tootsie roll sesame snaps lollipop gingerbread bonbon. Gummies 
		halvah gummies danish biscuit applicake gingerbread jelly-o pastry.
	&lt;/div&gt;

&lt;/article&gt;

Furthermore, the &lt;article&gt; element can be used in conjunction with the section element, so the article can be divided into several sections with &lt;section&gt; element when the case is reasonable to do so, such as the example below.

&lt;article class="post"&gt;
	&lt;header&gt;
	&lt;h1&gt;This is Blog Post Title&lt;/h1&gt;
	&lt;div class="post-meta"&gt;
		&lt;ul&gt;
			&lt;li class="author"&gt;Author Name&lt;/li&gt;
			&lt;li class="categories"&gt;Save in Categories&lt;/li&gt;
		&lt;/ul&gt;
	&lt;/div&gt;
	&lt;/header&gt;

	&lt;div class="post-content"&gt;
		&lt;section&gt;
		&lt;h2&gt;This is the Sub-Heading&lt;/h2&gt;
		Sweet roll halvah biscuit toffee liquorice tart pudding sesame snaps. 
		Biscuit powder jelly-o fruitcake faworki chocolate bar. Pudding oat cake 
		tootsie roll sesame snaps lollipop gingerbread bonbon. Gummies halvah 
		gummies danish biscuit applicake gingerbread jelly-o pastry.
		&lt;/section&gt;

		&lt;section&gt;
		&lt;h4&gt;This is another Sub-Heading&lt;/h4&gt;
		Topping cheesecake sweet pie carrot cake sweet roll. Gummi bears lemon drops
		toffee sesame snaps tart topping chupa chups apple pie gummies. Wafer chocolate
		cake. Sugar plum chocolate bar topping ice cream carrot cake danish bonbon. 
		Cheesecake gummi bears dragée jujubes dragée dragée brownie jelly biscuit. Powder croissant jelly beans pastry.
		&lt;/section&gt;
	&lt;/div&gt;

&lt;/article&gt;

Conclusion

All the new elements in HTML5 are invented to make the web structure more Semantic as how the founder of the World Wide Web and the director of W3C has prevised. There are still being debated among web developers and designers, though, on how to apply these elements more correctly, some say this, others might say differently.

However, don’t get confused with the idea. As I have mentioned above, as long as the case is reasonable to use them and you see that the structure is quite meaningful when you examine it, then go for it. After all, it does not matter in the end.

WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail