Media Defaults

From CSS Discuss

Jump to: navigation, search


Default Values for Media


There are four broad methods for invoking Media Stylesheets . If you don't specify a value (or values) for media type then a default is applied. Netscape 4 has a particular quirk with the first of the four methods.

Note that this document describes what should happen regarding defaults according to the HTML and CSS specs. It's always possible that browsers may behave differently (surprise). The best course of action is to always specify media, even if it's media="all".

1. HTML <link> element

If you invoke an external stylesheet using the HTML <link> element, then the default is media="all" HTML4.01 spec 14.4.1.

Exceptionally, Netscape 4 will invoke the stylesheet only if media="screen" or if there is no media attribute. In both cases, the stylesheet will be applied to all media.

2. HTML <style> element

If you define styles using the HTML <style> element, then the default is media="screen" HTML4.01 spec 14.2.3 and not, as might be expected, media="all". Bert Bos of W3C tells me [personal communication October 2004] that this is a known error (anomaly) in the HTML4.01 spec (although no erratum has been published) that has been fixed in XHTML2.

3. CSS @import rule

If you invoke a stylesheet using the CSS @import rule, then the default is all media (i.e. an unconditional import) CSS2.1 spec 6.3.

NS4 doesn't support the @import rule at all. This forms the basis of a common workround to exclude styles that NS4 can't handle.

4. CSS @media rule

If you define styles using the CSS @media rule, the spec CSS2.1 Section 7.2.1 requires that at least one media value is specified. However, it is silent on what happens if you omit a media value or values.

Since an @media rule with no media is invalid, the implied error behaviour is that the entire @media rule is ignored, which conforms to common sense.

About this page

This page was created in August 2004 by Jim Wilkinson, who welcomes contributions, comments and corrections, particularly with regard to the actual behaviour of browsers where it differs from the specs.

Personal tools