HTML Paragraphs
Learn to structure text content with HTML paragraphs - the building blocks of readable web content.
How do you create a paragraph in HTML?
Wrap text in a <p> element: <p>Your text here.</p>. Browsers ignore extra spaces and line breaks in your source code and collapse them into one space, so each paragraph needs its own <p>. Use <br> only for line breaks that are part of the content, such as addresses or poems.
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
<address>12 Main St<br>Springfield</address>Try It: Paragraph Elements
Experiment with paragraph elements and see how they structure text content. Try modifying the text and CSS to see the effects.
Code Editor
<p>This is a paragraph. Extra spaces and
line breaks in the source collapse into one space.</p>
<p>A line break inside a paragraph:<br>uses <br>, for addresses or poems.</p>
<pre>Preformatted text
keeps spacing
exactly.</pre>
<hr>
<p>A horizontal rule (<hr>) separates topics.</p>Preview
What Are HTML Paragraphs?
The <p> element defines a paragraph of text. It's one of the most fundamental HTML elements for structuring readable content.
Basic Paragraph Syntax:
<p>This is a paragraph of text.</p>
<p>This is another paragraph.</p>Key Characteristics:
- Block-level element: Takes up the full width of its container
- Automatic spacing: Browsers add margin above and below paragraphs
- Text flow: Text automatically wraps to the next line when needed
- Can contain inline elements: Links, bold, italic, and other inline content
What Can Go Inside Paragraphs?
Paragraphs can contain text and various inline elements, but not other block-level elements like headings or other paragraphs.
Allowed Content
- • Plain text
- • <strong> and <b> (bold)
- • <em> and <i> (italic)
- •
<a>(links) - •
<code>(inline code) - •
<span>(generic inline) - •
<br>(line breaks) - •
<img>(images)
✗Not Allowed
- •
<h1>-<h6>(headings) - •
<p>(other paragraphs) - •
<div>(block containers) - •
<section>(sections) - •
<article>(articles) - •
<ul>,<ol>(lists) - •
<table>(tables) - •
<form>(forms)
Example of Mixed Content:
<p>
This paragraph contains <strong>bold text</strong>,
<em>italic text</em>, a <a href="#">link</a>,
and some <code>inline code</code>.
</p>Line Breaks and Spacing
Understanding how paragraphs handle whitespace and line breaks is crucial for proper text formatting.
Automatic Behavior:
- Whitespace collapse:
Multiple spaces become one
- Line breaks ignored:
HTML ignores line breaks in source code
- Automatic wrapping:
Text wraps at container boundaries
Manual Control:
- <br> element:
Forces a line break
- CSS properties:
Control spacing with margins/padding
-
Non-breaking space character
Examples:
Multiple spaces in HTML:
<p>This has many spaces.</p>Displays as: "This has many spaces."
Manual line break:
<p>First line<br>Second line</p>Creates two lines within the same paragraph
Best Practices
Good Practices:
- Keep paragraphs focused on one main idea
- Use reasonable paragraph lengths (3-5 sentences)
- Use CSS for styling, not HTML structure
- Ensure good contrast and readability
Avoid These:
- ✗Using <br> to create spacing between paragraphs
- ✗Putting block elements inside paragraphs
- ✗Using paragraphs just for spacing
- ✗Very long paragraphs that are hard to read
HTML Paragraphs — step by step
Use p for text paragraphs
The p element defines a paragraph of text. Browsers automatically add spacing above and below paragraphs, creating visual separation between blocks of content.
🎯 Quick Check
What HTML element creates a single line break within text content?
HTML Paragraphs: summary
Key points
<p>can't contain block elements like<div>,<ul>or another<p>; the browser closes the paragraph early.- Paragraph spacing comes from default CSS margins and can be changed with CSS.
<pre>keeps whitespace and line breaks exactly as typed, which is useful for code or ASCII art.
Frequently asked questions
›How do I add a line break without a new paragraph?
Use <br>. For spacing between blocks of text, use separate <p> elements and CSS margins instead of several <br> tags.
›Why are my extra spaces not showing?
HTML collapses runs of whitespace into a single space. Use CSS (white-space: pre-wrap), the <pre> element, or for a single non-breaking space.