HTML Paragraphs



Paragraph element is used to publish text on the web pages.

The HTML <p> element defines a paragraph. It is a Paired Tag, i.e. it comes with an opening <p> and a closing </p> tag.

HTML Paragraphs are block-level elements, i.e., a new paragraph will always start from a new line.


Example : 

<p>This is the first paragraph.</p>  
<p>This is the second paragraph.</p>  
<p>This is the third paragraph.</p>  

Output : 

This is the first paragraph.

This is the second paragraph.

This is the third paragraph.



Space inside Paragraph

If you put a lot of spaces inside the HTML <p> tag, the browser removes extra spaces and extra lines while displaying the page. The browser counts a number of spaces and lines as a single one.


 Example : 

<p>This paragraph contains  multiple   spaces    in the source code.</p>
<p>
    This paragraph
    contains multiple tabs and line breaks
    in the source code.
</p>

Output : 

This paragraph contains multiple spaces in the source code.

This paragraph contains multiple tabs and line breaks in the source code.

Defining Preformatted Text

Sometimes, using &nbsp;<br>, etc. for managing spaces isn't very convenient. Alternatively, you can use the <pre> tag to display spaces, tabs, line breaks, etc. exactly as written in the HTML file. It is very helpful in presenting text where spaces and line breaks are important like poem or code.


 Example : 

<pre>This paragraph contains  multiple   spaces    in the source code.</pre>
<pre>
    This paragraph
    contains multiple tabs and line breaks
    in the source code.
</pre>

Output : 

This paragraph contains  multiple   spaces    in the source code.

This paragraph

contains multiple tabs and line breaks

in the source code.

 

Note: If you want to add some extra space outside the Paragraph, then don't use <br> tag. Instead, use CSS Margins to change the space above/below of a paragraph.