Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS media types

CSS media types


Media types allow you to specify how a document will be presented on different media. The document can be displayed in different ways on a screen, on paper, or in an auditory browser, and so on. 


Media type

Some CSS properties are designed for certain media only. For example, voice-family property is designed specifically for auditory user agents. Some other properties can be used for different media types. For example, font-size property can be used for screen and print media, but with different values. Documents on screen and on paper differ, and usually require a larger font,sans-serif font is more suitable for reading on screen, while serif font is easier to read on paper.


@media rule

The @media rule allows you to set different styles for different media in the same style sheet.

The example below tells the browser to display a 14-pixel Verdana font on screen. But if the page is printed, it will use a 10-pixel Times font. Note that font-weight is set to bold both on screen and on paper:

Example

@media

screen

{

p

.test

{

font-family:

verdana

,

sans-serif

;

font-size:

14

px

;

}

}

@media

print

{

p

.test

{

font-family:

times

,

serif

;

font-size:

10

px

;

}

}

@media

screen

,

print

{

p

.test

{

font-weight:

bold

;

}

}

Try it »

You can try it yourself ! If you are using Mozilla / Firefox Or print this page with IE5+, and you will see that the media type displays using a different font, sized a bit smaller than the rest of the text.


Other media types

**Note:** Media type names are case-insensitive.

Media type Description
all Used for all media devices.
aural Used for speech and audio synthesizers.
braille Used for braille tactile feedback devices for the blind.
embossed Used for paged braille printers.
handheld Used for small handheld devices.
print Used for printers.
projection Used for presentation media, such as slideshows.
screen Used for computer screens.
tty Used for media using a fixed-density letter grid, such as teletypewriters and terminals.
tv Used for television-type devices.