HTML Paragraphs


In this tutorial, you'll learn how to create paragraphs in HTML.


Creating Paragraphs

Paragraph tags are usually used to display a paragraph on a web page. That is, the paragraph in the HTML document is written using the <p> tag.

After starting with the <p> tag, you have to give the closing tag at the end of the paragraph. Although many browsers display HTML documents correctly, you may forget to enter a closing tag. Even then you should always use closing tags. Here is an example:

Code Example:
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>HTML Paragraphs</title>										
  </head>
  <body>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Utinam quidem dicerent alium alio beatiorem! Iam ruinas videres. Duo Reges: constructio interrete. Zenonis est, inquam, hoc Stoici. Unum nescio, quo modo possit, si luxuriosus sit, finitas cupiditates habere. 
    </p>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Utinam quidem dicerent alium alio beatiorem! Iam ruinas videres. Duo Reges: constructio interrete. Zenonis est, inquam, hoc Stoici. Unum nescio, quo modo possit, si luxuriosus sit, finitas cupiditates habere. 
    </p>
  </body>
</html>
Note : The browser automatically leaves some space above and below the paragraph, that is, it adds margins.

Creating Line Breaks

The <br> tag is used to create a line break on a web page.

Code Example:
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>HTML Paragraphs</title>										
  </head>
  <body>
   	<p>This is a paragraph <br> with line break.</p>
    <p>This is <br>a paragraph <br> with line break.</p>
  </body>
</html>

Creating Horizontal Rules

The <hr> tag is used to create horizontal rules or lines in sections of individual content visually on a web page.

Code Example:
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>HTML Paragraphs</title>										
  </head>
  <body>
   	<p>This is paragraph.</p>
	<hr>
        <p>This is a paragraph with Horizontal Rule</p>
  </body>
</html>

Managing White Spaces

Multiple spaces in HTML, carriage returns, tabs, etc. are changed to create only one space. No matter how many spaces you give in the code, you will get only one space in the output.

So if you want to create extra space in the middle of a text, you need to use the word &nbsp; . You need to use as much space as you want &nbsp;

Following example:

Code Example:
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>HTML Paragraphs</title>										
  </head>
  <body>
   	<p> This     is a     paragraph. </p>
  </body>
</html>

Defining Preformatted Text

Sometimes, it’s not very convenient to use &nbsp; <br> , etc to manage places. Alternatively, you can display the <pre> tag in the text of the HTML file for spaces, tabs, line breaks, etc. It is very helpful in presenting text where spaces and line breaks are as important as poems or codes. Here is an example.

Code Example:
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>HTML Paragraphs</title>										
  </head>
  <body>
   <pre>
	This is a paragraph
	This is another paragraph
    </pre>
  </body>
</html>