barak manos
barak manos

Reputation: 30136

Using the `br` tag in an HTML webpage

Here is a summary from http://www.w3schools.com/tags/tag_br.asp for the <br> tag:

So can I safely use <br> in a webpage (or any other HTML snippet) without closing it?

And if I'm advised to close it, then is this the correct way: <br><br/> (with nothing in between)?

Upvotes: 1

Views: 148

Answers (4)

Omri
Omri

Reputation: 94

It doesn't matter if you use <br> or <br/> in the newer versions of HTML, but it is recommended to close all the HTML tags, using <br/> (and not <br></br>). The same is tru for <hr/>, <img src="..." /> etc.

Upvotes: 1

Stefano Sanfilippo
Stefano Sanfilippo

Reputation: 33046

Since <br> is a void tag (meaning it cannot wrap any content inside), you can either use it as <br> or <br/> (the trailing / will be ignored), but <br></br> is invalid.

If you want your markup to be valid XML, then use <br/>, but that is irrelevant for a HTML parser.

This, according to the (latest) HTML5 specs, section elements.

Upvotes: 4

Martin Zikmund
Martin Zikmund

Reputation: 39072

It is safe and works but it is not something generally recommended.

HTML5 doesn't care if you close it or not, it should work everywhere well, but I always prefer to use the valid structure that conforms to XML standards.

Upvotes: 0

Lawrence Thurman
Lawrence Thurman

Reputation: 677

For older HTML yes, for modern, like 4 or 5 is has become a standard to close all tags. There may come a day when they will just not work anymore. Other words, todays HTML is strict like XHTML.

Upvotes: 0

Related Questions