• Tutorial List

HTML Paragraphs

Last updated Jul 08, 2020
HTML Paragraphs

How to create paragraphs on a web page?

The HTML <p> tag is used to create paragraphs on a web page. This tag has the closing tag. Most browsers display paragraphs correctly, even if you do not use the closing tag.

📝 But avoiding the closing tag can produce unexpected results or errors. Therefore don’t forget to add the closing tag after opening the paragraph tag.


  • HTML Paragraph Tag
    • <p>...</p>
<!DOCTYPE html>
<html>
	<body>

      <p>This is a paragraph.</p>
	  <p>This is another paragraph.</p>

	</body>
</html>

The output of HTML paragraphs on browser

  • Web Browsers automatically add some space (margin) before and after a Paragraph.
  • If you add multiple spaces in a paragraph, browsers reduce the spaces to a single space.
  • If you add multiple lines in a paragraph, browsers reduce the lines to a single line.
<!DOCTYPE html>
<html>
	<body>

      <p>This paragraph contains         a lot of spaces.</p>
      
	  <p>This paragraph contains
		multiple
		lines.</p>

	</body>
</html>

How to break lines in HTML paragraphs?

The HTML <br> tag is used to break lines. You can use this tag to break lines in HTML paragraphs. This <br> tag does not have the closing tag, it is a self-closing tag.

<!DOCTYPE html>
<html>
	<body>
      
	  <p>This paragraph contains<br>multiple<br>lines.</p>

	</body>
</html>

How to add multiple spaces in HTML Paragraphs?

With the help of &nbsp; HTML entity, you can add multiple spaces to HTML paragraphs. This non-breaking space &nbsp; consists of a single space.

<!DOCTYPE html>
<html>
	<body>

      <p>This paragraph contains &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a lot of spaces.</p>

	</body>
</html>

HTML preformatted text

If you want to preserve multiple text spaces, line breaks, tabs, and other formatting characters, which are ignored by web browsers, the <pre> tag is used to preserve those formatting characters.

<!DOCTYPE html>
<html>
	<body>

<pre>
This paragraph contains         a lot of spaces.

This paragraph contains
multiple
lines.
</pre>

	</body>
</html>

Ask Questions

Your email address will not be published. Required fields are marked *