Using <br> instead of <br />

This question already has an answer here:

  • HTML 5: Is it <br>, <br/>, or <br />? 24 answers

  • 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.


    <br>是在HTML做到这一点的有效方式,并<br/>是做在XHTML的方式。


    This is a duplicate, but anyways, there is no difference other than preference, at least in HTML. In XML, <br /> is more correct.

    链接地址: http://www.djcxy.com/p/15678.html

    上一篇: 如何用<br />标签替换字符串中的所有换行符?

    下一篇: 使用<br>而不是<br />