Reputation: 30136
Here is a summary from http://www.w3schools.com/tags/tag_br.asp for the <br>
tag:
<br>
tag inserts a single line break.<br>
tag is an empty tag which means that it has no end tag.<br>
tag has no end tag.<br>
tag must be properly closed, like this: <br />
.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
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
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
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
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