The window.screen object provides details about the user’s screen.
The window.screen object can be accessed without the window prefix.
Properties include:
The screen.width property returns the width of the user’s screen in pixels.
Show the screen width in pixels:
document.getElementById(“demo”).innerHTML = “Screen Width: “ + screen.width; |
The output will be:
Screen Width: 1366 |
The screen.height property returns the height of the user’s screen in pixels.
Show the height of the screen in pixels:
document.getElementById(“demo”).innerHTML = “Screen Height: “ + screen.height; |
The output will be:
Height of the screen: 768 |
The screen.availWidth property returns the width of the user’s screen in pixels, excluding interface elements such as the Windows Taskbar.
Show the available width of the screen in pixels:
document.getElementById(“demo”).innerHTML = “Available Screen Width: “ + screen.availWidth; |
Result will be:
Available Screen Width: 1366 |
The screen.availHeight property returns the height of the user’s screen in pixels, excluding interface elements like the Windows Taskbar.
Show the available height of the screen in pixels:
document.getElementById(“demo”).innerHTML = “Available Screen Height: “ + screen.availHeight; |
Result will be:
Available Screen Height: 728 |
The screen.colorDepth property returns the number of bits used to represent a single color on the screen.
Modern devices typically use 24-bit or 32-bit color resolution:
Older systems often used 16-bit resolution, offering 65,536 “High Colors,” while older computers and phones might have used 8-bit color, providing just 256 “VGA Colors.”
Show the screen’s color depth in bits:
document.getElementById(“demo”).innerHTML = “Screen Color Depth: “ + screen.colorDepth; |
Result will be:
Screen Color Depth: 24 |
The #rrggbb (RGB) values used in HTML represent “True Colors,” offering 16,777,216 distinct color options. |
The screen.pixelDepth property returns the pixel depth of the screen.
Display the pixel depth of the screen in bits:
document.getElementById(“demo”).innerHTML = “Screen Pixel Depth: “ + screen.pixelDepth; |
Result will be:
Screen Pixel Depth: 24 |
For modern computers, the color depth and pixel depth are the same. |