Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
HTML, the backbone of web development, provides a set of tags to structure and present content. In the world of line breaks, the <br> tag plays a crucial role. Short for "break," this tag is a simple yet powerful tool for controlling the flow of text and elements on a webpage. This blog explores the HTML <br> tag, unraveling its functionality, use cases, and the impact it has on the visual presentation of content.
What is <br> Tag in HTML?
<br> tag in HTML gives you a line break in the text. This is an empty tag, meaning it has no end tag. <br> tag is generally used in writing poems, addresses, or where it is required to add a break in the text. The tag can be used anywhere, i.e., clubbed with other tags.
Syntax of HTML <br> Tag
Although, <br> tag has no such specified syntax. It is used with its name enclosed in angular brackets.
<br>
Attributes of <br> Tag in HTML
The <br> tag in HTML is a void element, meaning it doesn't have a closing tag. It doesn't have specific attributes like many other tags. It's used to insert a line break in the document.
Welcome to yet another interesting article. <br>In this blog, we will learn about br tag.
</body>
</html>
Output
We can see in the above code that the sentence gets broken out after using the <br> tag. The tag itself has no such specified output. It only has a little purpose except to break the text. It is not compulsory to use <br> tag with other tags. The tag can be directly used in the body to separate text.
Let’s see the below example for this:
HTML Code
HTML Code
<!DOCTYPE html> <html lang="en"> <head> <title>First Web Page</title> </head> <body> Chrome<br>Internet Explorer <br> Microsoft Edge <br> Opera Mini <br> Brave <br>Safari </body> </html>
Output
You can see in the above code that <br> tag is used in the body part of HTML. You can also add margins and text spacing using the <br> tag, but it is advisable to use something other than the <br> tag for this purpose. The CSS stylesheet has margins and various height properties for spacing and height of the text.
Let’s achieve the above output without using the <br> tag.
HTML Code
HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>First Web Page</title>
</head>
<body>
<p>Chrome</p>
<p>Internet Explorer </p>
<p> Microsoft Edge </p>
<p> Opera Mini </p>
<p>Brave</p>
<p> Safari</p>
</body>
</html>
Output
Difference Between <br> and <br/> in HTML
The primary difference between <br> and <br/> in HTML lies in their usage and syntax:
1. Syntax:
<br>: Traditional syntax for line breaks in HTML. <br/>: Self-closing syntax, recommended in XHTML and HTML5 for consistency and compatibility. It's also accepted in HTML.
2. XHTML and HTML5:
<br>: Commonly used in HTML documents without closing tag. <br/>: Preferred in XHTML and HTML5 for self-closing tags.
3. Compatibility: Both are generally supported across browsers, but <br/> is more consistent with XML rules. In HTML5, both <br> and <br/> are accepted, providing flexibility.
4. Common Usage:
<br>: Widely used in HTML for line breaks. <br/>: More commonly used in contexts adhering to XHTML or HTML5 standards.
In practice, for HTML5, both forms are accepted, but for XHTML and consistency, <br/> is often recommended. For HTML, <br> is more commonly used due to its simplicity.
Supported Browsers
The <br> tag, which represents a line break in HTML, is universally supported across all major web browsers. This includes popular browsers such as:
Google Chrome
Mozilla Firefox
Apple Safari
Microsoft Edge
Internet Explorer
The consistent support for the <br> tag ensures that line breaks are rendered consistently across different browsers and platforms, providing a standard way to control the layout and spacing of content within HTML documents.
Frequently Asked Questions
What is <br> tag in HTML?
<br> tag gives you a single line break in the text. This tag is used in poems, addresses, or where there is a need to break the lines.
How to use <br> tag in HTML table?
To add line breaks in an HTML table, use <br> within table cell content to move text or elements to a new line.
Conclusion
In this blog, we thoroughly discussed <br> tag in HTML. We learned about its syntax, usage, and examples of using <br> tag, and we also discussed the reason for not using the <br> tag in HTML.
To learn more about HTML, and its tags, please refer.