I wrote an html to image renderer based on selenium back in the day, and this is how I handled auto sizing the page. https://github.com/machineonamission/mediaforge/blob/8e4470fd113bfce0aae848da0dd60f931120ccbc/chromiumrender.py#L289-L292 https://github.com/machineonamission/mediaforge/blob/8e4470fd113bfce0aae848da0dd60f931120ccbc/rendering/common.js#L1-L9 Feel free to browse the whole file for a bunch of other tricks I used for HTML rendering to png