Explain it simply
Explain it simply
At school a teacher probably told you to start a new paragraph whenever a new idea begins. The <p> element is that paragraph for a web page. Text that starts with <p> and ends with </p> is shown as its own block, and the browser automatically puts empty space between one paragraph and the next.
One important surprise: pressing Enter or typing many spaces in your source code changes nothing on the page. If you want a new paragraph, you write a new <p>.
Problem → Why → Solution
The problem: a wall of text
The "About us" text for a café was split into nice lines in the editor, but all of it sits inside one <p>. When the page opens, every line break disappears and the text becomes one long block. On a phone it fills the whole screen, and the reader cannot see where one idea ends and the next begins.
<p>
We opened in 2019 in a small street in Yangon.
Our tea leaves come from family farms in Shan State.
Every Saturday we run a free tea-tasting class.
</p>Why do the line breaks disappear?
In HTML, line breaks and spaces in the source exist only to make the code readable for its author. The browser collapses any run of whitespace (spaces, tabs, newlines) into a single space. Only tags describe structure, so if three ideas should be three paragraphs, you must write three <p> elements.
Core concept: a paragraph is a block of text
<p> is a block-level element: it starts on a new line and takes the full available width. The browser's default stylesheet gives every paragraph a margin of 1em above and below. When two paragraphs touch, those margins do not add up to 2em; the larger one wins, which is called margin collapsing. That is why the gap between paragraphs is about one line high.
HTML is strict about what a paragraph may contain: only text and inline elements, called phrasing content, such as <a>, <strong>, <em>, <code>, <img> and <br>. Block elements such as <ul>, <div>, <h2>, <table> or another <p> are not allowed. If you put one in, there is no error message. The HTML parser silently closes the <p> where the block element starts, and the leftover </p> later on creates an extra empty paragraph. The DOM you get no longer matches the code you wrote.
The whitespace rule applies inside paragraphs too. Indentation and line wrapping in your source all become single spaces, so you are free to format the code for readability. When a paragraph genuinely needs a line break, as in a poem or a postal address, you use <br>, and when every space must be kept exactly you use <pre>; both come in later lessons.
If you leave out the </p> end tag, the page still renders because the browser closes the paragraph when the next block element arrives. Where exactly it closes is hard to predict and can cause CSS and JavaScript bugs, so always write the </p>. The Elements panel in the browser's DevTools shows the real DOM the parser built, which makes it the best place to check for these surprises.
- Each idea gets its own <p> box
- Inside: text and inline tags only
- Source whitespace becomes one space
- Gaps between boxes come from margin
The number of paragraphs on screen always equals the number of <p> tags, never the number of times you pressed Enter.
General pattern
<p>One idea, written as text and inline elements.</p>
<p>The next idea starts a new paragraph.</p>
<p>
Long text can be wrapped in the source;
the browser joins these lines with single spaces.
</p>Each <p> is one paragraph. Inline elements such as <strong> or <a> may go inside it, but blocks such as lists, headings and divs belong outside the paragraph.
Example: three paragraphs and collapsed whitespace
The first two paragraphs are ordinary. The third is written over three source lines with extra spaces. Before you open the page, predict how it will look.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Paragraphs</title>
</head>
<body>
<h1>Paragraphs</h1>
<p>This is the first paragraph.</p>
<p>This is the second paragraph. It has space from the first one.</p>
<p>
Extra spaces and
line breaks in the source
collapse into single spaces.
</p>
</body>
</html>Code breakdown
- Line 9
<p>This is the first paragraph.</p>The simplest paragraph. As a block element it starts on its own line, and the browser gives it a margin above and below.
- Line 10
<p>This is the second paragraph. It has space from the first one.</p>The gap between the two paragraphs is 1em, not 2em, because of margin collapsing. One paragraph can hold several sentences.
- Line 12
Extra spaces andThe six spaces between "Extra" and "spaces" render as one space.
- Lines 11-15
<p> Extra spaces and line breaks in the source collapse into single spaces. </p>The line breaks and indentation also become single spaces, so the text flows as one line. Whitespace right after <p> and right before </p> is dropped entirely.
Below the heading you see three paragraphs separated by blank space. The third reads "Extra spaces and line breaks in the source collapse into single spaces." as one continuous line of text with a single space between every word.What happens when a list goes inside a paragraph
The code below looks reasonable, but the DOM in the browser's developer tools shows three pieces: a paragraph holding "Our menu:", a <ul> outside the paragraph, and an empty paragraph created by the stray </p>. CSS rules aimed at the paragraph no longer reach the list, and the empty paragraph adds unwanted space.
<!-- Written like this... -->
<p>Our menu:
<ul>
<li>Green tea</li>
<li>Milk tea</li>
</ul>
</p>
<!-- ...the browser builds this DOM:
<p>Our menu:</p>
<ul>...</ul>
<p></p>
-->The fix is simple: close the paragraph before the list and make the list its sibling, <p>Our menu:</p> followed by <ul>...</ul>. If you need more space between paragraphs, change the CSS margin instead of adding empty <p></p> elements or <br> tags.
<style>
p {
max-width: 65ch;
line-height: 1.6;
margin: 0 0 1.25em;
}
</style>
<p>65ch keeps each line to about 65 characters wide.</p>
<p>line-height adds air between the lines of one paragraph.</p>In real projects
Where this shows up in real projects
Blog posts, news articles and product descriptions are all built from paragraphs. In a CMS, pressing Enter twice usually creates a new <p> behind the scenes, so writers never see the tag, but the HTML that comes out follows the rules in this lesson. In Markdown, every block of text separated by a blank line becomes a <p> as well.
Design teams usually limit paragraph line length to roughly 60-80 characters and set line-height around 1.5 for readability, which is a single p rule in the CSS. Screen readers also offer navigation from paragraph to paragraph, so short paragraphs help both people reading on a phone and people listening. Content pasted into a CMS often brings empty paragraphs, or paragraphs holding only a non-breaking space, so code reviews look for these and remove them.
Common mistakes
Common mistakes
1. Expecting Enter to start a paragraph
Blank lines inside one <p> still give a single paragraph on the page. Give each idea its own <p>.
2. Nesting a list or div inside a paragraph
A <ul> inside <p> makes the browser close the paragraph early and invent an empty one. The Elements panel in DevTools reveals it immediately. Place the list outside the paragraph as a sibling.
3. Using empty paragraphs for spacing
Empty paragraphs, or paragraphs holding only a non-breaking space, may be announced as "blank" by screen readers and make spacing hard to control across screen sizes. Replace them with a CSS rule such as p { margin-bottom: 1.5em; }.
Best practices
Best practices
- Write web paragraphs shorter than book paragraphs; two to four sentences read well on a phone screen.
- Put the main point in the first sentence of a paragraph, because people who skim often read only the openings.
- Keep typography (margin, line-height, max-width) in one p rule instead of style attributes on individual paragraphs.
- Check pasted content in DevTools and remove any empty paragraphs it brought along.
Mini challenge
Mini challenge: a café's About page
Turn the café text from the problem section into a readable About page. Give each idea its own paragraph, keep the tea list outside any paragraph, and control spacing and line length with CSS.
- One <h1> and three <p> elements for the three ideas
- A <ul> placed after an "Our teas:" paragraph, as a sibling
- No empty <p> or <br> used for spacing
- One p rule setting max-width, line-height and margin
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>About</title>
<style>
/* TODO: a p rule for line length, line height and spacing */
</style>
</head>
<body>
<!-- TODO: page heading -->
<!-- TODO: one paragraph per idea (opening, tea farms, Saturday class) -->
<!-- TODO: an "Our teas:" paragraph, then a list that is NOT inside it -->
</body>
</html>Expected: Under the heading you see three short paragraphs, an "Our teas:" line and a bulleted list. DevTools shows no empty paragraphs, and the lines are narrow and comfortable to read.
Show hint
Read each paragraph and ask "is this one idea?". Remember to write </p> before the list starts.
Show solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>About Golden Leaf Tea House</title>
<style>
p {
max-width: 60ch;
line-height: 1.6;
margin: 0 0 1.25em;
}
</style>
</head>
<body>
<h1>About Golden Leaf Tea House</h1>
<p>We opened in 2019 in a small street in Yangon.</p>
<p>Our tea leaves come from family farms in Shan State.</p>
<p>Every Saturday we run a free tea-tasting class for beginners.</p>
<p>Our teas:</p>
<ul>
<li>Green tea</li>
<li>Milk tea</li>
<li>Pickled tea leaf salad</li>
</ul>
</body>
</html>Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- Each <p> is one paragraph; give every idea its own.
- Runs of spaces, tabs and newlines in the source collapse into one space.
- Put only text and inline elements inside <p>; lists and divs go outside it.
- Control paragraph spacing, line length and line height with CSS.