# Why does my footer float up into the middle of the page when content is short

Source: https://coursesweb.net/forum/t/why-does-my-footer-float-up-into-the-middle-of-the-page-when-content/
Site: CoursesWeb Forum, category CSS Layout: Flexbox and Grid
Published: 2026-11-30. Updated: 2026-12-01. Replies: 2.

## Question by Ferdi K., 2026-11-30

Attempt number 5 at this and I am still stuck, so I am asking. My portfolio has a header, a main section and a footer. On the pages with a lot of text it is fine. On my Contact page there are only three lines of text, and the footer sits right under them, in the middle of the screen, with a big white gap below it. I want the footer at the bottom of the window.

```html
<body>
  <header>My portfolio</header>
  <main>
    <h1>Contact</h1>
    <p>Email me at the address below.</p>
  </main>
  <footer>Ferdi K. 2026</footer>
</body>
```

```css
footer {
  background: #222;
  color: #fff;
  padding: 20px;
}
```

What I tried so far:

1. height: 100% on body (nothing changed)
2. position: absolute; bottom: 0 on the footer (it is at the bottom now, but on my long pages it covers the last paragraph)
3. margin-top: 400px on the footer (works on my laptop, broke on my phone)

I used to run a warehouse shift, so I like things being where they belong. Why does the footer not just go to the bottom by itself?

## Reply 1 by Mpho N., 2026-12-01

Put height: 100vh on the body and the footer will be at the bottom. vh means viewport height, so the body is as tall as the window. Easy. I did this on my class project last month and the footer stayed at the bottom on the page I tested.

## Reply 2 by Gaelle R., 2026-12-01

You can also do it with grid. On the body: display: grid; min-height: 100vh; grid-template-rows: auto 1fr auto; It gives header, main and footer. The middle row takes the free space. I use this on every project.

---
Cite as: CoursesWeb Forum, "Why does my footer float up into the middle of the page when content is short", https://coursesweb.net/forum/t/why-does-my-footer-float-up-into-the-middle-of-the-page-when-content/, accessed 2026-12-01.
