In HTML, paragraphs are defined using the <p> tag. They are used to display blocks of text on a web page, and each paragraph automatically starts on a new line.
A paragraph is the most common way to add text content in HTML.
Basic Paragraph Example
<p>This is my first paragraph in HTML.</p>
<p>This is another paragraph, and it will start on a new line.</p>
By default, browsers add space before and after a paragraph to separate it from other content.
Line Breaks with <br>
If you want text to continue on the next line without starting a new paragraph, you can use the <br> tag.
<p>
Hello!<br>
This text starts on a new line but is still part of the same paragraph.
</p>
Paragraphs vs Line Breaks
Difference between <p> and <br>:
- <p> creates a new block of text with space before and after.
- <br> just breaks the line, but text stays in the same paragraph.
Preformatted Text with <pre>
Sometimes you want to keep spaces and line breaks exactly as written in your code. For this, use the <pre> tag.
<pre>
This text will
keep its spaces
and line breaks!
</pre>
Summary
- <p> defines a paragraph, and each starts on a new line.
- Browsers add default spacing before and after paragraphs.
- <br> adds a line break inside the same paragraph.
- <pre> preserves spaces and line breaks as written.
Use paragraphs to keep your content organized and readable.