tags:

views:

160

answers:

4

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 XHTML, <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>.

+1  A: 

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.

eumiro
Interesting thought, though that doesn't seem to be the close for the `<br>` tags (ie, no instances of `</br>`)
yc
+3  A: 

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. :)

Chris
Nah, there's a ton of anecdotal evidence floating around the interwebs that the Google engineers just don't care about writing standard compliant code. Funny, since they're now one of the major browser vendors...
Yi Jiang
Maybe. I've certainly heard mention of them doign it to shorten pages but I can't see any reason to leave these things in and make the pages longer...Ah well, mine is not to question our great overlords at google... :)
Chris
+1  A: 

Someone wrote it years ago and now nobody wants to touch it and break Google ;)

gertas
+1  A: 

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.

yc