dionidium.com

Wayne Burkett's Weblog | Home

Extending XHTML: Target and Strict
09:51PM CST May 07, 2004 | Comments [6]

That the target attribute is not by default allowed in valid XHTML 1.1 or XHTML 1.0 Strict continues to be a source of frustration for designers. It simply doesn't have to be. Others -- Jacques Distler and Dave Hodder, namely -- have pointed out that XHTML is designed to be modular and that it's easy to extend the specification by creating your own DTD. Jeffrey Zeldman suggests caution:

This approach is very much in the spirit of XHTML extensibility but leaves open the question of whether browsers that use DOCTYPE switching will render such a page in Standards or Quirks mode. Such browsers (IE, Mozilla/Netscape, and now Opera 7) do not download and parse DTDs; they rely on known DOCTYPE declarations stored in an internal database to determine how a page should be rendered.

Zeldman's better-safe-than-sorry response is understandable, but there's no evidence that Internet Explorer, or any other browser, will punish you for extending XHTML. In fact, there's a lot of evidence that custom DTDs are supported by the major players. Mozilla, for example, invokes Standards Mode at the sight of any unknown DOCTYPE, as well as for DOCTYPEs extended via an internal subset. (I've been using an internal subset to extend XHTML 1.1 since September 2003.) Internet Explorer, too, defaults to Standards Mode when confronted with an unknown DOCTYPE. Opera's docs don't explicitly claim similar support, but the following tests suggest identical behavior.

See for yourself:

  1. An XHTML 1.1 document that uses Jacques Distler's DTD. Opera 7, Internet Explorer 6, and Mozilla 1.7 each have no problem rendering this document in Standards Mode.
  2. An XHTML 1.1 document extended via an internal subset of the DOCTYPE declaration. Rendered in Standards Mode by Opera 7, Internet Explorer 6, and Mozilla 1.7.
  3. An XHTML 1.0 Strict document extended via an internal subset of the DOCTYPE declaration. This document is also rendered in Standards Mode by Opera 7, Internet Explorer 6, and Mozilla 1.7.

The tests determine if extensions are invoking Quirks Mode through use of the JavaScript compatMode property, which returns BackCompat when in Quirks Mode and CSS1Compat in Standards Mode, and the CSS box model, which behaves differently in Quirks and Standards Modes.

Extending via an external subset of the declaration is convenient (since you don't have to create your own DTD), but this method leaves a short string of characters -- the end of the subset, in fact -- at the top of pages served as text/html. Documents served as application/xhtml+xml do not have this problem. As such, Jacques's method is the best solution for most cases.

The test documents are served as text/html for two reasons:

  1. Mozilla always renders properly-served XML in Standards Mode.
  2. Internet Explorer simply can't render XML documents served properly, in any mode.

In other words, serving XHTML as application/xhtml+xml to Gecko browsers gets you Standards Mode every time, as does serving a custom DTD to any browser. There's no indication that extending XHTML will rain on your standards parade.

Update: The Mozilla "View Page Info" tool (Ctrl+I) also tells whether a particular page is in Standards Mode or Quirks Mode. I wasn't aware of this feature when I first wrote these tests.

#1 | 08:16PM UTC June 16, 2004 | Wayne
Wayne

Extending via an external subset of the declaration is convenient (since you don't have to create your own DTD), but this method leaves a short string of characters -- the end of the subset, in fact -- at the top of pages served as text/html. Documents served as application/xhtml+xml do not have this problem. As such, Jacques's method is the best solution for most cases.

I should have said, "Jacques's method is the best solution for most cases, if you're using XHTML 1.0 Strict."

Don't copy Jacques's method directly if you plan on serving your documents as text/html. You shouldn't be sending XHTML as text/html in the first place, but you definitely shouldn't if you're using XHTML 1.1.

And keep in mind that text/html is the only thing keeping you from the other solutions, anyway. You won't get the extra string of characters if you're serving your documents properly, as aplication/xhtml+xml. And, you don't have to worry about Quirks Mode if you serve as aplication/xhtml+xml; the browsers that support it always invoke Standards Mode for documents served this way. It's another benefit of doing things correctly.

#2 | 08:06AM UTC July 27, 2004 | Paul
Paul

I have tried Number 2:

An XHTML 1.1 document extended via an internal subset of the DOCTYPE declaration.

No matter what I do, both Internet Explorer and Firefox display ]> at the top of the document.

I have also placed <meta http-equiv="Content-type" content="application/xhtml+xml; charset=UTF-8" /> within the html code.

I assume IE would display the characters ]> but Firefox?

What is the deal?

#3 | 08:07AM UTC July 27, 2004 | Paul
Paul

I have tried Number 2:

An XHTML 1.1 document extended via an internal subset of the DOCTYPE declaration.

No matter what I do, both Internet Explorer and Firefox display ]> at the top of the document.

I have also placed <meta http-equiv="Content-type" content="application/xhtml+xml; charset=UTF-8" /> within the html code.

I assume IE would display the characters ]> but Firefox?

What is the deal?

#4 | 08:16AM UTC July 28, 2004 | Daniel
Daniel
With Firefox/Mozilla, if you want to get rid of ]> characters and have entities declared in your internal subset expanded, you not only have to use the "application/xhtml+xml" content type but also to use the "xhtml" extension for your file! Unless you configure your server to accept html files with application/xhtml+xml content-type. But this not the case in default Apache MIME type configuration file. And take care that "text/html" MIME type is also associated with the "html" file extension. So to avoid any mess, just use the "xhtml" extension.
#5 | 08:29AM UTC July 28, 2004 | Daniel
Daniel
I should have pointed out the Mozilla developer documentation page explaining MIME type handling: see the "How Mozilla determines MIME Types" page and the Content-Type "hints" paragraph.
#6 | 08:09AM UTC August 18, 2004 | Wayne
Wayne

Sorry for being so late to reply. I missed these comments until now.

To be clear, Mozilla will not display the ]> if the document is served as application/xhtml+xml; the file extension has nothing to do with it. Daniel's point is well-taken, however; you will need to configure your server to send static files with the proper MIME type; meta http-equiv alone won't cut it.