“When an HTML page contains a small amount of content, the footer can sometimes sit halfway up the page leaving a blank space underneath. This can look bad, particularly on a large screen. Web designers are often asked to push footers down to the bottom of the viewport, but it’s not immediately obvious how this can be done.”
Following up on How to keep footers at the bottom of the page by Matthew James. I figured out that there’s a much easier way to do that technique using Viewport units. Also when using older techniques with for example landing pages that have full height sections it kind of gets in the way and ruins the whole page but this way doesn’t so let’s get into it.
Representation of how the markup should look down below
.main-container and footer are all that matters in this case and it goes as follows:
<div class=”main-container”> <header>
this is a header
this is content
this is a footer
</footer></div> <!-— /.main-container-->
The header and your content are irrelevant to make the footer stick at the bottom in styling, so I’m just gonna write what’s necessary for keeping your footer always at the bottom.
min-height: 100vh; /* will cover the 100% of viewport */
padding-bottom: 100px; /* height of your footer */
- Pure HTML and CSS
- Works on Modern browsers and mobile browsers as well. Check Viewport units support here on caniuse.com
- The only downside is that you have to do padding that equals the height of your footer.
I also prepared a demo. You can grab it from here.
I hope that my small tip was helpful to you guys and your feedback is more than welcome.
Thanks for reading. 👏 Clap it if you like it. You can learn more about me on my personal website