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.

<!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.
- 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
- [Program] How to read three different values using Scanner in Java - Java
- Java SE 8 Update 301 available with various bug fixes and security improvements - Java
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error - Android
- Path of homebrew (brew) installation in macOS Big Sur - MacOS
- Parsing CSV file using Java code example (Comma Separated File) - Java
- Java 8 Format Date and Time Examples - Java
- The Zsh Shell - Mac Tutorial - MacOS
- How to Reset Eclipse Theme to Classic - Eclipse