<br> Tag in HTML

Introduction

HTML Stands for Hypertext Markup Language. We also call it the backbone of the internet. It is one of the markup languages which is used to create web pages and applications. One of HTML's most essential and powerful features is the <br> tag. With the help of this tag, we can provide a line between a paragraph. In this article, we will learn all the details about <br> tag.

When we write an article in MS Word, the cursor will move to the next time we press enter key. In HTML, when we write any paragraph and need one line of space, we go for <br> tag.

Examples of <br> Tag

Example 1: Let's take an example and write a poem without giving <br> tag and what we get in the output.

Output:

HTML br tag

Explanation:

In the above program, we write the poem by writing line breaks, but all the lines are converted into a single line in the output.

Example 2: Let's rewrite the above code with the help of <br> tag and see what we got in the output.

Output:

HTML br tag

Explanation:

We got the output per our expected format after giving the <br> tag in the above code.

Let's come to the definition of the <br> tag.

Definition of <br> Tag in HTML

<br> tag is an element in HTML used to produce a line break in an HTML document (carriage return).

Syntax of <br> Tag:

We can write the <br> tag with the help of the below syntax.

Attributes of <br> Tag in HTML

In HTML, <br> tag supports only two types of attributes. These two attributes are Global and event Handler attributes.

1. Global Attributes

The global attribute that is supported in HTML is as follows.

  • Accesskey
  • Autocaptilize
  • Class
  • contenteditable

2. Event Handler Attributes

We want something returned as a response whenever we press any key or click. In that case, we take the help of the event handler. The list of event listeners supported by the <br> tag is as follows.

  • Onabort
  • Onautocomplete
  • Onautocompleteerror
  • Onblur

NOTE: The <br> tag is deprecated in HTML 5. So It Is no longer supported in HTML5 and should not be used.

Example of <br> Tag with HTML & CSS Code

Output:

HTML br tag

Difference between <br> and <br/> in HTML

  • With the help of <br> tag, we provide the line break in HTML. There is no need for </br> tag.
  • But in XTML, it is stricter in HTML. So in XTML, the syntax is changed.
  • We need to use <br/> (not to be confused with the usual ending tags in HTML where the slash is written before the element name, not after ex: </h1>,</br>)

Example of <br> Tag for Entering Line Breaks in HTML

Output:

HTML br tag
Next TopicHTML button tag




Latest Courses