Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




HTML - Line Break


Let us say that there is a requirement where you are asked to print a small story in HTML with line breaks.

Example :

In a huge pond,
there lived many fish.
They were arrogant and
never listened to anyone.

Let us try writing it and see if it works.


Example :



<html>	
	<body>
		In a huge pond, 
		there lived many fish. 
		They were arrogant and 
		never listened to anyone.
	</body>
</html>


Output :




So, if you look at the above output, the story got printed in a single line without line breaks.


That's not what we wanted.


And this is where the <br> tag comes into picture.


Line breaks in HTML with <br> tag


So, let us rewrite the above example with <br> tag and see if that works.


Example :



<html>	
	<body>
		In a huge pond, <br>
		there lived many fish. <br> 
		They were arrogant and <br>
		never listened to anyone. <br>	
	</body>
</html>


Output :




Now, if you look at the above output, the story got printed with proper line breaks.


And all we have done is, at the end of each line we have placed the <br> tag.


In a huge pond, <br>
there lived many fish. <br>
They were arrogant and <br>
never listened to anyone. <br>

Line breaks can also be inserted using <p> element.


Line breaks in HTML with <p> element


The <p> element also inserts two line breaks.


Let us rewrite the above example with <p> element.


Example :



<html>	
	<body>
		<p> In a huge pond, </p>
		<p> there lived many fish. </p> 
		<p> They were arrogant and </p> 
		<p> never listened to anyone. </p>
	</body>
</html>


Output :




So, if you look at the above output, two line breaks for each line.


Line breaks in HTML with <div> element


Once again, let us rewrite the above example using the <div> element. The <div> element inserts one line break for each line.


Example :



<html>	
	<body>
		<div> In a huge pond, </div>
		<div> there lived many fish. </div> 
		<div> They were arrogant and </div>
		<div> never listened to anyone. </div>
	</body>
</html>


Output :




So, in the above output, the <div> element inserted one line break for each line.