JavaScript Window Screen

Back to JS page

Table of Contents

Window Screen Width

The screen.width property returns the width of the visitor's screen in pixels:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Screen</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>Window Screen Width</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "Screen width: " + screen.width + "px";
</script>

</body>
</html>

Example 1

Result View Example

Window Screen Height

The screen.height property returns the height of the visitor's screen in pixels:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Screen</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>Window Screen Height</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "Screen height: " + screen.height + "px";
</script>

</body>
</html>

Example 2

Result View Example

Window Screen Available Width

The screen.availWidth property returns the width of the visitor's screen in pixels, minus interface features like the taskbar:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Screen</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>Window Screen Available Width</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "Available screen width: " + screen.availWidth + "px";
</script>

</body>
</html>

Example 3

Result View Example

Window Screen Available Height

The screen.availHeight property returns the height of the visitor's screen in pixels, minus interface features like the taskbar:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Screen</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>Window Screen Available Height</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "Available screen height: " + screen.availHeight + "px";
</script>

</body>
</html>

Example 4

Result View Example

Window Screen Color and Pixel Depth

The screen.colorDepth property returns the number of bits used to display one color. The screen.pixelDepth property returns the pixel depth of the screen:

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Window Screen</h2>
<p>From w3schools.com, Experiment by Teeratus_R</p>

<h4>Window Screen Color and Pixel Depth</h4>
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML =
  "Screen color depth: " + screen.colorDepth + " bits<br>" +
  "Screen pixel depth: " + screen.pixelDepth + " bits<br><br>" +
  "All screen properties:<br>" +
  "Total size: " + screen.width + " x " + screen.height + "<br>" +
  "Available: " + screen.availWidth + " x " + screen.availHeight + "<br>" +
  "Color depth: " + screen.colorDepth + " bits<br>" +
  "Pixel depth: " + screen.pixelDepth + " bits";
</script>

</body>
</html>

Example 5

Result View Example

Document

Document in project

You can Download PDF file.

Reference