Need help with jquery-iframe-auto-height?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

459 Stars 223 Forks 155 Commits 7 Opened issues


jQuery plugin to set the height of an iframe to its contents height

Services available


Need anything else?

Contributors list

jQuery iframe auto height plugin


You may want to consider one of these alternative solutions for your iframe resizing needs?


This plugin will NOT work if the iframe contains a page from another domain, use one of the alternate libraries above if you need cross domain resize.


$ npm install --save-dev jquery-iframe-auto-height
  • There is no longer a NuGet package, please use bower for all javascript packaging needs.

You will find versions before 2.0.0 in the release directory, all newer versions are handled using bower and the packaged file is in the dist directory.



  • include jquery in your page
  • include the latest version using bower or the grab the current file from the
  • use the variable jQuery or its alias $ and pass a selector that matches one or more iframes

  • jQuery('iframe').iframeAutoHeight();
    • will resize all iframes on the page
  • $('').iframeAutoHeight();
    • will resize only iframes with the css class photo
  • code can be called from within

    or after iframes are declared in markup



  • callback: function
    • Default empty function
    • Optionally define a callback function (in this case inline) that will do something with the callbackObject.newFrameHeight value. This can for instance be used with easyXDM to alert another domain that the frame has changed height.
    • Example:
      $('iframe').iframeAutoHeight({callback: function(callbackObject) { alert(callbackObject.newFrameHeight);} });
    • you can also access the current iframe jquery wrapper object use the
    • for example:
      callback: function(callbackObject) { alert(callbackObject.newFrameHeight + " and the iframe href is:" + $(this).attr('src')); }
  • debug: boolean
    • Default is false
    • Will log some internal information to the console, if available
    • Example:
      $('iframe').iframeAutoHeight({debug: true})
  • heightOffset: integer
    • Default is 0
    • Unit is pixels
    • Optionally add some buffer to the bottom
    • Example:
      $('iframe').iframeAutoHeight({heightOffset: 20});
  • minHeight: integer
    • Default is 0
    • Unit is pixels
    • Sets the iframe height to this value if the calculated value is less
    • Example:
      $('iframe').iframeAutoHeight({minHeight: 200});
  • animate: boolean
    • Default is false
    • Uses jquery animate with duration of 500 when resizing the iframe
    • Example:
      $('iframe').iframeAutoHeight({animate: true});
  • resetToMinHeight: boolean
    • Default is false
    • hard set the iframe height to the minHeight before re-sizing
  • triggerFunctions: Array of functions
    • Default is an empty array
    • Optionally define 1 or more functions that will have access to the resize method
    • can be used to resize the iframe from external events such as click or window resize - see examples below
  • heightCalculationOverrides: Array of 2 element arrays
    • Default is an empty array
    • Optionally re-define the height calculation method(s)
    • override the default implementation or just override specific browsers
    • Example:
      $('iframe').iframeAutoHeight({strategyOverrides: [{ browser: 'mozilla', calculation: function () { return 2000; }}]);
    • The
      key should be one of 'webkit', 'mozilla', 'msie', 'opera' or 'default', see
    • The
      key should be a function, usually with the signature
      (iframe, $iframeBody, options, browser)
    • see more examples below



// fire iframe resize when window is resized
var windowResizeFunction = function (resizeFunction, iframe) {
  $(window).resize(function () {
    console.debug("window resized - firing resizeHeight on iframe");

// fire iframe resize when a link is clicked var clickFunction = function (resizeFunction, iframe) { $('a').click(function () { $(iframe).contents().find('body').html(''); // clear content of iframe console.debug("link clicked - firing resizeHeight on iframe"); resizeFunction(iframe); }); };

$('iframe').iframeAutoHeight({ debug: true, triggerFunctions: [ windowResizeFunction, clickFunction ] });


// override all browser calculations using default
  debug: true,
  heightCalculationOverrides: [{
    browser: 'default',
    calculation: function (iframe, $iframeBody, options, browser) {
      return 1000;

// mozilla seems to be problematic for some // this is the usual work around, but it breaks demo pages so not used in plugin $('iframe').iframeAutoHeight({ debug: true, heightCalculationOverrides: [{ browser: 'mozilla', calculation: function (iframe, $iframeBody, options, browser) { // since the jquery browser is passed in you can also check specific versions if desired return iframe.contentDocument.documentElement.scrollHeight + options.heightOffset; } }] });

Plugin development

  • fork the repo
  • create a new branch
  • run
    grunt watch
  • modify the file
    as needed
    • grunt will auto compile it to the dist directory
  • view your changes in the browser
    • run
      python -m SimpleHTTPServer 8000
      or another web server
    • open in a browser -
  • verify all pages still function properly in as many browers as possible
  • Add your name to the file
    • alphabetical order
  • submit a Pull Request (PR)
    • include a list of OS / browser / version that the changes were tested in as part of the PR



2.0.0 / 2015-06-28

  • Changes entire repo directory structure
    • Use grunt for building and packaging code
    • Remove rails demo, use static html instead
    • Include jquery.browser.js in bower main
  • Add chrome to strategyKeys array
  • use
    instead of

1.9.5 / 2014-05-17

  • Update the way that the initial resize happens
    • load event may never trigger if content is already loaded

1.9.4 / 2014-05-14

  • maxHeight option

1.9.3 / 2013-06-01

  • the url was bad - doh!

1.9.2 / 2013-06-01

  • update url for jquery browser plugin, original repo was removed from github
  • jslint fixes

1.9.1 / 2013-02-02

  • Add js alert warning if using jquery 1.9 and up,
    is needed

1.9.0 / 2012-11-11

  • use the
    in-place of
    , requires jquery 1.4 and up

1.8.0 / 2012-09-22

  • new option - resetToMinHeight
  • new option - triggerFunctions
  • new option - heightCalculationOverrides

1.7.1 / 2012-06-02

  • webkit browsers, don't set to 0px on initial page load

1.7.0 / 2012-06-02

  • adds the animate option

1.6.0 / 2012-01-07

  • callback function invoking now allows access to the iframe in the callback

1.5.0 / 2011-08-18

  • add minHeight option, refactoring height calculation

1.4.0 / 2011-07-25

  • add debug option, small refactoring and minified version

1.3.0 / 2011-07-17

  • fix issue on Webkit (Google Chrome & Safari) when tall iframe links to short iframe

1.2.0 / 2011-07-08

  • If the iframe document is read in quirks mode, fixed a problem with IE not applying the correct height.

1.1.0 / 2011-05-29

  • added the ability to pass in a callback function

1.0.0 / 2010-10-22 / Initial release

  • converted code to plugin
  • match on specified selector instead of all iframes on page


  • Manual testing and documention of supported browser versions
  • Add specs to take screenshots
    • Sauce Labs?
  • Add instructions for defect reporting
    • code samples, screenshots, etc...


Original code by NATHAN SMITH; see

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.