CSS

Create a Sticky Footer Layout with Flexbox

Implement a robust sticky footer design using Flexbox that always remains at the bottom of the viewport, even on pages with limited content, for a polished user experience.

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

body {
  display: flex;
  flex-direction: column; /* Stacks header, content, and footer vertically */
}

.main-content {
  flex: 1; /* This makes the content area expand to fill available space */
  padding: 20px;
  background-color: #f9f9f9;
}

header, footer {
  padding: 15px;
  background-color: #333;
  color: white;
  text-align: center;
}
How it works: This snippet constructs a classic sticky footer layout. By setting `html` and `body` to `height: 100%` and `body` to `display: flex` with `flex-direction: column`, we create a column-based flex container spanning the full viewport. The magic happens with `.main-content { flex: 1; }`, which allows the content area to grow and consume all available space between the header and footer, effectively pushing the footer to the bottom.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs