Flexbox Sticky Footer Full Height
Create a sticky footer layout using flexbox with a column direction and auto margin on the main content area.
Code
.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
CSS Flexbox PlaygroundInteractively test CSS flexbox container and item properties with a live preview. Adjust justify-content, align-items, flex-direction, and flex-grow to see layout changes.CSS Grid PlaygroundExperiment with CSS grid layout properties interactively. Define columns, rows, gaps, and areas while watching the grid template update in a live visual preview.Line Height CalculatorConvert between a unitless line-height ratio and its pixel value for a given font size.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
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.
Report a problem with this exampleOpens a pre-filled issue on GitHub.