Using <section> and <article> Elements

Tutorial 2 of 5

Using <section> and <article> Elements

1. Introduction

Goal

In this tutorial, we'll explore how to use the <section> and <article> HTML5 semantic tags effectively to structure the content in your HTML documents.

Learning Outcomes

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.

Prerequisites

Basic understanding of HTML is required. If you're new to HTML, consider learning the basics before proceeding with this tutorial.

2. Step-by-Step Guide

Concept

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.

Examples and Best Practices

  • 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.

3. Code Examples

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.

4. Summary

  • <section> is used to group related content.
  • <article> is used for content that makes sense on its own, and can be independently distributed.
  • Always try to include a heading (<h1>-<h6>) as a child of the <section> or <article> element.

Next Steps

To continue learning about HTML5 semantic elements, check the following resources:
1. MDN Web Docs: HTML elements reference
2. W3Schools: HTML Semantic Elements

5. Practice Exercises

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.