Why would a site ever use </img> in HTML markup
I encountered this page https://www.google.com/accounts/ServiceLogin, a Google service login page that (beyond just omitting a doctype), contains 6 instances of </img>
For example,
<img src="https://www.google.com/accounts/google_transparent.gif"
alt="Google">
</img>
Why would they ever do that? What benefit/functionality/grandfathering do they possibly achieve?
Anything I've ever read about HTML and XHTML has made it pretty unequovical:
In HTML 4.01 and prior, <img>
tags are never to be closed ( <img src="img.gif" alt="text" >
).
In XHTM开发者_开发百科L, <img>
tags are to be closed using self-closing syntax ( <img src='img.gif' alt="text" />
)
In HTML5, (my understanding is that) either syntax (open or self-closed) is acceptable, but still never </img>
.
I'd say this is a bug. In at least one case it seems to be just producing totally invalid code:
<img class=logo
src='https://www.google.com/intl/en/images/logos/accounts_logo.gif'
alt="Google" />
</img>
You can see the img tag is self closing and being closed by a separate closing tag. Clearly unintended. And its inconsistent which is a little weird too. I'd suggest e-mailing them and asking. :)
I've found the only (proposed) way this code is ever actually compliant, though it does not apply in Google's case (since they lack a DOCTYPE).
XHTML 2, which was proposed and then scrapped, implements a </img>
tag as a way to replace the alt attribute.
So, instead of this in XHTML 1.0/1.1:
<img src="monkeys.gif" alt="Monkeys throwing feces" />
You'd have this
<img src="monkeys.gif">Monkeys throwing feces</img>
Where 'Monkeys throwing feces' only displays if monkeys.gif fails to load.
This would make <img>
behave as other content embedding tags, like <object>
.
In the spec's words,
The img element is a holder for embedding attributes such as src. Since these attributes may be applied to any element, the img element is not strictly necessary, but is included to ease the transition to XHTML2. Like the object element, this element's content is only presented if the referenced resource is unavailable.
Maybe their HTML-generator closes every <tag>
with a corresponding </tag>
, which is just a programmatically lazier alternative to writing <tag/>
for such single tags.
精彩评论