Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it allowed to have a self-closing div tag in an html document?

Tags:

html

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/>

like image 851
ripper234 Avatar asked Feb 23 '23 17:02

ripper234


1 Answers

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 --
  >
like image 103
Oded Avatar answered Feb 25 '23 06:02

Oded