Skip to content

03. p Tag

The <p> (paragraph) tag is one of the most fundamental HTML elements. It defines a block of text as a paragraph, creating logical groupings of content and providing natural spacing between text blocks. Understanding how to use paragraphs correctly is essential for creating readable, well-structured web content.

The <p> tag creates a paragraph element, which is a block-level element that represents a paragraph of text. Browsers automatically add spacing before and after paragraphs, making them visually distinct blocks of content.

<p>This is a paragraph of text. It can contain multiple sentences and will be displayed as a block element.</p>
<p>This is a single paragraph containing multiple sentences. It will be displayed as one continuous block of text with automatic word wrapping.</p>
<p>This is the first paragraph. It contains information about the topic.</p>
<p>This is the second paragraph. It provides additional information and will be automatically separated from the first paragraph by spacing.</p>
<p>This is the third paragraph. Each paragraph is a distinct block element.</p>

Paragraphs are block-level elements:

  • Take full width of container
  • Start on new line
  • Have spacing above and below
  • Cannot contain other block elements

Browsers add default margins:

<p>Paragraph 1</p>
<p>Paragraph 2</p>
<!-- Automatic spacing between paragraphs -->

Text automatically wraps:

<p>This is a very long paragraph that will automatically wrap to multiple lines when it reaches the edge of its container.</p>
<p>Plain text content in a paragraph.</p>

Paragraphs can contain inline elements:

<p>This paragraph contains <strong>bold text</strong>, <em>italic text</em>, and <a href="#">a link</a>.</p>

Use <br> for line breaks within paragraphs:

<p>Line one<br>Line two<br>Line three</p>

Note: Prefer separate paragraphs over line breaks when possible.

<article>
<h1>Article Title</h1>
<p>Introduction paragraph that introduces the topic.</p>
<p>Main content paragraph that provides detailed information.</p>
<p>Conclusion paragraph that summarizes the content.</p>
</article>
<article>
<h1>Blog Post Title</h1>
<p>First paragraph of the blog post.</p>
<p>Second paragraph continues the discussion.</p>
<p>Third paragraph concludes the section.</p>
</article>
<section>
<h2>Section Title</h2>
<p>Paragraph describing the section content.</p>
<p>Additional paragraph with more information.</p>
</section>

Keep paragraphs focused:

<!-- Good: Clear, focused paragraphs -->
<p>This paragraph discusses one main idea.</p>
<p>This paragraph discusses a different but related idea.</p>
<!-- Avoid: Overly long paragraphs -->
<p>This paragraph has too many ideas. It discusses topic one, then topic two, then topic three, and it keeps going with more topics until it becomes hard to read and understand.</p>

Let browsers handle spacing:

<!-- Good: Let CSS handle spacing -->
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<style>
p {
margin-bottom: 1em;
}
</style>

Use paragraphs for text blocks:

<!-- Good: Semantic paragraphs -->
<p>Content here.</p>
<!-- Avoid: Using divs for text -->
<div>Content here.</div>
<p>Styled paragraph</p>
<style>
p {
font-size: 1.1em;
line-height: 1.6;
margin-bottom: 1.5em;
color: #333;
}
</style>
p {
margin-top: 1em;
margin-bottom: 1em;
}
/* Remove spacing between paragraphs */
p + p {
margin-top: 0;
}

Problem:

<p>Paragraph 1
<p>Paragraph 2

Solution:

<p>Paragraph 1</p>
<p>Paragraph 2</p>

Problem:

<p>Text <div>Block element</div> more text</p>

Solution:

<p>Text</p>
<div>Block element</div>
<p>More text</p>

Problem:

<div>This is text content.</div>

Solution:

<p>This is text content.</p>

Paragraphs help screen readers:

<article>
<h1>Title</h1>
<p>First paragraph that screen readers can navigate.</p>
<p>Second paragraph that provides additional context.</p>
</article>

Screen readers can:

  • Navigate by paragraph
  • Understand content structure
  • Provide better reading experience
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Paragraph Example</title>
<style>
p {
line-height: 1.6;
margin-bottom: 1em;
}
</style>
</head>
<body>
<article>
<h1>Understanding HTML Paragraphs</h1>
<p>The paragraph tag is fundamental to HTML. It creates logical blocks of text content.</p>
<p>Each paragraph is a distinct element that browsers automatically space apart. This makes content easier to read and understand.</p>
<p>Paragraphs can contain <strong>inline elements</strong> like <em>emphasis</em> and <a href="#">links</a>.</p>
</article>
</body>
</html>