HTML Paragraphs
HTML paragraphs are used to display blocks of text on a webpage. They help organize written content into readable sections.
What are HTML Paragraphs?
A paragraph in HTML is created using the <p> tag.
Everything written inside this tag will be displayed as a paragraph.
Browsers automatically add some space before and after each paragraph.
Example
<p>This is a paragraph.</p> <p>This is another paragraph.</p>
How Paragraphs Work
Each paragraph always starts on a new line.
Even if you write text in one line in your code, the browser will display it properly as a paragraph.
<p>This is a paragraph with some text. It will still display correctly in the browser.</p>
<!DOCTYPE html> <html> <head> <title>HTML paragraphs</title> </head> <body> <p>This is a paragraph with some text. It will still display correctly in the browser.<p> </body> </html>
Line Breaks
To create a line break inside a paragraph, use the <br> tag.
<p> This is line one.<br> This is line two. </p>
<!DOCTYPE html> <html> <head> <title>HTML paragraphs</title> </head> <body> <p>This is line one. <br> This is line two.<p> </body> </html>
HTML Ignores Extra Spaces
HTML removes extra spaces and line breaks automatically.
<p> This text has many spaces </p>
The browser will display it as normal text without extra spaces.
Preformatted Text
If you want to display text exactly as written (with spaces and line breaks), use the <pre> tag.
<pre>
This is line 1
This is line 2
</pre>
<!DOCTYPE html> <html> <head> <title>HTML paragraphs</title> </head> <body> <pre> This is line 1 This is line 2 <pre> </body> </html>
Why Paragraphs Matter
- Make text easy to read
- Organize content clearly
- Improve user experience
- Help structure webpages
Best Practices
- Use paragraphs for blocks of text
- Keep paragraphs short and readable
- Use <br> only for line breaks, not spacing
- Use <pre> when formatting matters