Not syntactically, no. But those end tags tend to make the markup much more easy to read for human beings.
Yes, there must be a matching end tag for every start tag in X(HT)ML.
The element types declared as EMPTY
in the HTML DTDs must not have an end tag. There are no </br>
, </hr>
, </img>
, </meta>
tags etc in HTML.
For element types that can have content, the end tag is required even if the element is empty (except for those element types that have an optional end tag).
In XHTML it’s different, since it must be well-formed. Even empty elements need a closing tag. Instead of <br></br>
etc XML offers a shorter notation, <br/>
. It’s called a null end tag (NET), and it’s a feature that is theoretically available even in HTML (albeit with a different syntax), but no browsers support it in HTML.
Using <br/>
in HTML actually means something different than in XHTML (it means <br>>
). But all browsers have buggy parsers that interpret it as <br>
, which is why pretend-XHTML works.
In real XHTML you can use NET syntax for any empty element, even if it’s not declared as EMPTY
. For instance, the following is perfectly valid XHTML:
<script type="application/javascript" src="script.js"/>
You can’t use this in pretend-XHTML, though. NET syntax can only be used with EMPTY
elements in pretend-XHTML.
In HTML you just use <br>
and <hr>
. In XHTML you’d normally use <br/>
and <hr/>
. In real XHTML you could also use <br></br>
and <hr></hr>
, but there’s no reason to. In pretend-XHTML it’s customary to leave a space before the NESTC delimiter (<br />
etc) to cater for extra-buggy HTML parsers.