How to Fix Footer Not Sticking to Bottom of Page: A Complete CSS Guide

A common issue in web development is the 'flying footer'—where the footer floats in the middle of the screen because the page content is too short. To create a professional look, your footer should always stay at the bottom of the browser window even on pages with minimal text. This guide covers the most effective modern methods to fix this using CSS Flexbox and Grid.

Step 1: Identify the 'Flying Footer' Problem

When the content of a webpage is shorter than the height of the browser window, the footer follows the last element immediately, leaving a blank white space underneath. This often happens on Blogger templates or custom landing pages. To fix this, we must ensure the main container occupies the full height of the viewport.

Step 2: The Modern Flexbox Solution

The most reliable way to fix this bug is by applying Flexbox to your site's body tag. This method forces the main content area to expand and push the footer to the bottom. Add the following code to your CSS stylesheet:

body {    display: flex;    flex-direction: column;    min-height: 100vh;    margin: 0;  }    main {    flex: 1;  }

In this snippet, min-height: 100vh ensures the body is at least as tall as the screen. The flex: 1 property on the main content element tells it to grow and fill all available empty space.

Step 3: Implementing the CSS Grid Fix

If your layout already uses CSS Grid, you can achieve a sticky footer with even fewer lines of code. This is ideal for modern Blogger template customization. Use the following structure:

body {    display: grid;    grid-template-rows: auto 1fr auto;    min-height: 100vh;  }

This layout defines three rows: the header (auto), the main content (1fr), and the footer (auto). The 1fr (fractional unit) ensures the middle section expands to fill the remaining vertical space.

Step 4: Troubleshooting Blogger Templates

If you are editing a Blogger XML template, go to Theme > Edit HTML. You may need to identify the specific IDs used by Blogger (like #outer-wrapper or .main-wrapper). Apply the min-height and display: flex properties to the outermost container. Ensure there are no fixed heights (e.g., height: 500px) set on your blog posts area, as this will override the dynamic stretching.

Step 5: Avoid the 'Position: Absolute' Trap

Many beginners try to fix this by using position: absolute; bottom: 0; on the footer. Avoid this method because it takes the footer out of the document flow, causing it to overlap your content on mobile devices or pages with long text. Stick to the Flexbox or Grid methods mentioned above for a fully responsive and bug-free design.


💡 Pro Tip: Keep your software updated to avoid these issues in the future.


Category: #Website