Junior
What is the difference between the article and section elements in HTML?
sobes.tech AI
Answer from AI
article is a self-contained, independent piece of content that can be distributed or reused outside the main context of a page. Examples include a blog post, news item, comment, or widget.
section is a thematic group of content. It can be a division on a page (e.g., "Introduction", "Contents", "Contacts") or a group of related paragraphs, images, etc. section often has a heading.
Main difference: article is a content unit that makes sense on its own, while section is a structural part of a page or document.
Example of usage:
<article>
<h2>Article Title</h2>
<p>Main text of the article...</p>
<section> <!-- Subsection within the article -->
<h3>Comments</h3>
<article> <!-- A separate comment as a self-contained element -->
<p>Comment text.</p>
</article>
</section>
</article>
<section> <!-- A separate section on the page, not related to the previous article -->
<h2>Section with additional information</h2>
<p>Additional information text...</p>
</section>