Window screen.colorDepth
Example
Get the bit depth of the color palette:
let depth = screen.colorDepth;
Try it Yourself »
More "Try it Yourself" examples below.
Description
The colorDepth
property returns the screen's color depth.
The colorDepth
property returns the depth in bits per pixel.
The colorDepth
property is read-only.
Syntax
screen.colorDepth
Return Value
Type | Description |
A number | The depth of the screen's color palette in bits per pixel: 1, 4, 8, 15, 16, 24, 32, or 48. |
More Examples
Display an alternate background color for 8 bit screens (to avoid that 8 bit screens, which do not support the modern color, uses an ugly substitute color instead):
if (screen.colorDepth <= 8)
//simple blue background color for 8 bit screens
document.body.style.background = "#0000FF"
else
//fancy blue background color for modern screens
document.body.style.background = "#87CEFA"
Try it Yourself »
All screen properties:
let text = "Total width/height: " + screen.width + "*" + screen.height + "<br>" +
"Available width/height: " + screen.availWidth + "*" + screen.availHeight + "<br>" +
"Color depth: " + screen.colorDepth + "<br>" +
"Color resolution: " + screen.pixelDepth;
Try it Yourself »
Browser Support
screen.colorDepth
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |