HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a wide variety of different elements. In Html, there is one of the tags, <br> that is used for adding line break in any paragraph or text.

A line break in a html document  can be made using the HTML br tag.

New paragraph and line breaks in the html text document are not provided by the browser. You can add line breaks in your html document with the help of <br> tag. One carriage returns or break is inserted into the document by <br> tag. No end tag exists for this element.

It is typically used in poems or addresses where line breaks are required. The <br> tag functions similarly to the enter key in a word file if it is included in the HTML code.

Syntax of br tag

Paragraph <br> Paragraph

Example of br tag in HTML

<!DOCTYPE HTML>  
<html>  
<head>  
<title>  
 BR tag  
</title>  
</head>    
<body>    
<h2> Example Of Br Tag </h2>
<p>This Is an Example of Br <br> Tag in a paragraph, <br> use the BR element in <br> your HTML document. When You add line break </p>    
</body>  
</html> 

Output: html-br-tag

Html <br> Tag

Example 2

<!DOCTYPE HTML>  
<html>  
<head>  
<title>  
Example of BR tag in Address  
</title>  
</head>    
<body> <font color="Blue"> <!-The color attribute displays the color of following address in green -->   
<p>Bhajanpura<br>   
Wazirabad Road, <br>  
New Delhi, <br>  
India <br>   
</body>  
</html>    

Output:

Html <br> Tag

As you can see from the above example, a <br> element is included at each point where we want the text to break. The text after the <br> begins again at the start of the next line of the text block.

Styling with CSS

The br> element's sole, clearly stated function is to introduce a line break into a block of text. As a result, there isn't much you can do to style it and it doesn't have any dimensions or visual output of its own.

To increase the space between the lines of text in the block, you can add a margin to the br> elements themselves, but this is bad practise; instead, you should use the line-height property, which was made for that purpose.

Availability issues

In addition to being bad practice, using the br> character to break up paragraphs of text causes issues for users of screen reading software. Although content contained within br> cannot be read aloud by screen readers, the element can be announced to be present. The screen reader user may find this to be both confusing and frustrating.

Use p> elements and CSS spacing properties to manage their spacing.

Why <br> tag is differed from <br/> tag?

There are two ways to use the HTML br tag: br> or br/>. Since closed br tags are supported by both HTML and XHTML.

The self-closing br tag is used to create line breaks in HTML documents.

A self-closing tag (also known as an empty tag) can be used when a tag is used without any space between them. One of these self-closing tags is br does not require the closing tag (/br). Therefore, it follows that when used in HTML, br and br/ will yield the same results.

However, when using XHTML (which is stricter than HTML), it is not permitted to leave tags open (for example, you cannot write just br; you must also close it, but /br doesn't make sense because it is a self-closing tag), so br/ will be used in that situation.

Additionally, br is less efficient as compared to br/ in terms of code organization and readability. As a result, br/ is typically preferred over br.

Browser Compatibility

  • Chrome
  • Firefox
  • Opera Mini
  • Safari (All)
  • Edge

Attributes

The only attributes that apply to the <br> tag are the global attributes. There aren't any attributes unique to the <br> tag.

Conclusion

A line break in a html document can be made using the HTML tag br. A new paragraph and line breaks in the html text document are not provided by the browser. You can add line breaks in your html document with the help of <br> tag.



ADVERTISEMENT
ADVERTISEMENT