| 0 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 | 1100 | 1200 | 1300 | 1400 | 1500 | 1600 | 1700 | 1800 | 1900 |
| 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90 |
JavaScript has many width (and height) values, many of which are listed below.
The grid above is fixed to the left of the viewport and won’t resize with different browser window widths so you can see the window
window.innerWidth is highlighted as it’s the value used by CSS media queries (“@media”) for the current device screen or browser window. (Some smartphones have suprising values!)
| window | : | ? | px |
| window | : | ? | px |
| window | : | ? | px |
| document | : | ? | px |
| document | : | ? | px |
| window | : | ? | px |
| document | : | ? | px |
| document | : | ? | px |
| document | : | ? | px |
| window | : | ? | px |
| window | : | ? | px |
| window | : | ? | px |
| document | : | ? | px |
| document | : | ? | px |
| window | : | ? | px |
| document | : | ? | px |
| document | : | ? | px |
| document | : | ? | px |
Values update as you resize the browser (or flip between portrait and landscape) - all except document
Width of scrollbar = ?px = window.innerWidth - document
See demo page above.
window.screen.width : width of the screen (monitor / smartphone / etc)
window.screen.availWidth : width of the active screen without the OS toolbars e.g. Windows taskbar
window.outerWidth : width of the entire browser window, including the address bar, tabs bar and other browser panels
document.documentElement.scrollWidth : html width + margin + border (not scrollbar)
document.documentElement.offsetWidth : html width + border (not margin or scrollbar)
window.innerWidth : width of the “viewport” window that displays the web page + scrollbar width
document.documentElement.clientWidth : the viewport window (html width); measured inside the scrollbar if there is one (not margin, border or scrollbar)
document.body.offsetWidth : body width + border (not margin or scrollbar)
document.body.scrollWidth : body width (not margin, border or scrollbar)
document.documentElement : property gives you the <html> element
document.body : property gives you the <body> element
Note: padding is included in the width
window.innerWidth vs document.documentElement.clientWidth
How to get browser width using JavaScript
Understanding offsetWidth, clientWidth, scrollWidth - with diagrams
| site map / contents | website privacy |
| glossary | contact me |