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,
- Meaning of javascript:void(0) explained with example
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- How to get UTC (GMT) time using JavaScript
- Add Animated Scrolling to Html Page Title Script
- Examples: Convert String to int in JavaScript
- Get Device Screen Width and Height using javaScript
- Remove items from JavaScript array
- Javascript convert text case from uppercase to lowercase
- [javaScript] Convert text case to lowercase
- How to detect Browser and Operating System Name and Version using JavaScript
- How to send email from JavaScript HTML using mailto
- How to check if a String contains substring or a word using javaScript
- Send Extra Data with Ajax Get or Post Request
- How to get query string in JavaScript HTML location.search
- How to get current URL Location using Javascript HTML
- JavaScript: Check if variable is a number
- JavaScript : Get current page address
- JavaScript: Count Words in a String
- Loading previous page using html button using JavaScript
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json
- How to Print from JavaScript HTML using window.print
- Submit html form on dropdown menu value selection or change using javascript
- Detect if Cookies are enabled using JavaScript
- Writing your first Hello, World! 🌍 JavaScript code Tutorial
- JavaScript date in yyyy-MM-dd format
More Posts:
- How to Gzip a file directory on Mac OS X using Terminal Command - Mac-OS-X
- [Solved] Mic not working on iPhone 7 after iOS 14 upgrade - Apple
- Setting up Cloud feature with Notepad++ - NotepadPlusPlus
- Find Mac version using terminal command - MacOS
- Unable to connect to the Internet : Google Chrome - Chrome
- Enable Spellcheck in eclipse workspace - Eclipse
- ls command sort by file size [Linix/UNIX/macOS/bash] - Linux
- How to enable line numbers in IntelliJ - HowTos