Code2care : TechZone Apps & Tutorials

Get Device Screen Width and Height using javaScript

To get the height and width of the Display Screen we must use screen.height and screen.width javascript properties respectively. The screen property is available in the Window Object, we don't need to prefix it with screen though.

<!DOCTYPE html>
<title>Get Device width and Height using Javscript</title>

<script type="text/javascript">

function getScreenDimentions() {
document.getElementById("dimenstions").innerHTML = 
"Display Width : " + screen.width +"<br/> Display Height : " + screen.height;

<h2>You Monitor display pixels</h2> 
<body onload="getScreenDimentions()">

<div id="dimenstions"></div>


To demonstrate we create an javaScript function in the head section getScreenDimentions() and set the screen width and height to the html div element with class name dimensions on body load.

screen dimentions output

Note that the screen property returns the dimensions in unit pixel.


Posts related to javascript.

1. Top 15 Programming Languages to learn 2014-2015

2. How to detect Browser and Operating System Name and Version using javaScript

3. How to make jsfiddle bootstrap ready

4. Detect if Cookies are enabled using javascript

5. How to get UTC (GMT) using javascript

6. Add Animated Scrolling to Html Page Title Script

7. Loading previous page using html button using javascript

8. Get Device Screen Width and Height using javaScript

9. Digital clock example using javaScript with Source code


Popular tags
x 175
x 29
x 20
x 14
x 14
x 14
x 13
x 11

1000+ C Programs     PHP Tutorial     JSON Tutorial     Swift Tutorial     India Pinocdes     About Us     Privacy Policy

Code2care © 2012-17