---
title: "How do I make a footer stick to the bottom of the page?"
description: "Keep a footer at the bottom of short pages without fixing it in place. Use a grid or flex layout with min-height: 100svh so the main content grows to fill the gap."
url: https://www.danny.engineering/answer/css/how-do-i-make-a-footer-stick-to-the-bottom-of-the-page
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:24:00.000Z
tags: ["CSS"]
---

# How do I make a footer stick to the bottom of the page?

## The short answer


Make the page wrapper at least as tall as the viewport, then let the main content take up any spare space. With CSS Grid, three rows of `auto 1fr auto` push the footer to the bottom on short pages and let it flow normally on long ones.


```css
body {
  min-height: 100svh;
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
```


```html
<body>
  <header>...</header>
  <main>...</main>
  <footer>...</footer>
</body>
```


## Why it happens


By default, a block element is only as tall as its content. If a page has a header, a short paragraph and a footer, the footer sits straight after the paragraph, halfway up the screen, with empty space below it.


What you usually want is a "sticky footer": on short pages it sits at the bottom of the viewport, and on long pages it sits after the content like normal. That is different from `position: fixed` or `position: sticky`, which keep the footer on screen while the page scrolls.


To get the sticky footer effect, two things must be true:

1. The wrapper around header, main and footer is at least the height of the viewport.
2. Something between the header and footer grows to fill the leftover space.

## How to fix it


### Use grid on the body


The grid version shown above is the shortest. `1fr` gives the middle row all the space left after the header and footer take their natural height. If the content is longer than the viewport, the grid just grows and the footer follows the content.


If your framework wraps the page in an extra element (for example a root `div` in a React app), put the grid on that element instead, and make sure there are exactly three direct children.


```css
#root {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
```


### Use flexbox


Flexbox works just as well. Make the wrapper a column and let `main` grow.


```css
body {
  min-height: 100svh;
  margin: 0;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}
```


An alternative is `margin-top: auto` on the footer, which pushes it down without changing `main`. That is useful when you cannot add styles to the content area.


```css
footer {
  margin-top: auto;
}
```


### Why 100svh and not 100vh


On mobile browsers, `100vh` is the height of the viewport with the address bar hidden. When the bar is showing, a `100vh` wrapper is taller than the screen, so the footer starts just out of view and the page scrolls for no reason. `100svh` (small viewport height) uses the height with the browser UI showing, so short pages fit without scrolling. The `svh`, `lvh` and `dvh` units have been supported in all major browsers since 2022.


If you need to support very old browsers, declare `100vh` first as a fallback:


```css
body {
  min-height: 100vh;
  min-height: 100svh;
}
```


## Common pitfalls

- Using `height` instead of `min-height`. A fixed height cuts off long pages or makes content overflow the footer.
- Forgetting the default `margin` on `body`. It adds a few pixels and causes a small scroll bar.
- Having more than three children in a three-row grid. An extra element such as a skip link or a portal root creates a new row and breaks the layout. Name the rows with `grid-template-areas`, or move the extra element out of the flow.
- Reaching for `position: fixed` or `position: absolute; bottom: 0`. The footer then covers content on long pages unless you add padding to match its height.
- Using `100vh` on mobile and wondering why short pages scroll.

## Related reading

- [MDN: grid-template-rows](https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-rows)
- [MDN: length units for the viewport](https://developer.mozilla.org/en-US/docs/Web/CSS/length#relative_length_units_based_on_viewport)
