title: Check whether HTML element has scrollbars
body: <p>What's the fastest way of checking whether an element has scroll bars?</p>
  
  <p>One thing of course is checking whether element is larger than its viewport, which can easily be done by checking these two values:</p>
  
  <pre><code>el.scrollHeight &gt; el.offsetHeight || el.scrollWidth &gt; el.offsetWidth
  </code></pre>
  
  <p>but that doesn't mean that it has scrollbars as well (so it can actually be scrolled by humans).</p>
  
  <h2>Question</h2>
  
  <p>How do I check for scrollbars in a <strong>1</strong> cross browser and <strong>2</strong> javascript only (as in <em>no jQuery</em>) way?</p>
  
  <p>Javascript only, because I need as small overhead as possible, because I'd like to write a very fast jQuery selector filter</p>
  
  <pre><code>// check for specific scrollbars
  $(":scrollable(x/y/both)")
  
  // check for ANY scrollbar
  $(":scrollable")
  </code></pre>
  
  <p>I suppose I'd have to check for <code>overflow</code> style settings but how do I do that in a cross browser way?</p>
  
  <h2>Additional edit</h2>
  
  <p>Not only <code>overflow</code> style settings. Checking whether an element has a scrollbar isn't as trivial as it seems. The first formula I've written above works fine when element doesn't have a border, but when it does (especially when border is of considerable width), <code>offset</code> dimension can be larger than <code>scroll</code> dimension but the element can still be scrollable. We actually have to subtract borders from <code>offset</code> dimension to get the actual scrollable viewport of the element and compare that to <code>scroll</code> dimension.</p>
  
  <h2>For future reference</h2>
  
  <p><code>:scrollable</code> jQuery selector filter is included in my <code>.scrollintoview()</code> jQuery plugin. Complete code can be found in my <a href="http://erraticdev.blogspot.com/2011/02/jquery-scroll-into-view-plugin-with.html" rel="noreferrer">blog post</a> if anybody needs it. Even though it didn't provide the actual solution Soumya's code considerably helped me solve the problem. It pointed me in the right direction.</p>