4

This question refers specifically to a script tag. I think it applies also to a div, but I just want to make sure. Is this legal html or not?

<div/>

Community
  • 1
  • 1
ripper234
  • 222,824
  • 274
  • 634
  • 905
  • 1
    in HTML, anything goes. In strict XHTML documents, no, it's not allowed. – Marc B Oct 13 '11 at 16:49
  • 2
    Possible duplicates: [
    vs
    ](http://stackoverflow.com/questions/6753748/div-div-vs-div), [Is there a difference between
    and
    ?](http://stackoverflow.com/questions/1411182/is-there-a-difference-between-div-and-div-div)
    – Dennis Oct 13 '11 at 16:51
  • That's invalid Markup, you will have to use the closing tag with <div> In any case there is absolutely useless to have a div close without anything in it :| – Aaditi Sharma Oct 13 '11 at 17:04

1 Answers1

8

No it isn't legal HTML.

The div element is not described as an EMPTY element in the DTD (4.01).

The definition doesn't have EMPTY:

<!ELEMENT DIV - - (%flow;)*            -- generic language/style container -->
<!ATTLIST DIV
  %attrs;                              -- %coreattrs, %i18n, %events --
  %reserved;                           -- reserved for possible future use --
  >

Contrast with the definition for HR:

<!ELEMENT HR - O EMPTY -- horizontal rule -->
<!ATTLIST HR
  %attrs;                              -- %coreattrs, %i18n, %events --
  >
Oded
  • 489,969
  • 99
  • 883
  • 1,009