How can I ensure that a div element in Webflow has the same height as the entire HTML document, even after exporting the code?

TL;DR
  • Set the div's height to 100vh in Webflow for initial viewport coverage.  
  • After export, set html and body to height: 100% in CSS, and apply min-height or height: 100% to the div.  
  • Use JavaScript to dynamically set the div's height if the document content changes.

To ensure a div element matches the full height of the HTML document in Webflow, even after exporting the code, you need to anchor it to the document height using custom styles.

​

1. Use 100vh for Initial Height

  • Set the div’s height to 100vh to match the viewport height in Webflow. However, this matches only the visible screen, not the full scrollable document.
  • In Designer: Select the div → In the Style panel, set Height to 100vh.

​

2. Apply height: 100% with Full Document Context

To match the document height (including scroll), you need to ensure the parent structure allows it.

​

  • By default, height: 100% doesn’t work unless all parent elements support it.
  • After export, adjust the following in your site’s CSS (inside <style> tag or external CSS):
  • Ensure html and body have height: 100%.
  • Set your target div to min-height: 100% or height: 100%, depending on layout.

​

Example styles to include after export:

html, body {
  height: 100%;
  margin: 0;
}

#your-div-id {
  min-height: 100%;
}

(Replace #your-div-id with your div’s actual ID or class.)

​

3. Use JavaScript for Dynamic Document Height (Optional)

If the document height changes dynamically (e.g., due to added content), use light JavaScript to update the div.

​

  • Add this inside <script> tag at the bottom of the exported HTML:
document.addEventListener("DOMContentLoaded", function() {
  var docHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
  document.getElementById("your-div-id").style.height = docHeight + "px";
});

​

  • This ensures your div stretches to the actual document height, regardless of content changes.

​

Summary

To make a Webflow div match the full document height after export, give html and body height: 100%, then set your div’s height with CSS or JavaScript. Use 100vh for viewport height and JS if the document height is dynamic.

Rate this answer

Other Webflow Questions