One problem I run into pretty frequently when coding a site in to XHTML and CSS is making my footer dock to the bottom of the screen. It’s especially annoying if you have a page that’s short on content and the footer, which happens to be a different color that the body background doesn’t stay at the bottom of the browser window. I can hear you say, “But why don’t you just do a fixed position on it. That’s easy enough.” True, but if you do that then it’s always at the bottom of the screen no matter how tall the window is. So if I have a page with a lot of content that footer shouldn’t show up until the content is done. How do we fix this? Let me show you. Here’s what the problem looks like:

This tutorial assumes a few things: 1. That you know basic HTML formatting, and 2. That you have a pretty good understanding of CSS.
So first we need to make sure that everything except the footer is inside a container div. So your code would look something like this:
<div id="container">
<div id="header">Header</div>
<div id="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
</ul>
</div>
<div id="content">Content Here.</div>
</div><!—End Container—>
<div id="footer">Footer Here.</div>
Now that you’ve got your basic HTML set up, let’s head over to the CSS and see what we need to do there to get it to work. First, we want to give the html and body tags a height of 100%:
html, body {
height: 100%;
}
Next, we need to set the container div to position:relative, min-height: 100% and negative margin the bottom the height of the footer. What? A fixed height footer you say? Yes, I haven’t quite figured out the best way to do it otherwise:
#container {
min-height: 100%;
margin-bottom: -330px;
position: relative;
}
Now, onto the footer. Make sure the height on the footer matches the height of the negative margin on the container and set the position to relative:
#footer {
height: 330px;
position: relative;
}
What’s that? Yes, I know it doesn’t work yet. There’s still a bit of magic to be done. See it turns out we need a div to help separate the footer from the container. We’re going to call it clearfooter. So jump back to your HTML and add the div class right inside the closing div of the container. That’s very important. Inside the closing div:
<div id="container">
<div id="header">Header</div>
<div id="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
</ul>
</div>
<div id="content">Content Here.</div>
<div class="clearfooter"></div>
</div><!—End Container—>
<div id="footer">Footer Here.</div>
Head back over to your CSS file and add this to the clearfooter div. Notice the height again:
.clearfooter {
height: 330px;
clear: both;
}
Alright! So for those of us using browsers that aren’t stupid, this should work great. But 80% of use that one browser that is stupid, our friend Internet Explorer 6. Thankfully, it’s a pretty simple fix. I know, how often does that happen? First of all, you should know that IE7 should work fine with what we’ve done up to this point. So all we need is an IE6 specific “hack.” In your header where you’re calling your external stylesheet put this:
<!—[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]—>
This is a conditional statement for IE6 so it will load the CSS file only in that browser. In the CSS file, all you have to put is:
#container {
height: 100%;
}
So there you have it! This works in IE 6 and 7, Firefox and Safari 2 and 3. I hope you’ve found this a useful tool in your CSS arsenal. If you know a better way, please let us know in the comments!

Update: Sorry guys, we had to turn off comments. Too much spam :(
Share This Entry with Your Favorite Social Networking Sites.@Shayla Dude I have no idea what you’re talking about without a link. I’m one of those visual people
.
You just helped me put an end to my fruntration!!! :D
Thank you Jonathan, this helped me a LOT! works perfect for iexplorer, firefox and chrome
Im a webdesigner newbie/fan but im starting to get the grip now. Ill let you check my first site after i get the basic layout done so i can get a profesional opinion
thanks again.
Exactly what I was looking for and excellent solution. Thank you Jonathan! The footer stays put with this!
Excellent tutorial! Getting the footer to stick at the bottom is a chore, and you’ve found an easy and effective solution. Thanks for sharing!
Thanks for the info. I always wondered exactly how they did that. I knew it was CSS with some div soup.
Interesting I do a different way of positioning my footer and with a lot of codes in it. But this one is very simple and less code I will definitely try this one. Thanks!
Thank you for very helpful article
If you’re not interested in using a full-on IE6 conditional stylesheet (maybe this is the only thing you’re using that needs it, who knows), you can use “!important” to target all modern browsers (including IE7+).
#container {
height: auto !important; /* Everything except IE6 */
height: 100%; /* IE6 */
}
Make sure to place the !important line ABOVE the 100%, since browsers read CSS importance from top to bottom. If you don’t know about hierarchy, a quick search online should yield some good reads.
Good article, Jonathan! Sorry I had only heard about it now (you can thank Smashing Magazine for that). =)
Welcome all you Smashing Magazine readers! This has been up for a while but I hope you find it useful
Great post, became a massive help for me after quite a few hours of working out how to stick a footer to the bottom of a site I am working on! Added to favourites for future reference! Thanks.
hey!
I was looking forward for a way to do it regarding the web semantic… cause we know that a empty DIV is not so good ... but I know that it really works…
you can avoid this with another tec. - visit my site to check it: http://www.webstandards.blog.br - (you may noticed that it is in portuguese, but the code is always the same
- CSS footer fixed.
thanks, see ya
You’re blog articles don’t print very well at all. (Using Mac OS X Leopard)
I like to print resourceful articles like this as PDF’s and save them on my local machine. You should consider developing a print stylesheet that organizes content better and cuts out the background image/navigation.
Just a thought.
@Jeff, Man I wish I had time to put together a print stylesheet! Been on the list of things to do for like 2 years
. In the meantime try this out: http://lab.arc90.com/experiments/readability/
@Jonathan, I can relate to that! Print stylesheets always end up on the back burner. Pretty sweet Readability resource, though. Thanks man.
Good article on the footer control, too, btw. Gracias.
Great tutorial. Thanks.
Thank you Thank you Thank you! I’ve been struggling to find a way to fix this problem. You’re a genius!
Thankx a lot
Hey Jonathan
This is a great solution. I’m having one problem though. I can’t seem to get the divs inside the container div to use height:100%;
My ‘nav’ div and ‘content’ div have different colour backgrounds so you can imagine that things don’t look good when they’re not filling the gap between them and the footer. Any solution to this?
I just solved my problem.
If you have any divs inside the container div that you want to have “100%” height then set the css for the divs to the following:
position:absolute;
height:inherit;
Problem solved
Hmmmm, my previous post came out a little funny towards the end…I think there’s a css error going on somewhere there.
Sorry guys but the height in my post is meant to be:
min-height: inherit;
NOT
height: inherit;
ok, my solution just doesn’t work very well.
The footer doesn’t work with the inner div’s having a position of absolute.
Guess I’m still stuck o.O
B, I’m not sure why you’re trying to se 100% heights on your nav and container, but if you want a color to fill it up all the way down you’ll need to use a background image on the body or something like that.
BestChristianDesign is helping give churches inspiration for their next project. Good call, guys.
Seth Godin reminds us to enjoy and take advantage of the uphills.
Stop announcing your new project. Just do it.
Rock and Roll people, Rock and Roll.
To all you staff designers out there, here’s a link for you. (via @ryanlascano)
Fascinating look into the music business.
Derek Sivers posts some great advice about balancing your life.
@bigonroad Thanks man :)
@ryanlascano You're kidding me! I just had a friend from high school tell me she has a Cosmo too. I think women name black cats Cosmo.
The best Content Management System for designers. Feature rich, completely customizable, and easily extendable.
Basecamp is the smarter, easier, more elegant way to collaborate on your internal and client projects.
(JavaScript must be enabled to view this email address)
May 06, 2009
Okay, got it working in FF, but in IE7 the backgrounds on the columns do not extend and the footer is sitting on top of the content not at the bottom of the page. Any suggestions?