JavaScript screen object - JavaScript Tutorial

JavaScript screen object

BLUF: This tutorial on JavaScript screen object provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript screen object

Understanding JavaScript screen object is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

  • Screen Object
  • Properties of Screen Object
  • Methods of Screen Object
  • Example of Screen Object

The JavaScript screen object contains details about the browser's screen. It can be utilized to present attributes such as screen width, height, color depth, pixel depth, and more.

The navigator object is a property of the window object, which means it can be accessed through:

Example

window.screen
Example

screen

Property of JavaScript Screen Object

Numerous attributes of the screen object provide details about the browser.

No. Property Description
1 width returns the width of the screen
2 height returns the height of the screen
3 availWidth returns the available width
4 availHeight returns the available height
5 colorDepth returns the color depth
6 pixelDepth returns the pixel depth.

Example of JavaScript Screen Object

Let’s see the different usage of screen object.

Example

<script>
document.writeln("<br/>screen.width: "+screen.width);
document.writeln("<br/>screen.height: "+screen.height);
document.writeln("<br/>screen.availWidth: "+screen.availWidth);
document.writeln("<br/>screen.availHeight: "+screen.availHeight);
document.writeln("<br/>screen.colorDepth: "+screen.colorDepth);
document.writeln("<br/>screen.pixelDepth: "+screen.pixelDepth);
</script>
Example

screen.width: 1366 
screen.height: 768 
screen.availWidth: 1366 
screen.availHeight: 728 
screen.colorDepth: 24 
screen.pixelDepth: 24

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience