style and script tags in HTML body… why not?

Although the specs explicitly state style tags are not permitted in the body tag, specs aren’t all that matters. Style tags are supported in the body by every major browser, and that’s ultimately how users see your site.* While there has long been a drive for better standards and standards support in the browser industry, there’s also long been a general push to render broken documents as well as can be.

Google, who leads the HTML5 spec effort, simultaneously maintains google.com which violates specs to save bytes, by leaving the quotes out of its attribute values, using selector hacks against the CSS spec, including script tags with no type or language, and link tags with no type. A purist could argue one of the most used sites on the internet is violating the specs and in serious danger of being horribly misrendered. Or, we can reason that no browser will enter popular use that can’t render such widely used hacks on the spec.

So, the question is more of which way the browser industry is going – which again is one of both better specs, but also doing their best to honor the intent of pages that violate those specs. My bet is style tags will keep working in the body for a long time to come.

*As of this writing, style tags in the body are supported with an HTML5 doctype in Firefox 3+, IE6+, Safari 2+, Chrome 12+. Support likely goes back farther but those browsers are rarely seen on the interwebs.

Leave a Comment