Quick Guide to the br Element in HTML

- Andrés Cruz

En español
Quick Guide to the br Element in HTML

The br element is used to give a line break, simply using the label:

<br>

It is also equivalent to use the closing tag.

</br>

Or the following:

<br />

The label that never closes: br

HTML is a fairly open markup language that, as you may have noticed, if you develop or create web pages, you can make errors and still the page looks either correctly or with some stumbling blocks; That is, we can open a <p> tag and close it with a <h2>:

<p>Text<h2>

Or even not closing some tags:

<h3>Text

Although it should be noted that the previous examples are errors and therefore we have to avoid them; On the other hand, we also have labels that are placed and that's it, they do not have a closing label; for example those of <img>, <hr> and even the same <br> which is our case of interest for this entry

Now if you want to layout with XHTML, which is a markup language based on HTML but less open or with a more closed syntax, then it is mandatory that all tags close:

<br />

In this case this format.

</br>

West:

<br>

They would not be valid in XHTML; although it is good practice to close them to be compatible with XHTML and to be more organized but the decision is yours.

Differences between the use of the BR tag in HTML and XHTML

As you should know, XHTML is the most organized and strict form of HTML, things that we can do in HTML and are supported by our browsers we cannot do in XHTML; in HTML the <br> tag does not have to close, as we showed previously; while in XHTML the <br /> tag does have to close, like the one shown above.

Example of using the br tag: Line breaks in HTML

As we indicated, the BR tag is especially useful for breaking between lines; itself is its only use in this markup language:

<p> To break <br> lines in text, <br>use the br </p> element

To break lines
in a text,
use the br element

Another form of line breaks: Paragraphs in HTML

We can also include line breaks with our paragraphs with the corresponding tag:

<p> To break <p></p> lines in text, <br>use the br </p> element

To break lines

 

in a text,
use the br element

 

You can have more information about the use of the p tag in a previous post.

To indicate to the browser that we want to put a line break as a paragraph; With this we will not have to worry if the space is greater than that used in the writing with our paragraphs since it is equivalent to being the same label

BR Tag Events, CSS, and Attributes

The br tag does not have any particular attribute or event, the global ones for the HTML API if we are talking about CSS, it does not take any particular styles except the display:none to hide the element and therefore the jump of line.

w3schools recommends using the <br> element to break lines, but not to separate paragraphs; For the latter it is better to use other techniques such as the margin property in CSS.

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.