Javascript Reference - Screen pixelDepth Property








The pixelDepth property returns the color in bits per pixel of the visitor's screen.

Browser Support

pixelDepth Yes 10.0 Yes Yes Yes

Syntax

screen.pixelDepth

Return Value

Type Description
Number The color resolution, in bits per pixel. Possible values:
  • 1 bit per pixel
  • 4 bits per pixel
  • 8 bits per pixel
  • 15 bits per pixel
  • 16 bits per pixel
  • 24 bits per pixel
  • 32 bits per pixel
  • 48 bits per pixel




Example

The following code shows how to get the color resolution of your screen.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--  ww w  .j a v a 2s .co  m-->
<p id="demo"></p>

<script>
function myFunction() {
    var x = "Color resolution: " + screen.pixelDepth + " bits per pixel";
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





More Examples

All screen properties in one example


<!DOCTYPE html>
<html>
<body>
<div id="demo"></div>
<script>
var txt;
txt = "<p>Total width/height: " + screen.width + "*" + screen.height + "</p>";
txt+= "<p>Available width/height: " + screen.availWidth + "*" + screen.availHeight + "</p>";
txt+= "<p>Color depth: " + screen.colorDepth + "</p>";
txt+= "<p>Color resolution: " + screen.pixelDepth + "</p>";
<!--from  w w w . j av a  2s .co  m-->
document.getElementById("demo").innerHTML = txt;
</script>

</body>
</html>

The code above is rendered as follows: