<section>
and <article>
ElementsIn this tutorial, we'll explore how to use the <section>
and <article>
HTML5 semantic tags effectively to structure the content in your HTML documents.
By the end of this tutorial, you will be able to:
- Understand the purpose of <section>
and <article>
tags.
- Correctly use these tags to structure your HTML documents.
- Learn best practices and tips for using these tags.
Basic understanding of HTML is required. If you're new to HTML, consider learning the basics before proceeding with this tutorial.
The <section>
element represents a standalone section of a document, such as chapters, tabs, or any other areas of a document that can be independently distributed or syndicated.
The <article>
element represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable.
Use <section>
to group related content. Each <section>
should be identified, typically by including a heading (<h1>-<h6>
element) as a child of the <section>
element.
<article>
should make sense on its own, and it should be possible to distribute it independently from the rest of the site. For instance, a blog post, a forum post, or a news story.
Example 1: Using <section>
element
<!-- A basic usage of section tag -->
<section>
<h1>Welcome to My Web Page</h1>
<p>This is the first section of the page.</p>
</section>
In this example, we define a section with a heading and a paragraph.
Example 2: Using <article>
element
<!-- A basic usage of article tag -->
<article>
<h2>My First Blog Post</h2>
<p>This is the content of my first blog post.</p>
</article>
In this example, we define an article with a blog post title and content.
<section>
is used to group related content.<article>
is used for content that makes sense on its own, and can be independently distributed.<h1>-<h6>
) as a child of the <section>
or <article>
element.To continue learning about HTML5 semantic elements, check the following resources:
1. MDN Web Docs: HTML elements reference
2. W3Schools: HTML Semantic Elements
Exercise 1: Create an HTML document with at least three <section>
elements, each containing a heading and a paragraph.
Exercise 2: Create an HTML document representing a blog page. Use <article>
elements for each blog post.
Exercise 3: Combine the usage of <section>
and <article>
in one HTML document. For example, create a document with multiple sections, and within each section, include an article.
Solutions and Explanations:
The solutions to these exercises will vary greatly depending on your creativity. Remember that <section>
is used to group related content and <article>
is used for content that can be independently distributed.