Skip to content
CoursesWeb Forum

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

Asked by Ferdi K. · CSS Layout: Flexbox and Grid2 repliesupdated

Short answer

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.

Written by Ferdi K. ·
CiteCoursesWeb 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.
  1. Member ·
    <body>
      <header>My portfolio</header>
      <main>
        <h1>Contact</h1>
        <p>Email me at the address below.</p>
      </main>
      <footer>Ferdi K. 2026</footer>
    </body>
    
    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?

    1
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. Mpho N.Member ·

    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.

  2. Gaelle R.Member ·

    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.

CoursesWeb Forum. Questions and answers on learning web development: HTML, CSS, JavaScript, PHP, MySQL, Node.js and AI coding help.