How to get the size of the screen, browser window, and the web page itself in JavaScript?
Hello everyone! I'm a beginner in JavaScript and I'm making a responsive website. I need some elements to adapt to the user's device size. But I'm confused about the terms: what is screen, window, and document? And how do I get their exact sizes?
For example, I wrote this code:
```javascript
console.log('screen width:', screen.width);
console.log('window inner width:', window.innerWidth);
console.log('document width:', document.width);
```
But `document.width` returns `undefined`, and `screen.width` seems to show something I don't expect. I have a laptop with a Full HD screen (1920×1080), but `screen.width` gives 1536, and `window.innerWidth` gives 1519 (when the window is maximized). Why is that? And how do I correctly get the width and height of the web page itself (including scroll)?
I want to understand th
No answers yet.
Log in to leave an answer
Blogs
How to Become a Go Developer: Tips and Resume for Beginners
Dates in TypeScript: How to Properly Declare a Type and Not Lose Your Mind
How to Return a Response from an Asynchronous Call: A Complete Guide for JS
Python Developer Jobs: Top Career Paths & Salaries in 2025