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\" singl
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 (/
).
Most of the cases in HTML, the tags are in pair. But for a line break you don't need a pair of tags. Therefore to indicate this, HTML uses <br/>
format. <br/>
is the right one. Use that format.
<br>
tag has no end tag in HTML
In XHTML, the <br>
tag must be properly closed, like this: <br />
In XML every tag must be closed. XHTML is an extension of XML, hence all the rules of XML must be followed for valid XHTML. Hence even empty tags (nodes without child nodes) like
should be closed. XML has a short form called self closing tags for empty nodes. You can write <br></br> as <br />
. Hence in XHTML <br />
is used.
HTML is very lenient in this regard, and there is no such rule. So in HTML empty nodes like <br> <hr> <meta>
etc are written without the closing forward slash.
HTML
<br>
<hr>
<meta name="keywords" content="">
<link rel="canonical" href="http://www.google.com/">
XHTML
<br />
<hr />
<meta name="keywords" content="" />
<link rel="canonical" href="http://www.google.com/" />
Not all tags can be self closed. For example, a tag like <script src="jQuery.min.js" />
is not allowed by XHTML DTD.
If you're interested in comparability (not compatibility, but comparability) then I'd stick with <br />
.
Otherwise, <br>
is fine.
<br/>
is the most appropriate one. This tag notation can also be used in Reactjs where a line break is required instead of <br>
In HTML (up to HTML 4): use <br>
In HTML 5: <br>
is preferred, but <br/>
and <br />
is also acceptable
In 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: