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 the screen though.

screen dimentions output
getScreenDimentions.html
<!DOCTYPE html>
<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;
}
</script>
<h2>You Monitor display pixels</h2>
<body onload="getScreenDimentions()">
<div id="dimenstions"></div>
</body>
</html>
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.
Note that the screen property returns the dimensions in the unit pixel.
More Posts related to JavaScript,
- How to get UTC (GMT) time using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- How to detect Browser and Operating System Name and Version using JavaScript
- JavaScript : Get current page address
- [javaScript] Convert text case to lowercase
- How to check if a String contains substring or a word using javaScript
- Writing your first Hello, World! 🌍 JavaScript code Tutorial
- JavaScript: Check if variable is a number
- How to send email from JavaScript HTML using mailto
- Meaning of javascript:void(0) explained with example
- How to get query string in JavaScript HTML location.search
- Javascript convert text case from uppercase to lowercase
- Loading previous page using html button using JavaScript
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- How to get current URL Location using Javascript HTML
- Detect if Cookies are enabled using JavaScript
- Write javaScript code in Swedish using FikaScript
- Add Animated Scrolling to Html Page Title Script
- JavaScript: Convert an Image into Base64 String
- Remove items from JavaScript array
- Send Extra Data with Ajax Get or Post Request
- How to Print from JavaScript HTML using window.print
- Get Device Screen Width and Height using javaScript
- Examples: Convert String to int in JavaScript
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json
More Posts:
- [fix] Microsoft Error Code 0x80004005 - Unspecified error - Microsoft
- Check version of pip package installer for Python - Python
- [Solution] AWS Java SDK S3 AmazonS3Exception InvalidAccessKeyId - AWS
- Align html element at the center of page vertically and horizontally - Html
- How to connect to SFTP location using Terminal command - FTP
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020 - Android
- Error : Facebook SDK AndroidRuntime?FATAL EXCEPTION: main - Android
- Bash For Loop Example - Bash