by Sai gowtham

How to get the screen size (width, height) in JavaScript

Learn, how to get the device width and height in JavaScript

Using availHeight and availWidth

We can use the screen.availWidth and screen.availHeight properties to get the screen size of a device in pixels.

Example:

window.screen.availWidth; // 1440

window.screen.availWidth; // 877

Note: The availWidth, availHeight properties excludes the device taskbar.

If you want to get the total width and height of the user’s screen including taskbar, you can use the screen.width and screen.height properties.

window.screen.width; // 1440

window.screen.height; // 900

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course