HTML Paragraphs
The <p> tag defines a paragraph. The browser adds some space before and after each paragraph.
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
Output in the browser
This is the first paragraph.
This is the second paragraph.
Extra spaces and lines are ignored
HTML shows extra spaces and new lines in your code as one single space. To start a new line, you must use a tag.
<p>This text has extra
spaces and a new line.</p>
Output in the browser
This text has extra
spaces and a new line.
Line break: br
The <br> tag gives a new line without starting a new paragraph. It has no closing tag.
<p>Roses are red,<br>Violets are blue.</p>
Output in the browser
Roses are red,
Violets are blue.
Note:
Do not use many <br> tags to create space between things. Use separate paragraphs, and CSS margin for spacing.
Horizontal line: hr
The <hr> tag shows a line to separate content. In HTML5 it means a change of topic.
<p>First topic.</p>
<hr>
<p>Second topic.</p>
Preformatted text: pre
The <pre> tag keeps the spaces and line breaks exactly as you typed them, and shows text in a fixed-width font. It is good for poems and code.
<pre>
Line one
Line two (indented)
Line three
</pre>
Summary
- Use
<p>for each paragraph. - Extra spaces and new lines in the code are ignored by the browser.
- Use
<br>for a line break,<hr>for a separator and<pre>to keep the formatting. - Next: Block and Inline elements.
Congratulations! Chapter Finished. Learn more about the similar topics:
| Exercises & Assignments |
|---|
| Program to see difference between paragraphs & normal text with line break |
| Interview Questions & Answers |
|---|
| No Content Found. |