Skip to content

15. Grouping Text

Grouping text content is essential for creating well-organized, readable HTML documents. HTML provides various elements and techniques for grouping related text, making content easier to understand, style, and maintain. Understanding how to group text properly improves both structure and accessibility.

Group sentences into paragraphs:

<p>First paragraph with related content.</p>
<p>Second paragraph with different but related content.</p>

Group related content with sections:

<section>
<h2>Introduction</h2>
<p>Content...</p>
</section>
<section>
<h2>Main Content</h2>
<p>Content...</p>
</section>

Group independent content:

<article>
<h1>Article Title</h1>
<p>Article content...</p>
</article>

Group related content together:

<!-- Good: Logical grouping -->
<section>
<h2>About Us</h2>
<p>Company history...</p>
<p>Our mission...</p>
</section>

Use semantic elements:

<article>
<header>
<h1>Title</h1>
</header>
<section>
<h2>Section</h2>
<p>Content</p>
</section>
</article>