Why use <br> ?

When we need to make a new line inside a paragraph tag. Then used <br> . HTML document Browser ignores line break or extra space inside HTML Browser will manage margin automatically

before and after the tag <p>  When we needed to end our line stop and start the new line then we used <br> .



Syntax:

    <p>
        Our life is not a joke.<br> Life unit of jokes.        
    </p>



Example:

<!DOCTYPE html>
<html >
<head>
 
    <title>Basic get in </title>
</head>
<body>
    <p>
        Our life is not a joke.<br> Life unit of jokes.        
    </p>
</body>
</html>






Output:






What will happen when we don’t  use <br>?

Code without <br>:

<!DOCTYPE html>
<html >
<head>
 
    <title>Basic get in </title>
</head>
<body>
    <p>
        Our life is not a joke.
       Life unit of jokes.        
    </p>
</body>
</html>


Output:








In here you can see that we use new line in our code but we don't used

<br>. It now reads one line in the browser. We know Browsers ignore extra space and new lines. We need to say to the browser ,hay start a new line by <br> tags. When we use more space and start a new line. It makes a single space between last-first and last-second words.

Code:

<!DOCTYPE html>
<html >
<head>
 
    <title>Basic get in </title>
</head>
<body>
    <p>
        Our life                 is not a joke.
       
       
       
       
        Life unit
       
       
        of jokes.        
    </p>
</body>
</html>



Output:


You see the difference.



What are our solutions?

We use <br> for line breaks and we need to use extra space.

We need more tags like: &nbsp; , &#160; , &ensp; , &emsp; 

 We will learn more in the next.


Code:

<!DOCTYPE html>
<html >
<head>
 
    <title>Basic get in </title>
</head>
<body>
    <p>
             
        Our life &nbsp; &nbsp; &nbsp; is
            not a joke.<br>Life unit of &emsp; &emsp; jokes.  
       
    </p>
</body>
</html>


Output:












Post a Comment

Previous Post Next Post