HTML PARAGRAPH
HTML paragraph is represented by <p> tag. Paragraph has both opening and closing tags and content is written within the opening and closing tag. like: <p> ... </p>
Here is an Example:
<p>This is a paragraph.</p>
Try It
Output:
I am paragraph
The element <p> is used to define paragraphs in HTML.
- <p> tag automatically adds space before and after any paragraph.
- If there are multiple spaces added in content within the <p> tag then browsers ignore multiple spaces and treat them as only single spaces.
- If there are multiple lines given in any paragraph then also browsers ignore multiple lines and treat them as single lines. See the example below.
<p>This paragraph has multiple spaces.</p>
<p>This paragraph
has multiple
lines but browser
omits them.</p>
Try It
Output:
This paragraph has multiple spaces.
This paragraph has multiple lines but browser omits them.
HTML Line Breaks
Line break in HTML is defined by <br> tag.
In case you want to change the line in the paragraph then you can add the <br> tag and line will be changed.
Note: In HTML Writing <br> is sufficient but in XHTML you have to close the tag by writing <br /> .
Here is an example:
<p>This paragraph has Break <br> Line.</p>
Try It
Output:
This paragraph has Break
Line.
HTML pre Tag
As mentioned above <p> tag omits multiple spaces and multiple lines.And there are many cases when you have to put multiple lines as well as spaces.In such case you can use <pre> tag. <pre> tag preserve both multiple lines and space.
<pre>Pre tag store
both multiple space
and multiple line.</pre>
Try It
Output:
Pre tag store both multiple space and multiple line.