When I started learning HTML from w3schools, they were using this <br />
. As I started learning ASP.NET, on their forum (ASP.NET Forums) I was told to use <br>
. So I started using the second one.
My Question: What is the difference between <br>
and <br />
? Is there something like browser support?
A lone
<br>
is invalid in XHTML, since XML documents must close each tag they open.<br />
is semantically the same as<br></br>
in XML documents, and is referred to as a self-closing tag, so<br />
is used when writing XHTML, or HTML documents that will be read by an XML parser.This applies to all other tags that do not have a closing tag in HTML, such as
<hr />
and<meta />
.Both are valid HTML, so there is no reason not to use
<br />
, unless you are writing for a broken HTML parser.Note that in XML,
<br/>
is valid. However, older HTML parsers that don't know about self-closing tags have been known to choke on this. If a space is inserted before the tag name and the self-closing tag token (/
) then these parsers see/
as an attribute, or as noise that is discarded. Therefore, one should always make sure to put a space between the element name and the self-closing tag token for compatibility with these broken parsers.