Sections and articles help organize web pages into meaningful parts. They make content easier to read and understand.
Section and article in HTML
<section> <!-- content here --> </section> <article> <!-- content here --> </article>
<section> is for grouping related content with a heading.
<article> is for self-contained content that can stand alone.
<section> <h2>About Us</h2> <p>We make great websites.</p> </section>
<article> <h1>My Blog Post</h1> <p>This is the content of the blog post.</p> </article>
<section> <h2>News</h2> <article> <h3>News Item 1</h3> <p>Details about news item 1.</p> </article> <article> <h3>News Item 2</h3> <p>Details about news item 2.</p> </article> </section>
This page uses <section> to group content about 'About Us' and 'Latest News'. Inside 'Latest News', each news item is an <article> because they are separate stories.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Section and Article Example</title> </head> <body> <header> <h1>Welcome to Our Website</h1> </header> <main> <section> <h2>About Us</h2> <p>We create simple and clear websites for everyone.</p> </section> <section> <h2>Latest News</h2> <article> <h3>New Website Launched</h3> <p>Our new website design is live now!</p> </article> <article> <h3>Upcoming Workshop</h3> <p>Join our free workshop next week.</p> </article> </section> </main> <footer> <p>Contact us at info@example.com</p> </footer> </body> </html>
Use headings inside <section> and <article> to describe the content.
Screen readers use these tags to help users navigate the page.
Don't use <section> or <article> just to style content; they should have meaning.
<section> groups related content with a heading.
<article> is for independent, self-contained content.
Using these tags improves page structure and accessibility.
Practice
Solution
Step 1: Understand the purpose of <section>
The <section> tag is designed to group related content, often with a heading, to organize the page logically.Step 2: Compare with other tags
<article> is for independent content, <div> and <span> are generic containers without semantic meaning.Final Answer:
<section> -> Option BQuick Check:
Grouping related content = <section> [OK]
- Confusing <article> with <section>
- Using <div> instead of semantic tags
- Thinking <span> can group block content
Solution
Step 1: Identify correct opening tag syntax
The correct way to start an article is with an opening tag <article> without a slash.Step 2: Check other options for correctness
<article/> is self-closing and invalid for this tag; <article></article> is a full element, not just start; <article></section> mismatches tags.Final Answer:
<article> -> Option DQuick Check:
Opening tag syntax = <article> [OK]
- Using self-closing syntax for non-void tags
- Mismatching start and end tags
- Confusing full element with just opening tag
<section>
<h2>News</h2>
<article>
<h3>Article 1</h3>
<p>Content of article 1.</p>
</article>
<article>
<h3>Article 2</h3>
<p>Content of article 2.</p>
</article>
</section>Solution
Step 1: Understand the structure of the code
The <section> contains a heading <h2> 'News' and two <article> elements each with their own <h3> and paragraph.Step 2: Predict browser rendering
The browser will display the 'News' heading, then each article's heading and paragraph as separate blocks.Final Answer:
A heading 'News' with two separate articles each having their own heading and paragraph -> Option AQuick Check:
Section with heading + articles = full content shown [OK]
- Thinking articles are hidden by default
- Ignoring the section heading
- Assuming syntax error from nested tags
<section>
<article>
<h2>Title</h3>
<p>Paragraph content.</p>
</article>
</section>Solution
Step 1: Check tag pairs for correctness
The heading starts with <h2> but incorrectly closes with </h3>, which is a mismatch.Step 2: Verify other tags
The <article> and <section> tags are properly opened and closed; paragraph tag is valid inside article.Final Answer:
Mismatched heading tags: <h2> opened but </h3> closed -> Option CQuick Check:
Matching tags must open and close the same [OK]
- Ignoring tag mismatch errors
- Assuming section cannot contain article
- Thinking paragraph is invalid inside article
Solution
Step 1: Understand semantic roles of <section> and <article>
<section> groups related content; <article> is for independent, self-contained content like blog posts.Step 2: Analyze each option's structure
<section>\n <article>\n <h2>Post Title</h2>\n <p>By Author</p>\n <p>Post content here.</p>\n </article>\n <article>\n <h2>Another Post</h2>\n <p>By Another Author</p>\n <p>More content here.</p>\n </article>\n</section> uses one <section> to group all posts, each post is an <article> with title, author, and content. This is semantically correct. <article>\n <section>\n <h2>Post Title</h2>\n <p>By Author</p>\n <p>Post content here.</p>\n </section>\n <section>\n <h2>Another Post</h2>\n <p>By Another Author</p>\n <p>More content here.</p>\n </section>\n</article> wrongly nests <section> inside <article>. <div>\n <div>\n <h2>Post Title</h2>\n <p>By Author</p>\n <p>Post content here.</p>\n </div>\n <div>\n <h2>Another Post</h2>\n <p>By Another Author</p>\n <p>More content here.</p>\n </div>\n</div> uses generic <div> without semantic meaning. <section>\n <section>\n <h2>Post Title</h2>\n <p>By Author</p>\n <p>Post content here.</p>\n </section>\n <section>\n <h2>Another Post</h2>\n <p>By Another Author</p>\n <p>More content here.</p>\n </section>\n</section> nests <section> inside <section> for posts, which is less clear than using <article> for posts.Final Answer:
Option A: section grouping articles for posts -> Option AQuick Check:
Posts = articles inside a section [OK]
- Using <section> instead of <article> for posts
- Nesting <section> inside <article> incorrectly
- Using only <div> without semantic tags
Ready to prove it?
Pass the test and this pattern moves unknown
