How to fix a footer at the bottom of the page
Tags: html, css
Published: 2019-09-30 03:34:12

<p>I believe all beginning developers at some point come across this problem while building web pages. Sometimes you have too little content on your page, then your footer ‘jumps up’ and follows the rest of the content somewhere in the center of a page. See picture below.</p>
![Footer doesn't stick to the bottom](https://thepracticaldev.s3.amazonaws.com/i/4mt05n3icstrh29v8xa4.jpg)
<p>I’ll share with you an easy way how to fix that step by step. </p>
<p>Markup of the page is very simple. Inside the body we have a main section and a footer. The main section contains a heading and a paragraph with some lorem ipsum text to fill in some space. As we can see the footer is in the middle of the page.</p>
![html markup](https://thepracticaldev.s3.amazonaws.com/i/ce83jgh6o8w5f2cbrfoi.jpeg)
<p>If you want you footer to be attached to the bottom of the screen and you are not going to change its content a lot you can give it a fixed height. My footer is 35px high. Basic styling is below.</p>
![Footer basic styles](https://thepracticaldev.s3.amazonaws.com/i/rmdjkpnas916lj4s2sv9.jpeg)
<p>We need just 3 lines of code to force it to the bottom of the page.</p>
<p>To do that we need to give our footer a position of fixed, this will take it out of the normal flow of the document. After that we can place it anywhere on the page, in our case we change its position to 0px from the bottom and 0px from the left.</p>
![Footer final styles](https://thepracticaldev.s3.amazonaws.com/i/ft3cl12ylrr1p0rgqbqx.jpeg)
<p>Now our footer is attached to the bottom of the page.</p>
![Footer sticks to the bottom](https://thepracticaldev.s3.amazonaws.com/i/3phwxax5udmt5e9zkqmf.jpg)
<p>We might think we are done now. Not yet…</p>
<p>As we add more content onto the page we get into trouble. In our case I’ll add more lorem ipsum text so that it reaches the bottom. As we do that we find out that we don’t see the end of the lorem ipsum text. The footer is overlapping it. Even if you scroll to the very bottom of the page some part of the text is covered by the footer.</p>
![Text covered by the footer](https://thepracticaldev.s3.amazonaws.com/i/stxi8cesja1oot0dmg3f.jpg)
<p>This can be fixed with one line of code.</p>
<p>We know that our footer is 35px high. It means that to be able see all the content of the section that goes before the footer we need to move the bottom of that section up by 35px. We can do that by giving our main section a margin-bottom of 35px. This way the bottom edge of our main section and the top edge of the footer are not overlapping any more, they are now attached to each other, and the content is not covered by the footer.</p>
![Main final styles](https://thepracticaldev.s3.amazonaws.com/i/c9h7zct0qey0m6g4uwtx.jpeg)
![Final print screen, text is not covered by the footer](https://thepracticaldev.s3.amazonaws.com/i/2oruvi5mckarqqzi0zxf.jpg)
<p>This is my first article that I wrote with the intention to help beginning developers to find easy solutions to common issues that 100% of beginners face.</p>
<p>Hopefully I’ll help you make your life easier.</p>
<p>More article to follow…</p>