Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
Get width and height of viewport excluding scroll bars

Okay, I've read about 1000 different ideas here but no answer seems to be complete.

I have a page that scrolls both horizontally and vertically, therefore, I have both horizontal and vertical scrollbars. I want the width of the viewport EXCLUDING the scrollbar and the height of the viewport EXCLUDING the scrollbar. Please also consider padding, and margins and borders etc.

For width, I originally had window.innerWidth but that included the scroll bar so I came to this solution that also accounts for body margin, padding and border, document.body.offsetWidth + parseInt(window.getComputedStyle(document.body).getPropertyValue('margin-left')) + parseInt(window.getComputedStyle(document.body).getPropertyValue('margin-right'))

Most other solutions for height either recommend window.innerHeight (but this includes the horizontal scrollbar which is not good) or document.body.clientHeight (which returns the whole length of the page, not just the viewport.)

So, does anyone have a solution for something so seemingly trivial?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.body.clientWidth and .clientHeight maybe what you're looking for.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!