I\'m working with a web page the translates content from XML to HTML and then displays it on the HTML template page. I have a single page where some elements are getting mi
Missing tags are treated differently depending on tag. When HTML specifications allow end tag omission, e.g. for
, all browsers imply them and are even required to do so. The situation is different for invalid end tag omission. For example,
div
element is interpreted as containing much more than intended, and this may have drastic effects if there are style sheets that format the element (or scripts that process it). For text-level elements like em
, processing is more complicated: an end tag is implied when the end of an enclosing block element is encountered but the text-level element is opened again at the start of the next block! This is described and other specialties are presented in section 8.2.8 An introduction to error handling and strange cases in the parser of the HTML5 spec.
All this applies to HTML syntax. When using XHTML syntax and the browser has been instructed to process the data as being of an XML content type such as application/xhtml+xml, no end tag omission is tolerated: the first omitted end tag, being a well-formedness violation, is treated as a fatal error. This means that document content is not shown at all; an error message is shown to the user instead. This is very rare situation on web pages, since there is seldom a good reason to use “real XHTML” (i.e. XHTML processed by XML rules).
The conclusion is that you should generate valid HTML and at least in some tests validate it, using a suitable validator like http://validator.w3.org.