To get the width of the browser window using JavaScript, you can use the window.innerWidth
property. This property returns the width of the browser window including the width of the scrollbar (if present).
Alternatively, if you want to get the width of the viewport only (excluding the scrollbar), you can use document.documentElement.clientWidth
.
Here's an example:
index.tsx172 chars6 lines
Note that these properties return the width of the window/viewport in pixels.
gistlibby LogSnag