Re: Closed </li> element

2017-06-30 13:35 GMT+03:00 Jens Oliver Meiert <jens@meiert.com>:

> I have found an issue. Validator does not pay attention to unclosed <li>
> > element if it goes after closed </a>.
>
> It does, it’s just perfectly valid HTML.


More exactly, it is valid (there is really no such thing as being
imperfectly valid) in any version of HTML except those based on XML. The
incantation <!DOCTYPE html> specifies HTML5, and the validator seems to
treat this as HTML5 in HTML serialization, where indeed </li> is always
optional.

In XML serialization of HTML5, end tag omission is not allowed. I cannot
find any way to tell the validator to use XML serialization rules when
using direct input. But if you validate a document via URL and the HTTP
headers specify an XML content type, then XML serialization rules will be
applied.

Should you wish to do that, you would need to use the xmlns attribute, with
<html xmlns="http://www.w3.org/1999/xhtml">
instead of plain <html>.

Then you would get the error message

*Error*: XHTML element li
<http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-li-element>
not
allowed as child of XHTML element li
<http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-li-element>
in
this context. (Suppressing further errors from this subtree.)

It’s somewhat cryptic (as XML validation messages often are), but it
clearly points at the issue.


> (Omitting *all* optional tags can be a very effective way of
> simplifying HTML, but it’s not a wide-spread practice.)


I have no statistics on this, but omitting omissible end tags was common
practice when the Web was young. It was XHTML advocacy that made people
think they gain something by using omissible end tags.

Yucca

Received on Friday, 30 June 2017 10:55:39 UTC