HTML Paragraphs
The <p> element defines a paragraph of text, the most common block on most pages.
A paragraph is a block of text wrapped in <p>. Browsers add a little space above and below each one to keep text readable.
Writing Paragraphs
Two paragraphs
<!DOCTYPE html>
<html>
<body>
<p>HTML documents are built from elements like this paragraph.</p>
<p>Each new paragraph starts on its own line, with space above and below it.</p>
</body>
</html>Whitespace Is Collapsed
Extra spaces and line breaks in your code do not show up on the page. The browser collapses any amount of whitespace into a single space, so layout comes from tags, not from how you space the source.
- Use <br> to force a line break inside a paragraph.
- Use <hr> to draw a horizontal dividing line between sections.
- Use <pre> when you need to keep spacing exactly as typed.
Preformatted Text
The <pre> element keeps both spaces and line breaks, which makes it handy for poems or code.
Preserved spacing
<!DOCTYPE html>
<html>
<body>
<pre>
function greet() {
return "Hello!";
}
</pre>
</body>
</html>Note: You cannot add extra blank lines to a page just by pressing Enter in your code. Use separate elements instead.
Exercise: HTML Paragraphs
Which element is used to define a paragraph of text in HTML?