Standards, BEST PRACTICE, accessibility, usability, XML
CSS should not be used to present homemade XML as web pages. You end up with nothing but style. Neither man nor machine can understand the structure of your document. CSS should only be used for widely supported XML applications like XHTML.
Almost any book about XML has a chapter telling us that we can use CSS to style XML for presentation. I don't know why so many get CSS for XML mostly wrong. XML is the new meta markup language for making markup languages. XML is for making "new sets of tags", xml vocabularies, xml applications.
XML is for storage, publishing and exchange of data and documents between systems. Most XML applications are specialized to do one of the three. Only a small fraction of all xml applications is made to be used for publishing, and even fewer for presentation directly on the Internet using CSS. For the Internet we will most often use XHTML.
XHTML has a known set of elements and attributes. The DTD of XHTML is public and part of a standard (Recommendations). The browsers, seach engines like Google, screen readers, etc., know the markup of XHTML in advance. That is the reason why CSS works for XHTML, and why styling your own XML is just plain stupid.
Since the browsers know the markup, "the DTD", of XHTML, they have a default stylesheet (CSS) ready for showing the web pages. When you, the web page author, add styles to an XHTML document, you most often only have to bother with the very few properties that you for some reason would like to change. As a web page author you can count on the default stylesheet in the browser for most of the styling.
When you try to style some XML of your own, the browser has no default stylesheet to use. The browsers have no way of knowing what your elements and attributes mean. You must set up styles for all the markup in your XML document, and you must specify almost all properties.
If you try to CSS your own XML, you run into a lot of problems. How make links? For that you must use the XLink standard (W3C Recommendations) not yet supported by Internet Explorer. How will you use images? How will you make an ordered list that nicely changes the numbers of the items when needed? How will you make tables to present some of your data?
Even the day Xlink is widely supported, and even if we are good enough coders to solve the above problems, we should still not use XML directly for web pages. Why reinvent your own private "myXHTML" just to confuse the world? Division of labor has existed for a long time. What you come up with is almost for certain not even half as good.
How are the great web crawlers indexing the Internet, Google, etc., supposed to make sense of your homemade XML markup for webpages? Where is your "page title" so important to Google as link text, etc. Where are your headings, h1, h2? Google and other search engines have no way of knowing what is what in your document, no way of knowing if a search term is found in a headline or in a footnote. Your web pages are most likely ignored.
What about blind people and their screen readers? How are they supposed to make use of your web pages? No "page title" to identify it. No known markup for heading levels, lists, paragraphs, tables, strong, etc. How can the screen readers inform the blind about the structure of your document when they have no way of knowing the meaning of your markup?
Most XML applications are for storage and/or exchange of data and documents only. We should not try to view them directly using CSS. Think of XML as a database format in these cases. Only a few XML applications like XHTML are optimized to be published on the Internet and viewed in an ordinary browser.
One day the browsers will also support a few other XML applications like SVG (Scalable Vector Graphics). For some other XML applications we will need special browsers, but most XML applications are just a way to markup, store and exchange documents and data.
If the browsers don't have a default stylesheet for an XML application, don't style it, but think of it as an XML data store. If we want to view XML from our XML data store, we should most often use XSLT to transform it to some format of presentation like text, pdf or a well-supported XML application optimized for presentation on the net like XHTML.
Copyright © Jesper Tverskov, 2004
Last updated 2006-06-16