JS Screen object

The JavaScript screen object provides information about the user's screen. It is a property of the window object and allows developers to access various details about the screen's dimensions and color capabilities. This can be useful for optimizing the display of web content based on the user's screen size and resolution.

Property of JavaScript Screen Object

Property Description
screen.width Returns the total width of the screen in pixels.
screen.height Returns the total height of the screen in pixels.
screen.availWidth Returns the available width of the screen for web content, excluding system interface features.
screen.availHeight Returns the available height of the screen for web content, excluding system interface features.
screen.colorDepth Returns the number of bits used to display colors on the screen.
screen.pixelDepth Returns the number of bits used to represent the color of each pixel.

Example:

<script>
document.writeln("<br/>screen.width: " + screen.width);
document.writeln("<br/>screen.height: " + screen.height);
document.writeln("<br/>screen.availWidth: " + screen.availWidth);
document.writeln("<br/>screen.availHeight: " + screen.availHeight);
document.writeln("<br/>screen.colorDepth: " + screen.colorDepth);
document.writeln("<br/>screen.pixelDepth: " + screen.pixelDepth);
</script>

Output: