Contents
One of the most important features of style sheets is that they 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 are only designed for certain media (e.g.,
the 'cue-before''page-break-before' property
for aural user agents).only applies to paged media). 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 types 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,Therefore, it is necessary to express that a style sheet --sheet, or a
section of a style sheet --sheet, applies to certain media types.
There are currently two ways to specify media dependencies for style sheets:
@importurl("loudvoice.css")aural;url("fancyfonts.css") screen; @media print { /* style sheet for print goes here */ }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML4.0//EN">4.01//EN"> <HTML> <HEAD> <TITLE>Link to a target medium</TITLE> <LINK REL="stylesheet" TYPE="text/css" MEDIA="print, handheld" HREF="foo.css"> </HEAD> <BODY> <P>The body... </BODY> </HTML>
The @import rule is defined in the chapter on the cascade.
An @media rule
specifies the target media types (separated
by commas) of a set of rulesstatements (delimited by curly
braces). Invalid statements must be ignored per 4.1.7 "Rule sets, declaration blocks,
and selectors" and 4.2
"Rules for handling parsing errors." 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: 12pt13px }
}
@media screen, print {
body { line-height: 1.2 }
}
7.3 Recognized media types A CSS media type names a set of CSS properties. A user agent that claims to support a media type by name must implement allStyle rules outside of the properties that@media rules apply to all media types
that the style sheet applies to. At-rules inside @media are invalid in
CSS2.1.
The names chosen for CSS media types reflect target devices for
which the relevant properties make sense. In the following list of CSS
media types,types the names of media types are normative, but the
parentheticaldescriptions are not normative. They only give a sense of what deviceinformative. Likewise, the media type"Media" field in the
description of each property is meant to refer to.informative.
Media type names are case-insensitive.
Due to rapidly changing technologies, CSS2 does not specify a definitive list ofMedia types are mutually exclusive in the sense that a user agent can
only support one media type when rendering a document. However, user
agents may use different media types on different canvases. For
example, a document may (simultaneously) be valuesshown in 'screen' mode on
one canvas and 'print' mode on another canvas.
Note that a multimodal media type is still only one media type. The 'tv' media type, for example, is a multimodal media type that renders both visually and aurally to a single canvas.
@media .and @import rules with unknown media types are treated as if
the unknown media types are not present.
For example, in the following snippet, the rule on the P element applies in 'screen' mode (even though the '3D' media type is not known).
@media screen, 3D {
P { color: green; }
}
Note.
Future versionsupdates of CSS may extend this list.the list of media types. Authors
should not rely on media type names that are not yet defined
by a CSS specification.
This section is informative, not normative.
Each CSS property definition specifies thewhich media types for whichthe
property must be implemented by a conforming user agent .applies to. Since properties generally apply to several media,media
types, the "Applies to media" section of each property definition
lists media groups
rather than individual media types. Each property applies to all media
types in the media groups listed in its definition.
CSS2CSS 2.1 defines the following media groups:
The following table shows the relationships between media groups and media types:
| Media Types | Media Groups | |||
|---|---|---|---|---|
| continuous/paged | | grid/bitmap | interactive/static | |
| | continuous | tactile | grid | both |
| | paged | tactile | grid | |
| handheld | both | | both | both |
| paged | visual | bitmap | static | |
| projection | paged | visual | bitmap | |
| screen | continuous | | bitmap | both |
| speech | continuous | speech | N/A | both |
| tty | continuous | visual | grid | both |
| tv | both | visual, | bitmap | both |