4 ms·
Could you explain the <br> vs <br /> difference in HTML? HTML5 spec says that void elements may optionally include slash[1], and from the wording I'd assume tha
by zokier 16y ago
Could you explain the <br> vs <br /> difference in HTML? HTML5 spec says that void elements may optionally include slash[1], and from the wording I'd assume that it means that they should be treated equally.
[1] http://dev.w3.org/html5/markup/syntax.html#void-element http://dev.w3.org/html5/markup/syntax.html#void-element
- mambodog 16y agoAs I understand it, basically the 'self-closing tags' are considered valid markup, but this comes under WHATWG's philosophy of trying to be inclusive as much existing markup that is out there as possible (within reason). This is in opposition to the strictness of XHTML's approach. This post by hixie indicates that self-closing tags are allowed to 'ease migration': http://lists.whatwg.org/pipermail/help-whatwg.org/2008-August/000137.html http://lists.whatwg.org/pipermail/help-whatwg.org/2008-Augus... I believe the 'spirit' of the spec would imply that <br> is the best practice when writing new markup. HTML5 maintains no pretence of being XML.
- rimantas 16y agoThis is actually very tricky subject. In short: HTML is SGML application, and in SGML features section (http://www.w3.org/TR/html401/sgml/sgmldecl.html http://www.w3.org/TR/html401/sgml/sgmldecl.html) it has this little tidbit: SHORTTAG YES. This allows the usage of so called null-end tags: ability to close the tag with a single character, which happens to be solidus ("/"). So in essence <br/> in HTML should mean the same as <br>>, i.e. "/" closes the tag and then ">" is just some text. If you try to validate document using xhtml markup as html you may get this warning from validator: NET-enabling start-tag requires SHORTTAG YES The sequence <FOO /> can be interpreted in at least two different ways, depending on the DOCTYPE of the document. For HTML 4.01 Strict, the '/' terminates the tag <FOO (with an implied '>'). However, since many browsers don't interpret it this way, even in the presence of an HTML 4.01 Strict DOCTYPE, it is best to avoid it completely in pure HTML documents and reserve its use solely for those written in XHTML. In XML (and hence XHTML) with the help of some mind-boggling trickery (Web SGML Adaptations Annex) you can have things like <foo/>