CSS Media Features - Monochrome



CSS monochrome media feature is used to determine the number of bits are used to represent each pixel in the monochrome frame buffer of the output device.

The monochrome media feature is a range feature, you can use the min-monochrome and max-monochrome variants to query minimum and maximum values.

Monochrome devices display the content only in one color, usually black and white, such as monochrome monitors, printers, E-Book readers,..etc.

Possible Values

  • <integer> − This integer value indicates the number of bits allocated to each pixel in the monochrome frame buffer. For non-monochrome devices, the value is zero.

Syntax

monochrome: <integer>

CSS monochrome - Zero Value

The following example demonstrates how the monochrome media feature can be used to target non-monochrome (color) devices with a value of 0. For such devices, the background color of the element is changed to violet −

<html>
<head>
<style>
   .monochrome-box {
      width: 150px;
      height: 100px;
      background-color: pink;
   }
   @media (monochrome: 0) {
      .monochrome-box {
         background-color: violet;
      }
   }
</style>
</head>
<body>
   <div class="monochrome-box">CSS Media Feature Monochrome</div>
</body>
</html>

CSS monochrome - <integer> Value

When the monochrome media feature detects a monochrome frame buffer with 3 bits per pixel, the element will have a violet background color. On other devices, the element will have a pink background color.

Here is an example −

<html>
<head>
<style>
   .monochrome-box {
      width: 150px;
      height: 100px;
      background-color: pink;
   }
   @media (monochrome: 3) {
      .monochrome-box {
         background-color: violet;
      }
   }
</style>
</head>
<body>
   <div class="monochrome-box">CSS Media Feature Monochrome</div>
</body>
</html>
Advertisements