Screen colorDepthProperty
Screen Object
Definition and Usage
The colorDepth property returns the bit depth of the palette on the target device or buffer.
Syntax
screen.colorDepth
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the colorDepth property.
Examples
Example 1
Return the bit depth of the palette:
<script>
document.write("Color depth: " + screen.colorDepth);
</script>
document.write("Color depth: " + screen.colorDepth);
</script>
The output result of the above example:
Try it yourself »
Example 2
Display alternating background colors on an 8-bit screen:
if (screen.colorDepth<=8)
// Simple blue background for 8-bit screens
document.body.style.background="#0000FF"
else
// Fancy blue background for modern screens
document.body.style.background="#87CEFA"
// Simple blue background for 8-bit screens
document.body.style.background="#0000FF"
else
// Fancy blue background for modern screens
document.body.style.background="#87CEFA"
Try it yourself »
More Examples
This example contains all screen properties.
Screen Object Other Extensions