Liorean's Alternate Stylesheet Hack

Test of Filter

This text will be green if the rule has been applied.

Code Syntax

<link rel="stylesheet" type="text/css" href="styles.css" title="default" />
<link rel="stylesheet" type="text/css" href="other.css" title="don't select" />

Browser Support / Behaviour

Applied By

Not Applied By


Special Notes

According to the HTML 4.01 specs on external style sheets, the first style sheet with a title attribute is considered the preferred stylesheet. Any other titled stylesheets (whether specified through a <link>, <meta>, or <style> element) will be considered alternate stylesheets and shouldn't be applied along with the preferred stylesheet. Therefore, standards-compliant browsers will not apply this stylesheet (so the text in the example block should be red in compliant browsers).

In some browsers, the user can view a list of alternate stylesheets and change from the preferred to any alternate stylesheets. If you are using this technique as a CSS hack, you probably don't want to allow users to manually switch from your preferred stylesheet (containing rules for all browsers) to the alternate one (containing rules just for non-compliant browsers). There isn't anything you can do to prevent them from doing this. You could give the alternate stylesheet a name that would suggest that users might not want to select it as in the example (the title of the stylesheet is generally used to identify the stylesheet to the user).

More information