I've tried checking other answers, but I'm still confused--especially after seeing W3schools HTML 5 reference.
I thought HTML 4.01 was supposed to "allow" single-tags to just be <img>
and <br>
. Then XHTML came along with <img />
and <br />
(where someone said that the space is there for older browsers).
Now I'm wondering how I'm supposed to format my code when practicing HTML 5.
<!DOCTYPE HTML>
Is it <br>
, <br/>
or <br />
?
<br>
and<br/>
render differently. Some browsers interpret<br/>
as<br></br>
and insert two line breaksIn HTML (up to HTML 4): use
<br>
In HTML 5:
<br>
is preferred, but<br/>
and<br />
is also acceptableIn XHTML:
<br />
is preferred. Can also use<br/>
or<br></br>
Notes:
<br></br>
is not valid in HTML 5, it will be thought of as two line breaks.<br/>
but not<br />
Reference:
In HTML5 the slash is no longer necessary:
<br>
,<hr>
As many others have covered, both
<br>
and<br/>
are acceptable.I guess the tradeoff is the better readability and backward compatibility of
<br/>
versus sending one less character to the end users with<br>
.And since Google uses
<br>
so will I.(Of course keep in mind that they might be serving me
<br>
because I'm using Chrome which they know supports it. In IE they might still be serving<br/>
)Ummm.....does anyone know a SINGLE vendor, user-agent, or browser maker that has ever followed the W3C Specifications 100%??? So if HTML5 says it supports all three break element versions, you can bet the vendors support the same and even more sloppier versions!
The ONLY thing that matters in this debate is to CONSISTENTLY use coding that also happens to follow XML specifications as well as HTML specifications when possible. That means you should use the correct XML version of the break tag and encourage all your team to do the same:
The same space-slash format should apply for the img, a, hr, and meta tags in your code. Why? Because:
Besides, in the robotic and machine world that's here, where robots don't have the same Human-interface coding problems HTML5 solves for us, they will gladly go back to XML data systems and parse such UI web pages much faster when converted to XML data.
If you're interested in comparability (not compatibility, but comparability) then I'd stick with
<br />
.Otherwise,
<br>
is fine.