We just have a basic article element, with a header, main, and footer.
Try it out yourself:
HTML
As you can see, without any styles, the footer just sits right below the main element, instead of being at the bottom of the page.
Now let's move on to the styles.
CSS Styles
With our HTML markup established, we can apply the following styles to get the footer to stay at the bottom, regardless of the amount of content on the page.
CSS
html,
body {
height: 100%;
}
article {
display: flex;
flex-direction: column;
min-height: 100%;
}
main {
flex-grow: 1;
}
Try it below:
HTML
CSS
That's pretty much it. Now the footer is at the bottom of the page even though there isn't enough content to fill the page.
When there is enough content, the footer will follow naturally.
Conclusion
In this post, we looked at how to use CSS flexbox to ensure that your footer is at the bottom of the page.
Using the HTML markup and styles above, you can have a footer that remains at the bottom of the page even when there is not enough content to push it down.
Hopefully this helped you and thanks for reading!
To learn more about web development, founding a start-up, and bootstrapping a SaaS, follow me on X!