CSS Media Features - Update



CSS update media feature helps check how repeatedly the device can change the appearance of content after it has been displayed.

Possible Values

  • none − The display is not updated. This value is typically used for printed documents.

  • slow − The display has a slow refresh rate. This is common on e-book readers or very slow devices.

  • fast − The display has a fast refresh rate. This allows the use of regularly updating elements like CSS Animations, typical for computer screens.

Syntax

update: none|slow|fast;

CSS update - none Value

The following example demonstrates use of update: none media feature to apply an animation to the body element when the update frequency of the output device is none.This animation won't be visible on regular screens but will give an effect when you view it on something like a printed page −

<html>
<head>
<style>
   body {
      color: black;
   }
   @media (update: none) {
      body {
         animation: animation 1s infinite;
         color: red;
      }
   }
   @keyframes animation {
      0% {
         transform: translateX(0);
      }
      100% {
         transform: translateX(100px);
      }
   }
   button {
      background-color: violet;
      padding: 5px;
   }
</style>
</head>
<body>
   <p>Click on below button to see the effect when you print the page.</p>
   <button onclick="printPage()">Print Page</button>
   <p>CSS Media feature update: none</p>
   <script>
      function printPage() {
         window.print();
      }
   </script>
</body>
</html>

CSS update - slow Value

If you use the update: slow media feature, you should see the text content move to the right and turn red on devices that are slow to update their displays. This includes devices such as low-powered devices and e-ink displays.

Here is an example −

<html>
<head>
<style>
   body {
      color: black;
   }
   @media (update: slow) {
      body {
         animation: animation 1s infinite;
         color: red;
      }
   }
   @keyframes animation {
      0% {
         transform: translateX(0);
      }
      100% {
         transform: translateX(100px);
      }
   }
</style>
</head>
<body>
   <h3>You can see the effect of the update: slow media query on low-powered devices and e-ink displays.</h3>
   <p>CSS Media feature update: slow</p>
</body>
</html>

CSS update - fast Value

The following example demonstrates that the update: fast media feature will cause the body element to move 100 pixels to the right and then back to the left over the course of 1 second −

<html>
<head>
<style>
   body {
      color: black;
   }
   @media (update: fast) {
      body {
         animation: animation 1s infinite;
         color: red;
      }
   }
   @keyframes animation {
      0% {
         transform: translateX(0);
      }
      100% {
         transform: translateX(100px);
      }
   }
</style>
</head>
<body>
   <p>CSS Media feature update: fast</p>
</body>
</html>
Advertisements