🦶 CSS

The Sticky Footer Problem — Solved in 3 Lines (Finally)

📅 Jul 3, 2026 ⏱ 2 min read

Short page → footer floats mid-screen with awkward space below. A 15-year-old problem with a 3-line modern answer.

The flexbox solution

body {
  min-height: 100vh;          /* at least full screen (100dvh for mobile) */
  display: flex;
  flex-direction: column;
}
main { flex: 1; }             /* main absorbs the spare space */
/* header + footer keep natural height; footer lands at the bottom */

The grid version

body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;   /* header | main | footer */
}

Notes

This site uses the flex version — inspect body and see.

← All Articles