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 />
?
In HTML
<br>
and in XHTML<br/>
.I will suggest you to use
<br/>
.The elements without having end tags are called as empty tags. In html 4 and html 5, end tags are not required and can be omitted.
In xhtml, tags are so strict. That means must start with start tag and end with end tag.
According to the spec the expected form is
<br>
for HTML 5 but a closing slash is permitted.Both
<br>
and<br />
are acceptable in HTML5, but in the spirit of HTML,<br>
should be used. HTML5 allows closing slashes in order to be more compatible with documents that were previously HTML 4.01 and XHTML 1.0, allowing easier migration to HTML5. Of course,<br/>
is also acceptable, but to be compatible with some older browsers, there should be a space before the closing slash (/
).Simply
<br>
is sufficient.The other forms are there for compatibility with XHTML; to make it possible to write the same code as XHTML, and have it also work as HTML. Some systems that generate HTML may be based on XML generators, and thus do not have the ability to output just a bare
<br>
tag; if you're using such a system, it's fine to use<br/>
, it's just not necessary if you don't need to do it.Very few people actually use XHTML, however. You need to serve your content as
application/xhtml+xml
for it to be interpreted as XHTML, and that will not work in old versions of IE - it will also mean that any small error you make will prevent your page from being displayed in browsers that do support XHTML. So, most of what looks like XHTML on the web is actually being served, and interpreted, as HTML. See Serving XHTML as text/html Considered Harmful for some more information.In validation, of this question, it really depends on what
!DOCTYPE
you are trying to get verification through.My personal favorite is
4.01 Trans
where I just use the<br/>
and it clears the warnings and errors that may have popped up during validationStrict is a much more complicated beast, It HATES
"SHORTTAGS"
and quite literally only wants the<br></br>
In
HTML5
or the "LAX" of the code world, there really isn't a right answer because itdetects every example you put up
there as correct......In the end, I think all that matters
is what validation YOU PREFER
orthe person that you are working for prefers
... with thelackadaisical
movement in code strictness inhtml5
we are seeing some VERY LAZY CODERS