Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS Screen

The window.screen object provides details about the user’s screen.

Window Screen

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

Properties include:

  • screen.width
  • screen.height
  • screen.availWidth
  • screen.availHeight
  • screen.colorDepth
  • screen.pixelDepth

Window Screen Width

The screen.width property returns the width of the user’s screen in pixels.

Example

Show the screen width in pixels:

document.getElementById(“demo”).innerHTML =
“Screen Width: “ + screen.width;

The output will be:

Screen Width: 1366

Window Screen Height

The screen.height property returns the height of the user’s screen in pixels.

Example

Show the height of the screen in pixels:

document.getElementById(“demo”).innerHTML =
“Screen Height: “ + screen.height;

The output will be:

Height of the screen: 768

Window Screen Available Width

The screen.availWidth property returns the width of the user’s screen in pixels, excluding interface elements such as the Windows Taskbar.

Example

Show the available width of the screen in pixels:

document.getElementById(“demo”).innerHTML =
“Available Screen Width: “ + screen.availWidth;

Result will be:

Available Screen Width: 1366

Window Screen Available Height

The screen.availHeight property returns the height of the user’s screen in pixels, excluding interface elements like the Windows Taskbar.

Example

Show the available height of the screen in pixels:

document.getElementById(“demo”).innerHTML =
“Available Screen Height: “ + screen.availHeight;

Result will be:

Available Screen Height: 728

Window Screen Color Depth

The screen.colorDepth property returns the number of bits used to represent a single color on the screen.

Modern devices typically use 24-bit or 32-bit color resolution:

  • 24 bits: 16,777,216 “True Colors”
  • 32 bits: 4,294,967,296 “Deep Colors”

Older systems often used 16-bit resolution, offering 65,536 “High Colors,” while older computers and phones might have used 8-bit color, providing just 256 “VGA Colors.”

Example

Show the screen’s color depth in bits:

document.getElementById(“demo”).innerHTML =
“Screen Color Depth: “ + screen.colorDepth;

Result will be:

Screen Color Depth: 24

The #rrggbb (RGB) values used in HTML represent “True Colors,” offering 16,777,216 distinct color options.

Window Screen Pixel Depth

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

Example

Display the pixel depth of the screen in bits:

document.getElementById(“demo”).innerHTML =
“Screen Pixel Depth: “ + screen.pixelDepth;

Result will be:

Screen Pixel Depth: 24
For modern computers, the color depth and pixel depth are the same.