8 Media types

Contents

  1. Introduction to media types
  2. Specifying media-dependent style sheets
    1. The @media rule
    2. The media-dependent @import rule
  3. Recognized media types
    1. The canvas
      1. Scrollable media

8.1 Introduction to media types

One of the most important features of style sheets is that they allow authors to specify how a document is to be presented on different media: on the screen, on paper, with a speech synthesizer, with a braille device, etc.

Certain CSS properties only make sense for certain media (e.g., the 'cue-before' property for aural style sheets). On occasion, however, style sheets for different media types may share a property, but require different values for that property. For example, the 'font-size' property is useful both for screen and print media. However, the two media are different enough to require different values for the common property; a document will typically need a larger font on a computer screen than on paper. Experience also shows that sans serif fonts are easier to read on screen, while fonts with serifs are easier to read on paper. For these reasons, it is necessary to express that a style sheet -- or a section of a style sheet -- applies to certain media types.

The following sections describe how authors may specify different style sheets for different media (all of which participate in the cascade).

8.2 Specifying media-dependent style sheets

There are currently two ways to specify media dependencies for style sheets:

Since these two examples have the same media type, they are semantically equivalent.

8.2.1 The @media rule

An @media rule lists the media types (separated by commas) affected by a set of rules delimited by curly braces.

The @media construct allows style sheet rules for various media in the same style sheet:

  @media print {
    BODY { font-size: 10pt }
  }
  @media screen {
    BODY { font-size: 12pt }
  }
  @media screen, print {
    BODY { line-height: 1.2 }
  }

8.2.2 The media-dependent @import rule

So that user agents can avoid retrieving resources for unsupported media types, authors may specify media-dependent @import rules. These conditional imports   specify comma-separated media types after the URL.

The following rules have the same effect as if the imported style sheet were wrapped in an @media rule for the same media, but it may save the UA a fruitless download.

@import url(fineprint.css) print;
@import url(blueish.css) projection, tv;

In the absence of any media types, the import is unconditional. Specifying 'all' for the medium has the same effect.

8.3 Recognized media types

Due to rapidly changing technologies, CSS2 does not specify a definitive list of media types that may be values for @media . However, user agents that elect to support the devices in the following list must recognize the associated media type:

Media types are case-insensitive.

8.3.1 The canvas

For all media, the term canvas  means "the space where rendering objects are rendered" (see the CSS2 process model). For a screen, the canvas is a rectangular space generally of fixed width and "infinite" length. For paged media, the canvas is a sequence of rectangular page boxes of fixed width and height. For aural media, the canvas is a three dimensional audio space.

Scrollable media 

User agents for scrolled media may implement the canvas as an "infinitely" long (or however long the rendered document is) rectangle that has a fixed width. Users see this canvas through a user agent's viewport , a window or other viewing area on the screen. The canvas may be larger or smaller than the viewport. Typically, when the canvas is larger than the viewport, the user agent will offer the user a scrolling mechanism to bring hidden parts into view.

The user agent generally determines the width of the canvas and may change the dimensions of the canvas when the viewport is resized.

In general, when a document doesn't cover the entire canvas, the User agent should "borrow" the background of the root element. Since the BODY element is often percieved as the root element in HTML, this special rules apply to HTML documents: if the 'background' value of the HTML element is different from 'transparent' then use it, else use the 'background' value of the BODY element. If the resulting value is 'transparent', the rendering is undefined.

This rule allows the following:

  <HTML style="background: url(http://style.com/marble.png)">
  <BODY style="background: red">

In the example above, the canvas will be covered with "marble". The background of the BODY element (which may or may not fully cover the canvas) will be red.

Note that no structural element of a document corresponds to the canvas. In HTML, until other means of addressing the canvas become available, we recommend that authors set canvas properties on the BODY element.