HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

JavaScript Window Screen

The window.screen object contains information about the user's screen dimensions and color depth. Unlike the window's viewport (which is the area inside the browser), the screen object refers to the entire physical monitor or display device the visitor is using.


Live Screen Properties

Here are the actual dimensions of your current display detected by JavaScript:

Total Width --
Total Height --
Available Width --
Available Height --

Screen Width and Height

The width and height properties return the total width and height of the visitor's screen in pixels.

// Get total screen dimensions
let width = screen.width;
let height = screen.height;

console.log("Screen Width: " + width);
console.log("Screen Height: " + height);
Note: These values represent the physical resolution of the screen, not the size of the browser window.

Available Width and Height

The availWidth and availHeight properties return the width and height of the visitor's screen, minus interface features like the Windows Taskbar or MacOS Menu Bar.

// Get available screen space
let availWidth = screen.availWidth;
let availHeight = screen.availHeight;

console.log("Available Width: " + availWidth);
console.log("Available Height: " + availHeight);
Tip: Use availHeight if you want to know the maximum space your application can occupy without being covered by system bars.

Color Depth and Pixel Depth

The screen object also provides information about the color resolution of the display.

  • screen.colorDepth: Returns the number of bits used to display one color.
  • screen.pixelDepth: Returns the pixel depth of the screen.
document.write("Color Depth: " + screen.colorDepth);
document.write("Pixel Depth: " + screen.pixelDepth);
Fact: Modern computers typically use 24-bit or 32-bit color depth (16,777,216 Colors). Older systems might show 16-bit or 8-bit.

Screen Property Summary

Property Description
screen.width Total width of the visitor's screen
screen.height Total height of the visitor's screen
screen.availWidth Available width (minus taskbars)
screen.availHeight Available height (minus taskbars)
screen.colorDepth Number of bits to display one color
screen.pixelDepth The pixel depth of the screen

Key Points to Remember

  • The Screen object belongs to the BOM (Browser Object Model) and is accessed via window.screen.
  • It tells you about the device monitor, not the browser window.
  • The available dimensions are often smaller than the total dimensions due to system taskbars.
  • You cannot change screen properties (like resolution); they are read-only.
  • Screen information is useful for analytics and optimizing large-scale layouts.