JavaScript Screen

Beginner
8 min read
Updated: Nov 2026
3 examples
Display info

Definition and Usage

The screen object (window.screen) describes the userโ€™s display: width, height, available space, and color depth.

Use screen.width / screen.height for the full screen size, and availWidth / availHeight for the space minus system UI. Orientation APIs and the change event help when the device rotates.

This page teaches what Screen is. Events, methods, and properties live under this section.

Screen size โ‰  viewport size.

For layout inside the browser window, prefer window.innerWidth. screen.width is the whole monitor.

JavaScript Syntax

Reading Screen properties:

JavaScript
console.log(screen.width, screen.height);
console.log(screen.availWidth, screen.availHeight);
console.log(screen.colorDepth);

Core Ideas

Ideas every Screen tutorial builds on:

IdeaExampleRemember
Full sizescreen.widthEntire display width
Availablescreen.availWidthMinus taskbars / docks
Colorscreen.colorDepthBits per pixel
Orientationscreen.orientationPortrait / landscape API
changescreen.addEventListener("change")Display configuration changes
vs viewportwindow.innerWidthUse for CSS-like layout

JavaScript Examples

Three short programs that show how Screen works.

Example 1 — Log screen dimensions

width and height are the full screen in CSS pixels.

JavaScript
console.log(screen.width > 0);
console.log(screen.height > 0);

How It Works

  1. screen.width is a positive number on real devices.
  2. screen.height is the matching height.
  3. Values are for the display, not the browser window.

Example 2 — Available size

avail* excludes some system UI chrome.

JavaScript
console.log(screen.availWidth <= screen.width);
console.log(screen.availHeight <= screen.height);

How It Works

  1. availWidth is never larger than width.
  2. availHeight is never larger than height.
  3. Useful when placing pop-up windows.

Example 3 — Color depth

colorDepth is typically 24 or 30 on modern screens.

JavaScript
console.log(typeof screen.colorDepth);
console.log(screen.colorDepth >= 24);

How It Works

  1. colorDepth is a number of bits.
  2. Most displays report at least 24.
  3. Rarely needed for everyday UI work.

Next: Screen Guides

Continue with the change event and screen properties.

Look upWhy
changeListen for display changes
width / heightFull screen size
availWidthSpace minus system UI
orientationPortrait / landscape details

Full lists: Screen change event.

Frequently Asked Questions

window.screen is an object that describes the display: its pixel size, available area, color depth, and orientation-related features.
Usually no. Use CSS media queries or window.innerWidth for the browser viewport. screen.width is the whole monitor.
It is the horizontal space available roughly outside OS taskbars and docks. It is less than or equal to screen.width.
No. Screen is a browser API. It is undefined in typical Node.js scripts.
Open the change event guide, then Window for viewport sizes.

Open the Screen change event

Then browse width, availWidth, and orientation properties.

change event →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P ๐Ÿ”—

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful