Sticky Variable-Height Footer

suggest change

This code creates a sticky footer. When the content doesn’t reach the end of the viewport, the footer sticks to the bottom of the viewport. When the content extends past the bottom of the viewport, the footer is also pushed out of the viewport. View Result


<div class="header">

<div class="content">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. </p>

<div class="footer">


html, body {
  height: 100%;

body {
  display: flex;
  flex-direction: column;

.content {
  /* Include `0 auto` for best browser compatibility. */
  flex: 1 0 auto;

.header, .footer {
  background-color: grey;
  color: white;
  flex: none;

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents