Why is the style attribute allowed in strict doctypes?

The strict HTML and XHTML doctypes encourage the separation of semantic and presentational markup by disallowing the use of elements such as center, font and strike, and attributes like align, bgcolor, and border. So why is the style attribute allowed in strict doctypes? And why is it allowed (but strongly discouraged) in XHTML 2.0?

I admit that I sometimes use the style attribute. One example is when a site is designed to have a decorative photo as a background image in the masthead, and the client needs to be able to use the CMS to upload their own images. If the image is purely decorational it doesn't belong in the markup and should be specified in the CSS, preferably in an external CSS file. But doing so would require the CMS to make changes to the CSS file, which few CMSs are set up to do out of the box. Using a style attribute is much more convenient. Every time I use one I feel a bit dirty though. It's like using the javascript: pseudo-protocol or specifying event handlers like onclick inline. I'd rather avoid it.

An alternative approach would be to make the CMS write the necessary CSS to a style element in the document's head section, using a class or an id to apply it to the element that holds the background image. While not the ideal solution it will at least let you get rid of those style attributes.

After reading the above, you'll hardly be surprised that I agree with Emil Stenström: Inline CSS should not be allowed in strict doctypes. It seems like the logical choice since disallowing it would help enforce the separation of semantic and presentational markup. Then there's always the faint hope that it would send a message to those CMS vendors who are particularly guilty of sprinkling style attributes all over the markup their products produce that they are not following best practices.

Posted on June 6, 2006 in Quicklinks, (X)HTML