objectivity part II

July 25, 2004

objectivity part II

So I was wrong in stating that the <object> would supersede the <img> in XHTML 2.0. From the XHTML FAQ:

<img> is being replaced in XHTML2, but by something else (although you could use <object> if you wanted).

...

XHTML2 [says] that all images are equivalent to some piece of content; it does this by allowing you to put a src attribute on any element at all. What this says is: if the image is available, and the browser can process it, use it, otherwise use the content of the element.

Because browsers have mishandled the <object> so spectacularly, this is a much more elegant and practical alternative that looks to be 100% backwards compatible. Further investigation shows that other types of content (audio, video, animations) can be embedded as well. Let's see a couple practical examples:

Image replacement:

<h1 src="title.png" type="image/png">Document Title</h1>

This is undoubtedly the Holy Grail of image replacement techniques. It solves and/or avoids all of the problems of existing methods.

Embedding audio:

<p src="hokeypokey.wav" type="audio/x-wav">
You put your right foot in,
You put your right foot out...
</p>

While it is nothing revolutionary, it is certainly much cleaner and more reliable than existing methods of doing this.

The great thing is, both of these examples will work "correctly" in every browser at this very moment. That is to say, user agents that acknowledge the src attribute on elements and support the mime type of the object being embedded will (dis)play it. Those that do not will simply show the contents of the tag instead. Thus it is backwards compatible.

But don't expect to be able to use this in production any time soon. XHTML 2.0 is still a working draft, which means it could still change considerably over the coming months. Once it becomes a recommendation, it will be a good while before it is adopted by browser manufacturers and even longer before those browsers constitute the majority. But it goes to show that the W3C has come up with an elegant solution to the object problem and is working hard to keep things going in the right direction.

For those who can't wait and want to start playing with this right away, I've come up with an easy way for current browsers to fully emulate this behavior.

Posted by jon at July 25, 2004 4:45 AM

Comments