JavaScript

JavaScript is a high-level, interpreted programming language that is widely used for web development. Initially designed as a client-side scripting language, it runs directly in web browsers, enabling dynamic and interactive user experiences. JavaScript can now be used for server-side development as well.

JavaScript window.screen – Screen Object

14 April 2025 | Category:

The window.screen object provides information about the user’s screen, such as screen width, height, color depth, and more.

This is useful when you want to:

  • Make UI responsive based on screen size
  • Detect screen resolution
  • Create fullscreen experiences

🔹 What is window.screen?

window.screen is a built-in JavaScript object that contains properties about the user’s physical display screen.

console.log(window.screen); // Displays all screen properties

You don’t need to include window. — it’s optional since it’s the global object.


🔸 Common window.screen Properties

PropertyDescription
screen.widthTotal screen width (in pixels)
screen.heightTotal screen height (in pixels)
screen.availWidthWidth excluding system UI (taskbars, etc.)
screen.availHeightHeight excluding system UI
screen.colorDepthNumber of bits used to display colors
screen.pixelDepthColor resolution (usually same as colorDepth)

🔍 Examples

âś… Get Full Screen Size

console.log("Screen Width:", screen.width);
console.log("Screen Height:", screen.height);

âś… Get Available Screen Size

console.log("Available Width:", screen.availWidth);
console.log("Available Height:", screen.availHeight);

âś… Get Color Info

console.log("Color Depth:", screen.colorDepth + " bits");
console.log("Pixel Depth:", screen.pixelDepth + " bits");

🎯 Use Case: Fullscreen Check Before App Load

if (screen.width < 768) {
  alert("You are using a small screen. Some features may be limited.");
}

âś… Summary

PropertyUse Case
screen.width & screen.heightDetect total screen size
screen.availWidth & availHeightDetect usable area (excluding OS UI)
colorDepth & pixelDepthDetect screen color quality

đź§Ş Try It Yourself (Mini Project)

Create a button that shows all screen information when clicked:

<button onclick="showScreenInfo()">Get Screen Info</button>

<script>
  function showScreenInfo() {
    alert(
      "Screen Width: " + screen.width + "\n" +
      "Screen Height: " + screen.height + "\n" +
      "Available Width: " + screen.availWidth + "\n" +
      "Available Height: " + screen.availHeight + "\n" +
      "Color Depth: " + screen.colorDepth
    );
  }
</script>