HTML Paragraph

Please Share On:
  • As everyone knows that a paragraph always starts with new lines and usually a combination of texts.
  • HTML <p> element defines a paragraph. It has both opening and closing tag <p> </p>.
  • Browser automatically add a margin before and after a paragraph.

Syntax:

<p> Some Text... </p>

Code:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Headings</title>
  </head>
 
  <body>
     <p> I am a first paragraph. </p>
     <p> I am a second paragraph. </p>
     <p> I am a third paragraph. </p>
  </body>
</html> 			
                    

Output:

Browser Display:

As already mentioned above, the <p> tag adds a space before and after a paragraph, which is basically a margin added by your browser. The browser will remove extra spaces and lines when the page is displayed.

In the below example, the paragraph has been defined as using extra spaces and lines. Let’s see the browser output.

Code:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Headings</title>
  </head>
 
  <body>
    <p> Here, this first paragraph 
      has multiple lines,
      but the browser
      will ignore
      the multiple lines   
    </p>
    
     <p> Here,          this second         paragraph 
      contains          lot of space          in the source code,
      but           the browser
      ignore   spaces 
      to display.   
    </p>
  </body>
</html>  

Output:

HTML Horizontal Line:

<hr> tag is used to display a horizontal line.

<hr> tag is an empty tag, which means it doesn’t need a closing tag.

<hr> element is used to separate content in a webpage.

Syntax:

<hr>

Code:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Headings</title>
  </head>
 
  <body>
    <h1> Australia </h1>
    <p> Some description about Australia.</p>
    <hr>
    
    <h1> Nepal </h1>
    <p> Some description about Nepal.</p>
    <hr>
    
  </body>
</html> 			        

Output:

HTML Break Line

<br> element is used to break a line.

<br> tag is an empty tag, which means it doesn’t need a closing tag.

You just add a <br> tag whenever you need a line break.

Syntax:

<br>

Code:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Headings</title>
  </head>
 
  <body>
    <h1> Line Break Example</h1>
    
    <h3>Paragraph without break tag</h3>
    <p>This is a paragraph which uses a line break html tag element. </p>
    
    <br>
    
    <h3> Paragraph with break tag</h3>
    <p>This is a paragraph <br> which uses a line break <br> html tag element.</p>
    
  </body>
</html>

Output:

HTML <pre> Tag:

  • So we have learned how paragraph <p> tag ignores all extra lines and spaces before displaying in a browser. But, there is a way to preserve this by using a <pre> tag.
  • <pre> tag contains an opening and closing tag.
<pre> Some Text... </pre>
  • It displays a text with extra lines and spaces we use.
  • The best example to use <pre> tag is on song’s lyrics. which are written into multiple lines.

Syntax:

<pre> 

Some Text... 

</pre>

Code:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML Headings</title>
  </head>
 
  <body>
    <pre>
      This paragraph has multiple
      lines and it is displayed
      as it is written in the 
      code.
    </pre>
    
    <pre>
      This paragraph      has multiple
      spaces      and it is         displayed
      as it is      written in the 
      code.
    </pre>
    
  </body>
</html>          

Output:



You may be interested in the following topics:

Leave a Reply

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

Copyright @2023. All Right Reserved.


Social media & sharing icons powered by UltimatelySocial