Is it OK to use a self closing DIV tag?
According to the XML declaration and the XHTML 1.0 and 1.1 document definitions, this is fine: the null-end tag (>
) may be used when immediately following the null-end start tag closer (/
), and your code is equivalent to <div id="myDiv"></div>
.
It's a different matter entirely whether any particular consumer will be able to process this correctly.
The SGML declaration used by HTML 4.01 allows tag shortening, but it has a different syntax for the null-end tags; there you can write <div id="abc"/this is a non-empty div/
. Again, mileage may vary as for browser support. (My money is on "none".)
Future versions of HTML (HTML5? if that name is still alive) are no longer implemented as SGML languages, and therefore they simply allow what they say they do, without recourse to a formal grammar.
No. HTML 4.x doesn't have any concept of self closing tags.
It is valid in XHTML.
Div's are not valid self closing tags. To have an empty div it would be better to do this:
<div id="myDiv"></div>