JavaScript Tutorial
JS - Introduction JS - Basic JS - Placement JS - Output JS - Statements JS - Syntax JS - Variables JS - Comments JS - Data Types JS - Operators JS - Operator Precedence JS - Condition JS - Switch JS - Functions JS - Objects JS - Loops For JS - Loops While JS - Break JS - Strings JS - String Methods JS - Numbers JS - Number Methods JS - Arrays JS - Array Methods JS - Array Iteration JS - Events JS - Event Listener JS - Event Propagation JS - Date JS - Math JS - Random JS - Boolean JS - Type Conversion JS - RegExp JS - Exception JS - Scope JS - Debugging JS - Hoisting JS - Strict Mode JS - this Keyword JS - Mistakes JS - Best Practices JS - Performance JS - Form Validation JS - ES6 Features
JS Objects
Object Definitions Object Properties Object Methods Object Constructors Object Prototypes
JS Functions
Function Definitions Function Parameters Function Call Function Apply Function Closures
JS HTML DOM
DOM Introduction DOM Methods DOM Selectors DOM HTML DOM CSS DOM Attributes DOM Navigation
JS Browser BOM
JS - Window JS - Screen JS - Location JS - History JS - Navigator JS - Popup Alert JS - Timing JS - Cookies
JS AJAX
AJAX - Introduction AJAX - XMLHttp AJAX - Request AJAX - Response AJAX - PHP
JS JSON
JSON - Introduction JSON - Syntax JSON - Data Types JSON - Parse JSON - Stringify JSON - Objects JSON - Arrays JSON - PHP JSON - JSONP
JS References
JavaScript Reference JavaScript Methods HTML DOM Reference

JavaScript Window Screen

The window.screen object contains information about the user's screen.


The Screen Object

The window.screen object can be used to display screen resolution (width and height of the screen), color depth, pixel depth, etc.

The window.screen object can be written without the window prefix.

The screen object has the following properties:

The following section will show you how to get information of the user's display using the screen object property of the window object.


Window Screen Width

The screen.width property returns the total width of the visitor's screen in pixels.

Run code

Window Screen Height

The screen.height property returns the total height of the visitor's screen in pixels.

Run code

Window Screen Available Width

The screen.availWidth property returns the width, in pixels, of the area on the screen that is available for application windows.

The area for application windows is the entire screen excluding the taskbar.

Run code

Window Screen Available Height

The screen.availHeight property returns the height, in pixels, of the area on the screen that is available for application windows.

The area for application windows is the entire screen excluding the taskbar.

Run code

Window Screen Color Depth

The screen.colorDepth property returns the color depth of the user's screen.

Color depth is the number of bits used to represent the color of a single pixel.

Color depth indicates how many colors a device screen is capable to produce.

For example, screen with color depth of 8 can produce 256 colors (28).

Run code

Currently, most devices has screen with color depth of 24 or 32. In simple words more bits produce more color variations, like 24 bits can produce 224 = 16,777,216 color variations (true colors), whereas 32 bits can produce 232 = 4,294,967,296 color variations (deep colors).


Window Screen Pixel Depth

The screen.pixelDepth property returns the bit depth of the screen.

Pixel depth is the number of bits used per pixel by the system display hardware.

For modern devices, color depth and pixel depth are equal.

Run code

More Examples

This example shows all screen properties:

Run code