How to get the pixel depth and color depth of a screen in JavaScript?


Javascript window object has provided many methods to get various kinds of information regarding the browser.  It has provided screen.colorDepth and screen.pixelDepth to get the color depth and pixel depth of browser screen respectively. Let's discuss them individually.

Color depth

The window object has provided screen.colorDepth method to return the color depth. Color depth is nothing but the number of bits used to display one color. All modern computers use 24 bit or 32 bit hardware for color resolution.

Example

Live Demo

<html>
<body>
<p id="depth"></p>
<script>
   document.getElementById("depth").innerHTML =
   "Screen color depth is " + screen.colorDepth;
</script>
</body>
</html>

Output

Screen color depth is 24


Pixel depth

Javascript window object has provided screen.pixelDepth to return the pixel depth of the browser screen.

Example

Live Demo

<html>
<body>
<p id="depth"></p>
<script>
   document.getElementById("depth").innerHTML =
   "Screen pixel depth is " + screen.pixelDepth;
</script>
</body>
</html>

Output

Screen pixel depth is 24

Updated on: 30-Jul-2019

443 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements