With this entry I want to start a new bunch of articles under the subtitle of „Pure CSS“. Basically this means that I will be posting a number of articles dealing with web design issues and ways those issues can be solved in the most efficient and elegant way using CSS only! no JavaScript!
Specifically in this article, titled “Sticky Footer”, I will give you a step by step guide on how to create css sticky footers at the bottom of the page. I know that there are other methods out there and this issue has attracted more attention recently, but this is what I use and in my view it’s cleaner and applicable to existing HTML structures and you won’t have trouble uploading it to your web hosting provider.
It fulfills all main requirements of this type of solution: (a) it sticks at the bottom of the page only if all other content of the page does not occupy the full height of the page; (b) it works on IE5+, FF1+, Opera7+, Safari2+ and maybe even more; (c) and most importantly, it’s pure CSS.
So let’s get started…
The first thing we do is get acquainted with the basic HTML markup for this project. As I mentioned before this is a common HTML structure. We have a page container and content inside. The only thing that might be odd is that the footer is below and not inside the page container. This is important. Other than that it’s pretty straightforward:
<div id="container"> <div id="content"></div> </div> <div id="footer">My Sticky Footer</div>
Secondly, stretch html, body and page container elements to full window height. Notice that to make page container inherit body overflow I am using min-height property. Since IE6 or earlier does not support this, we have to make sure that IE, but only IE, applies height property to fix it. Here’s the right way to do it:
html, body,#container{ height: 100%; } body > #container { height: auto; min-height: 100%; }
Thirdly, we have to place the footer right after page container, creating a body overflow. However, we want it to be visible, so we forcibly move it up overlapping the bottom of page container — negative top margin for that reason. To make sure the whole footer is visible, negative margin must be equal to defined footer height. To fully secure footer’s position let’s clear both sides of floating elements, just in case.
#footer {
clear: both;
position: relative;
z-index: 10;
height: 3em;
margin-top: -3em;
}
Finally, we have to protect page content bottom from finding itself behind the footer by doing this:
#content { padding-bottom: 3em; }
Note that padding value is equal to footer height.
There you have it! You might want to check this sticky footer in action to get a sense of how it’s working.
April 14th, 2008 at 7:22 pmBuy Phentermine wrote:
Great Post, Thanks for sharing it. It is always good to read someone’s else point of view.
I Have bookmarked it for future use.
April 26th, 2008 at 11:58 pmKen wrote:
Great… very simple explanation and code for a sticky footer. What I am trying to do is create a layout that has a Header, more than one column (all of which will be equal height and stretch to fill the screen to the footer) and then the sticky footer. Is this possible?
May 18th, 2008 at 3:23 pmJeroen wrote:
Nice, i tried this on my own site but i have an issue. In IE it looks good but in Firefox i have to scroll down a bit (see: http://www.klassedesign.nl/test). I don’t see what i am doing wrong. Can someone help me?
Thanks!
May 18th, 2008 at 4:14 pmadmin wrote:
Jeroen, it’s your logo element that’s causing body overflow. Specifically, logo’s top margin. Margin creates space outside the element and makes nearby elements inherit this excess. In this case it would be recommended to use padding (inside space) instead. Keep that in mind, everybody.
May 18th, 2008 at 5:13 pmJeroen wrote:
Thanks! that works very well! I thought it was my logo when i was experimenting with firebug but this is the right solution.
June 6th, 2008 at 5:59 pmnic wrote:
you’re still popping up in google searches for CSS sticky footers…and it’s a good thing, too, because this is the clearest and best way to get a simple sticky footer. good work!
June 13th, 2008 at 12:46 pmSarah wrote:
Thanks for the clear explanation! I seem to have the same problem as Jeroen I checked about the use of margins but I don’t seem to be able to solve the problem. Could you help! The site I’m working on is:http://www.hyponetwork.de/index.php?id=1
Thanks!
September 2nd, 2008 at 6:17 pmtwgirl wrote:
hi
great, this works for me :)
i’m having a little problem though…
i have a div with absolute position since i need it to stay in the same place no matter what…the div would be the element thats under all the other content
the footer is working as this div doesnt exist, since it goes over the div until it finds the end of the rest of the content…
can u help me fix this little problem please?
thanks!
September 12th, 2008 at 9:25 amAbhishek wrote:
Nice Tutorial. Crisp and Clear. Thanks
September 12th, 2008 at 6:23 pmadmin wrote:
twgirl, it sounds like a specific issue. I (we) would have to see your code to figure out what’s going on. Good luck!
October 8th, 2008 at 8:22 pmAdded by a PAL to FAQ PAL wrote:
Pure CSS: Sticky Footer…
Specifically in this article, titled “Sticky Footer”, I will give you a step by step guide on how to create css sticky footers at the bottom of the page. I know that there are other methods out there and this issue has attracted more attention rece…
October 10th, 2008 at 8:03 pmJatin Kaka wrote:
nice tutorial…. will bookmark it for future reference.
crazyrahul84 | Designer | Iexplorehere
October 12th, 2008 at 11:25 amColin wrote:
I noticed that hidden in your own CSS file referenced from the example is:
p{margin:0;}
and if I remove that then a scroll bar appears.
I do not understand this - I thought that the default was zero anyway. Can anyone explain this, and how to get to behave as default while allowing the sticky footer to keep to the designated size?
October 12th, 2008 at 10:50 pmadmin wrote:
To Colin and all others that don’t want to import my reset.css. You should replace:
with:
Good luck!
October 13th, 2008 at 12:00 pmColin wrote:
Unfortunately, that does not work for me (FF 3.0.3). If I put a background over the “content” div, I see a white top margin, which pushes the displayed area larger than the window, however large the window is! Putting p{margin:0;} solves this, but I do not understand how the “p” margin has leaked out into the enclosing section.
October 13th, 2008 at 2:52 pmadmin wrote:
Colin, again, it sounds like a specific issue. Provide us with a link to your page and we’ll see if we can help. Margins, by the way, create outer, cross-layer space, so it can leak outside parent layers.
October 14th, 2008 at 5:56 pmcolin wrote:
Try your sticky footer, but remove the link to your CSS file.
I’ve just done it in IE7 - same thing - the scroll bar appears when the margin for “p” is not set to zero,
Other than that, this is a really neat solution - much better than others that I have seen.
October 15th, 2008 at 4:17 pmJohn wrote:
Hi
Thanks for the post. I normally use the Ryan Fait’s sticky footer solution (http://ryanfait.com/sticky-footer/), but for some reason it simply would not work on the site I was cutting up today.
Anyway found your solution (the principle is basically the same but your implementations are different) and it worked like a treat.
Cheers
October 16th, 2008 at 6:06 pmColin wrote:
There is a problem with IE if you float your “about” div. The footer will obscure the last line when the window is too small to hold both the content and the footer. The “clear:both” is clearly not working in IE. This is the solution that I have found - there may be a better one:
First create a new class in the CSS:
#prefooter {
margin: 0 0 1px;
width: 100%;
height: 1px;
clear: both;
}
and then put a suitable div in after the “about” div, so the structure looks like:
.. Whatever…
My Sticky Footer
That seems to satisfy IE and does not upset FF.
October 19th, 2008 at 8:10 pmadmin wrote:
Thanks Colin for your feedback.
Regarding issue #1, see this sticky footer without the link to my CSS file. Paragraph margin is set to 1em and it still looks fine on all browsers.
Regarding issue #2 I was actually hoping IE to enclose a float within a container ‘automatically’ (which it still does in many cases and websites), but I will have to look into this in the near future why it’s not happening in this simple example.
October 25th, 2008 at 2:29 pmColin wrote:
I have re-visited the padding problem. What I did originally was to remove your “theme” stuff as well as the link to your other CSS file. I wrongly attributed the scroll bar appearance to the p margins. I now discover that it is the padding applied to your “about” div. If the padding is non-zero, then there is no scroll bar. If the padding is zero, then scroll bar appears. BUT: if the padding is too small, then when the window is short then the footer overlaps the content. If you give the footer an opacity of around ,5, then you can see what overlaps with the padding too small.
November 1st, 2008 at 4:03 amSean Bannister wrote:
Here’s some screenshots of this method from a heap of browsers you’ll notice it doesn’t work under IE 5.01 and 4.0 :
http://browsershots.org/http://www.lwis.net/profile/CSS/sticky-footer.html
Due to the small browser share of IE 5 this doesn’t really bother me but it would be nice to work it out.
November 13th, 2008 at 9:16 pmCiaran wrote:
I found this to work much better than Ryan Faits code, which doesn’t work in Firefox no matter how hard I try. It always put the footer at the bottom of the screen as opposed to the bottom of the content. I’d recommend this version anyway, seems more robust. Cheers!
December 5th, 2008 at 7:30 pmBen Pickle wrote:
Great post. I went through two other tutorials that didn’t work before getting to this one. Pure dope.
December 11th, 2008 at 10:21 amJason wrote:
Just a note to those using .net. I struggled with the footer until I realised that the form tag also needs to be included in step 2
html, body, form, #container { height: 100%; }
and instead of inheriting from body, I inherited from form
form > #container { height: auto; min-height: 100%; }
This ensured that the also stretched.
December 22nd, 2008 at 9:34 amloganleger.com Renaissance | Logan Leger wrote:
[…] in the Wordpress Codex. Another CSS trick I used was a “sticky footer,” which I got here. This was really helpful and while I think it’s broken on some of the pages, it works quite […]
January 21st, 2009 at 6:15 amStever wrote:
A similar method, but also applies a clearfix hack to get things working in Chrome.
http://www.cssstickyfooter.com/
The clearfix also solves floating 2 column layout issues, browser re-size problems and others.
January 22nd, 2009 at 3:21 amJeremiah wrote:
This solution (and the one on cssstickyfooter.com) seems to break down if the height of the footer is less than 120px or so.
February 28th, 2009 at 4:46 pmIain wrote:
Excellent, thanks for your effort :)
April 23rd, 2009 at 3:08 pmGilles wrote:
Good job!
Thank you very much!
It works good!
April 24th, 2009 at 7:42 amDennison Uy wrote:
This is a very good implementation and a nice alternative to Cameron Adams’ footerStickAlt.
April 24th, 2009 at 12:57 pmCSS Vault Blog » Blog Archive » CSS Sticky Footer wrote:
[…] article from A List Apart, and takes suggestions from Cameron Adams’ footerStickAlt, and The Pure CSS Footer example from lwis.net. It applies a clear fix hack to keep the footer in place in Google Chrome and other browsers where […]
April 28th, 2009 at 3:50 pmnev wrote:
thanks
April 29th, 2009 at 3:01 amlinks for 2009-04-28 on studiowhiz.com wrote:
[…] Pure CSS: Sticky Footer - Science and Society by Tom@Lwis A great and simple tutorial for handling a sticky footer (tags: footer design sticky webdesign web tutorial tutorials css howto webdev development code html cool) […]
May 4th, 2009 at 9:43 pmJeevanath wrote:
Thank you very much!
It works good!
May 8th, 2009 at 12:21 pmSarah wrote:
Hello. I’m having a lot of problems with this and I cannot seem to find a solution. I am wondering if my javascript is interfering. I am getting a huge gap in between my footer and my content. I have looked at all the margins / heights in the content and I cannot seem to figure out what is causing the gap. I am not looking for someone to solve my problem, I just need someone to point out what is wrong…
May 8th, 2009 at 1:36 pmadmin wrote:
@Sarah, I don’t see a problem here. The larger your screen, the bigger the gap between the footer and the content. The footer is meant to stick at the bottom. Did I miss something?
May 26th, 2009 at 9:02 pmBrad wrote:
I’m trying to use your sticky footer method to cause two wraps, outer and inner, to scale 100% so that I can use two different background tiles (horizontal shadow tile vs vertical gradient tile for example). I can’t for the life of me figure out how to get the inner wrapper to scale to the height of the outer wrapper.
This is the last piece in the puzzle to a CSS framework hybrid I’ve been working on and any help would be greatly appreciated.
May 26th, 2009 at 9:09 pmBrad wrote:
Just to clarify, my outerwrap would be your container, then I would like to put another wrap inside this one and also have it stretch all the way to the bottom.
Thanks.
May 29th, 2009 at 12:46 pmadmin wrote:
@Brad, I think it should be:
html, body, #container, #container2 { height: 100%; }body > #container2 { height: auto; min-height: 100%; }
August 6th, 2009 at 6:16 amteo wrote:
thanks a lot
October 20th, 2009 at 2:55 amJohan wrote:
Thanks !!
October 20th, 2009 at 3:16 pmCSS Sticky Footer Layout | Jiby S K - Web Designer wrote:
[…] The Sticky Footer Layout posted here is from css sticky footer, A List Apart, Cameron Adams and, lwis.net. […]
December 17th, 2009 at 6:04 pmfrank wrote:
Lwis: thanks a million for this, was trying different methods and this is the best.
@Jason: your dot net version of the styles worked after I messed about with the original version and could not for the life of me get it to work. Thank you very much m8.
January 10th, 2010 at 4:20 amArisu wrote:
I love you O_O
This works so well! Thanks so much!
January 21st, 2010 at 3:20 pmHow to use the stiky footer « Mindless Thoughts wrote:
[…] Exploring Footers article from A List Apart as well as expands upon the work of Cameron Adams and this piece at lwis.net. It applies a clear fix hack to keep the footer in place in Google Chrome and other browsers where […]
March 12th, 2010 at 4:43 pmForrest wrote:
I can’t thank you enough for this solution. I have needed something like this for longer than I care to think. Thank you for sharing!
March 17th, 2010 at 6:46 pmJustin wrote:
Thank you so much for this easy-to-follow post! I’ve had difficulty applying this technique to my websites with the use of other tutorials but this one hit the nail on the head. Thanks!
April 19th, 2010 at 2:30 pmJhon wrote:
Thank You!
May 7th, 2010 at 3:25 pmkots wrote:
Thank you!
Very helpful to you.
May 24th, 2010 at 2:18 pmResurse noi pentru Web Design-ul cu CSS | WebShow wrote:
[…] Demo si Download […]
July 11th, 2010 at 2:28 amTop Css Techniques with Samples | Ulancer wrote:
[…] Pure CSS Sticky Footer […]
November 17th, 2010 at 4:32 pmRupen wrote:
but what about printing,
When I tried to print the sticky footer web page occupying two pages, the sticky footer is shown only once and that too at last page. what if we want to display this footer at the end of every page?
January 3rd, 2011 at 8:43 pmA pretty nifty #CSS sticky foo… | AdamJ_Design Tweet Backup wrote:
[…] Adam Johnson @AdamJ_Design Morgantown, WV | AdamJohnsonDesign.comA pretty nifty #CSS sticky footer: http://www.lwis.net/journal/2008/02/08/pure-css-sticky-footer/4:25pm 3 Jan 2011« Previous tweet Search all […]
January 4th, 2011 at 5:13 amandres wrote:
Groso man! years working on it!
February 2nd, 2011 at 7:01 pmAndrei wrote:
This worked perfectly.
February 9th, 2011 at 10:29 pmI want sticky footer - Ste Goodram wrote:
[…] The Sticky Footer solution presented here is based upon the information found in the Exploring Footers article from A List Apart as well as expands upon the work of Cameron Adams and this piece at lwis.net. […]
February 22nd, 2011 at 2:20 pmCreating Sticky Footer in CSS | Handy CSS wrote:
[…] pure css sticky footer […]
March 9th, 2011 at 4:06 pmJon Rivas wrote:
Hey! First of all, thank u for all the tutorials on this website, they are awsome. And now… I’ve got a problem with the sticky footer and I can’t explain how is possible that anyone had noticed this before:
All works fine until the window is resized to a small width.The horizontal scroll bar appears (of course) but the content now does not fill all the screen (width:100%), only the part that you see without scrolling. The rest “dissapears”. Try to resice window to a with of 400px and scroll to the left! what do you see? It also happens on lwis example and in all of actual websites using this code!
sorry for my bad english, I hope to have explained it well. Anybody has noticed it? is there any fix for this? do I have to publish screen captions to explain the problem in a better way?
thanks for reading!
May 13th, 2011 at 9:22 pmSimon wrote:
Thanks alot!! been looking for this, and this really worked:) css magic
May 26th, 2011 at 7:02 amSandeep wrote:
Thanks a lot
June 8th, 2011 at 1:51 pmJefferson Twacklethrade wrote:
So where’s the sticky footer on this page?
August 2nd, 2011 at 1:05 pmdigitalpbk wrote:
Thanks for the Tutorial. Works great
August 12th, 2011 at 10:00 amanonymus wrote:
How do you implement this on a dynamic page content. If the page content is more than the height of the page. the content seems to flow through the footer.
September 15th, 2011 at 1:34 amjfaith13 wrote:
I am having the same issue as anonymus (above) - I am using it on wordpress and it works beautifully until my content gets longer than the page, and then it (the content) goes right over the footer.
September 22nd, 2011 at 8:16 amMauritius Web design wrote:
Great stuff !!1
September 27th, 2011 at 9:37 pmComo Utiliar os Códigos HTML e CSS do Rodapé Fixo | Rafael Wisch wrote:
[…] A Solução de Rodapé Fixo apresentada aqui é baseada na informação encontrada no artigo Exploring Footers, da A List Apart assim como uma expansão do trabalho de Cameron Adams e este texto em lwis.net. […]
November 3rd, 2011 at 5:08 amBlogging Well » Blog Archive » 30 Pure CSS Alternatives to Javascript wrote:
[…] Pure CSS Sticky Footer […]
November 3rd, 2011 at 7:12 amBlogging Well » Blog Archive » 32 Javascript Alternatives with Pure CSS – Updated wrote:
[…] Pure CSS Sticky Footer […]
November 3rd, 2011 at 4:48 pm30 Effective Alternatives of CSS to Javascript | DesDevWeb wrote:
[…] Pure CSS Sticky Footer […]
November 8th, 2011 at 9:58 amgeek,aplicaciones web,descargas gratis,templates blogger,plantillas blogger wrote:
geek,aplicaciones web,descargas gratis,templates blogger,plantillas blogger…
[…]Pure CSS: Sticky Footer - Science and Society by Tomas Bagdanavičius[…]…
November 9th, 2011 at 4:37 pmsbobet2 login wrote:
Your write-up is really exciting. Many thanks.
November 25th, 2011 at 2:16 pmJames wrote:
This is actually the easiest solution to implement that i’ve found. Thank you.
December 16th, 2011 at 4:28 pmJelle wrote:
I implemented this technique in my website, and yes, the footer sticks to the bottom. But it only works well on the homepage where the most content is. I checked my margins, fiddled with the bottom padding and so on, but still a scrollbar appears and i have to scroll down to see the footer (disclaimer on my page) while content isn’t filling the page. Any thoughts?
December 20th, 2011 at 7:18 pmJelle wrote:
I got it sorted, nevermind.
I just added a extra div to push down the footer.
div.push {
clear:both;
height:[yourfooterheight+margins]px;
}
February 20th, 2012 at 11:08 amMichael Calkins wrote:
After tweaking it to fit my site worked like a charm!
March 11th, 2012 at 9:36 pmBethan wrote:
Great - first sticky footer that actually worked! Thank you :D
March 17th, 2012 at 3:02 pmTom De Herdt wrote:
Thanks, works great. But there seems to be an issue in IE8. Your sample page at http://www.lwis.net/profile/CSS/sticky-footer.html only works when the Google-JavaScript (div with ad) is there. When I make a local copy of the source code leaving out the ad div, the footer sticks at the bottom in IE8 but doesn’t move when I change window size. (But it does move to the bottom when I refresh the page.)
May 31st, 2012 at 7:11 pmBreno P. Lucena wrote:
Amazingly useful!
June 7th, 2012 at 12:50 pmangie wrote:
close enough! If you had a facebook like button, I would like it or share it..
September 25th, 2012 at 1:25 amChris wrote:
Great post. I know this article is pretty old so updates may not be possible, but Jason’s suggestion on December 11th, 2008 for us .NET developers would be great to have included in Step 2. That comment solved my problem and now its works great.
October 19th, 2012 at 1:46 pmnarendra wrote:
super explanation……
November 25th, 2012 at 3:25 amFred Manceaux wrote:
i tried this, but it doesn’t render correctly sometimes when resizing the window quickly, here’s the code that worked perfectly for me (yes there’s some js lol) : http://www.codicode.com/art/the_best_sticky_footer.aspx
hope this helps.
December 11th, 2012 at 2:35 pmAndy wrote:
Hi
After going through 1000s of sticky footer codes, I came across your and I must say, your code has finally put an end to my tiring search for a solution. I improvised your code a little to fit my requirements.
Here’s the page I made: http://a-malhotra.com/test/test2.htm
Here’s the html: view-source:http://a-malhotra.com/test/test2.htm
Here’s the css: http://a-malhotra.com/test/testformat2.css
Thank you very very much for your help.
Regards
December 28th, 2012 at 10:36 amsahil wrote:
Search all the web for this
but find the right solution here
thanks my friend