tadam logo

HTML <style> media Attribute

Example

Two different styles for two different media types (computer screen and print):
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
h1 {color:#FF0000;}
p {color:#0000FF;}
body {background-color:#FFEFD6;}
</style>

<style type="text/css" media="print">
h1 {color:#000000;}
p {color:#000000;}
body {background-color:#FFFFFF;}
</style>
</head>

<body>
<h1>Header 1</h1>
<p>A paragraph.</p>
</body>
</html>
The output of the code above will be:

Definition and Usage

The media attribute is used to specify different styles for different media types.

Tip: To define more than one media type per style element, use a comma-separated list (example: <style type="text/css" media="screen,projection">).

Browser Support

The media attribute with the value of "screen", "print", and "all" is supported in all major browsers.

Tip: Opera also supports the "handheld" value.

Syntax

<style media="value">

Attribute Values

ValueDescription
screenComputer screens (this is default)
ttyTeletypes and similar media using a fixed-pitch character grid
tvTelevision type devices (low resolution, limited scroll ability)
projectionProjectors
handheldHandheld devices (small screen, limited bandwidth)
printPrint preview mode/printed pages
brailleBraille feedback devices
auralSpeech synthesizers
allSuitable for all devices
Was this information helpful?
   

Comments