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
strike, and attributes like
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
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
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.
- Previous post: CSS World Awards
- Next post: MT-Blacklist 1.65, Movable Type 2.65 and Perl 5.8.8
Subscribe / follow
DreamHost web hosting
Use the promo code 456BEREASTREET3 to save USD 20 when you sign up for DreamHost