CancelImage Upload

How to return the screen height and width dimensions (properties) via JavaScript

Note that this tutorial discusses how a user's screen dimensions height and width can be established via JavaScript. This is not to be confused with the browser's current height and width, but the actual computer screen through which the website is viewed. Depending on this setting you may choose to make layout changes to your HTML document, to suit screens with greater or smaller width.

The height and width properties can be accessed via the following JavaScript code, which should work on most popular browsers:

var width = screen.width;

var height = screen.height;

Here is a more extensive example. The dimensions are loaded into a span via the JavaScript function getElementById():

<title>Screen Width and Height</title>

<script language="JavaScript">

function dimensions()

      var dimensions = document.getElementById("dimensions");

      var width = "Width: " + screen.width + "px";

      var height = "Height: " + screen.height + "px";

      dimensions.innerHTML = width + "<br>" + height;



<body onload="javascript:dimensions();">

<span id="dimensions"></span>


Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •