Flexbox Sticky Footer Full Height

Create a sticky footer layout using flexbox with a column direction and auto margin on the main content area.

CssData Integrity

Code

csssnippet
13 lines
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header { flex: 0 0 auto; }
.page-main { flex: 1 1 auto; }
.page-footer { flex: 0 0 auto; }

@media (min-width: 768px) {
  .page-main { max-width: 960px; margin: 0 auto; }
}

Inside the snippet

display: flex distributes the children along one axis, and the alignment properties decide how leftovers are handled.

flex: 1 lets the item grow to absorb free space along the main axis.

1 media query adjusts the layout where the current arrangement stops fitting.

The rules target .page, .page-main, .page-footer — each selector names the element it restyles, in source order.

Interactive Tools for This Topic

FAQ

Which elements does this stylesheet target?
The rules bind to `.page`, `.page-main`, `.page-footer`; when two rules tie in specificity, the one written later in the file wins.