Paragraphs & Headings
Headings and paragraphs are the backbone of any web page. They provide structure, hierarchy, and readability to text content. Headings break content into sections and tell users (and search engines) what each part of the page is about, while paragraphs deliver the actual readable content.
HTML provides six levels of headings, from <h1> (most important) to <h6> (least important), plus the <p> element for paragraphs. Together they form a semantic content hierarchy that is essential for accessibility and SEO.
Heading levels define a clear hierarchy from <h1> (top level) down to <h6> (deepest subsection). This hierarchy should mirror the outline of a book: one title (h1), chapters (h2), sections within chapters (h3), and so on.
| 1 | <h1>HTML Documentation Guide</h1> |
| 2 | <h2>Getting Started</h2> |
| 3 | <h3>Installing a Text Editor</h3> |
| 4 | <h3>Creating Your First File</h3> |
| 5 | <h2>Core Concepts</h2> |
| 6 | <h3>Document Structure</h3> |
| 7 | <h3>Elements and Tags</h3> |
| 8 | <h4>Block-Level Elements</h4> |
| 9 | <h4>Inline Elements</h4> |
| 10 | <h3>Attributes</h3> |
| 11 | <h4>Global Attributes</h4> |
| 12 | <h4>Event Handlers</h4> |
| 13 | <h2>Advanced Topics</h2> |
| 14 | <h3>Semantic HTML</h3> |
| 15 | <h3>Accessibility</h3> |
Each heading level represents a nesting depth. Going from <h1> to <h2> to <h3> creates a logical outline. Skipping levels (e.g., jumping from <h1> to <h3>) breaks the hierarchy and confuses screen readers.
best practice
The following preview demonstrates a proper heading hierarchy rendered with default browser styles:
Notice how the visual styling reinforces the hierarchy: <h1> is largest and boldest, while each subsequent level decreases in prominence. Screen readers use a similar mental model to help users navigate.
The <p> element represents a paragraph of text. It is a block-level element, meaning it starts on a new line and takes up the full width available. Browsers add default margins above and below paragraphs to create visual separation.
| 1 | <p>This is a paragraph of text. Browsers automatically add margins above and below each paragraph to create visual spacing between blocks of text.</p> |
| 2 | |
| 3 | <p>Paragraphs can contain inline elements like <strong>bold text</strong>, <em>italicized text</em>, <a href="#">links</a>, and <span style="color: #00FF41;">styled spans</span>.</p> |
| 4 | |
| 5 | <p>Empty paragraphs should be avoided. Use CSS margin or padding for spacing instead.</p> |
Paragraphs should not be nested inside other paragraphs, and they should not contain block-level elements like <div>, other <p> tags, or headings. The HTML parser will automatically close a <p> tag when encountering a nested block-level element.
The <br> element inserts a single line break within a paragraph. It is a void element (no closing tag) and should be used sparingly. Use separate <p> elements for distinct paragraphs, not multiple <br> tags for spacing.
| 1 | <!-- Correct: separate paragraphs --> |
| 2 | <p>This is the first paragraph of text. It contains several sentences that form a cohesive idea.</p> |
| 3 | <p>This is the second paragraph. Using separate p elements is semantically correct.</p> |
| 4 | |
| 5 | <!-- Acceptable use of br: addresses, poems, code snippets --> |
| 6 | <p> |
| 7 | John Doe<br> |
| 8 | 123 Main Street<br> |
| 9 | Springfield, IL 62701 |
| 10 | </p> |
| 11 | |
| 12 | <p> |
| 13 | Roses are red,<br> |
| 14 | Violets are blue,<br> |
| 15 | HTML is fun,<br> |
| 16 | And so are you. |
| 17 | </p> |
| 18 | |
| 19 | <!-- Incorrect: using br for spacing between paragraphs --> |
| 20 | <p>First paragraph text.</p> |
| 21 | <br><br> |
| 22 | <p>Second paragraph text.</p> |
info
The <hr> element represents a thematic break in the content, typically displayed as a horizontal line. It signifies a shift in topic or section within a page:
| 1 | <section> |
| 2 | <h2>Chapter 1: The Beginning</h2> |
| 3 | <p>Content for the first chapter goes here.</p> |
| 4 | </section> |
| 5 | |
| 6 | <hr> |
| 7 | |
| 8 | <section> |
| 9 | <h2>Chapter 2: The Middle</h2> |
| 10 | <p>Content for the second chapter begins after the thematic break.</p> |
| 11 | </section> |
The <hr> element is semantic, not presentational. It should be used when there is a thematic shift in content, not merely for decorative line separation. For visual-only lines, use CSS borders.
The <pre> element displays text exactly as it appears in the HTML source, preserving whitespace, line breaks, and indentation. It is commonly used for code blocks, ASCII art, and any text where formatting matters:
| 1 | <pre> |
| 2 | function greet(name) { |
| 3 | console.log("Hello, " + name + "!"); |
| 4 | return true; |
| 5 | } |
| 6 | |
| 7 | greet("World"); |
| 8 | </pre> |
| 9 | |
| 10 | <pre> |
| 11 | ┌─────┬─────┬─────┐ |
| 12 | │ 1 │ 2 │ 3 │ |
| 13 | ├─────┼─────┼─────┤ |
| 14 | │ 4 │ 5 │ 6 │ |
| 15 | ├─────┼─────┼─────┤ |
| 16 | │ 7 │ 8 │ 9 │ |
| 17 | └─────┴─────┴─────┘ |
| 18 | </pre> |
Text inside <pre> is displayed in a monospace font by default. You can nest <code> inside <pre> to add semantic meaning for code snippets, and you can use CSS to customize the font, colors, and background.
| 1 | <!-- Best practice for code blocks --> |
| 2 | <pre><code>const express = require('express'); |
| 3 | const app = express(); |
| 4 | |
| 5 | app.get('/', (req, res) => { |
| 6 | res.send('Hello World'); |
| 7 | }); |
| 8 | |
| 9 | app.listen(3000);</code></pre> |
info
The <blockquote> element represents a section of content quoted from another source. Use the cite attribute to reference the source URL:
| 1 | <blockquote cite="https://example.com/source"> |
| 2 | <p>The best way to predict the future is to create it.</p> |
| 3 | <footer>— <cite>Abraham Lincoln</cite>, <a href="https://example.com/source">1864 Address</a></footer> |
| 4 | </blockquote> |
| 5 | |
| 6 | <blockquote> |
| 7 | <p>HTML is the unifying language of the World Wide Web. It gives structure to content and meaning to text.</p> |
| 8 | </blockquote> |
For shorter inline quotations, use the <q> element, which automatically adds quotation marks:
| 1 | <p> |
| 2 | As Tim Berners-Lee said, <q cite="https://example.com">The Web does not just connect machines, it connects people.</q> |
| 3 | </p> |
Browsers automatically add the appropriate quotation marks for <q> based on the document language (e.g., curly quotes for English, guillemets for French). The cite attribute on <blockquote> and <q> provides a machine-readable source URL.
Following heading best practices ensures your content is accessible, SEO-friendly, and well-structured:
best practice
Combining headings with semantic HTML elements creates a rich, meaningful document structure. Use <section>, <article>, <nav>, and <aside> to group related content:
| 1 | <article> |
| 2 | <h1>How to Write Semantic HTML</h1> |
| 3 | <p>Semantic HTML means using the correct elements for their intended purpose.</p> |
| 4 | |
| 5 | <section> |
| 6 | <h2>Why Semantics Matter</h2> |
| 7 | <p>Semantic HTML improves accessibility, SEO, and maintainability.</p> |
| 8 | |
| 9 | <section> |
| 10 | <h3>Accessibility Benefits</h3> |
| 11 | <p>Screen readers use semantic elements to provide navigation.</p> |
| 12 | </section> |
| 13 | |
| 14 | <section> |
| 15 | <h3>SEO Benefits</h3> |
| 16 | <p>Search engines use heading structure to understand page content.</p> |
| 17 | </section> |
| 18 | </section> |
| 19 | |
| 20 | <section> |
| 21 | <h2>Common Semantic Elements</h2> |
| 22 | <ul> |
| 23 | <li><header> — introductory content</li> |
| 24 | <li><main> — primary content</li> |
| 25 | <li><footer> — closing content</li> |
| 26 | <li><nav> — navigation links</li> |
| 27 | </ul> |
| 28 | </section> |
| 29 | </article> |
Each <section> should ideally have its own heading. The <article> element represents a self-contained composition that can be independently distributed or reused, such as a blog post, news story, or forum comment.
pro tip
✗ Skipping Heading Levels
<h1>Page Title</h1><h3>Subsection</h3>Jumping from h1 to h3 breaks the document outline and confuses screen readers.
✓ Correct Hierarchy
<h1>Page Title</h1><h2>Subsection</h2><h3>Sub-subsection</h3>Always maintain sequential heading order for proper accessibility.
✗ Using <br> for Paragraph Spacing
<p>First paragraph.</p><br><br><p>Second paragraph.</p>Use CSS margins on p elements instead of empty br tags.
✓ Correct Spacing
<p class="mb-4">First paragraph.</p><p class="mb-4">Second paragraph.</p>Use CSS for spacing between paragraphs. Every br is semantically meaningless.
✗ Multiple <h1> Elements
<h1>Section 1</h1><h1>Section 2</h1><h1>Section 3</h1>Multiple h1 elements dilute the page hierarchy. Use one h1 and nest h2, h3, etc.
✓ Single h1
<h1>Page Title</h1><h2>Section 1</h2><h2>Section 2</h2>One h1 establishes the main topic; all other headings nest below it.
| Element | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| h1–h6 | ✓ | ✓ | ✓ | ✓ |
| p | ✓ | ✓ | ✓ | ✓ |
| br | ✓ | ✓ | ✓ | ✓ |
| hr | ✓ | ✓ | ✓ | ✓ |
| pre | ✓ | ✓ | ✓ | ✓ |
| blockquote | ✓ | ✓ | ✓ | ✓ |