Stack Overflow

A private, secure home for your teams questions and answers.

Sign uporlog into customize your list.

Start here for a quick overview of the site

Detailed answers to any questions you might have

Discuss the workings and policies of this site

Learn more about Stack Overflow the company

Learn more about hiring developers or posting ads with us

Join Stack Overflowto learn, share knowledge, and build your career.

I have a simple 2-column layout with a footer that clears both the right and left div in my markup. My problem is that I cant get the footer to stay at the bottom of the page in all browsers. It works if the content pushes the footer down, but thats not always the case.

Its not working properly in Firefox. Im seeing a strip of background color below the footer when theres not enough content on the page to push the footer all the way down to the bottom of the browser window. Unfortunately, this is the default state of the page.

Ill add to @Jimmy: You also need to have to declare absolute (or relative) positioning to the element that contains the footer. In your case, its the body element. Edit: I tested it on your page with firebug and it seemed to work very well…

answer by gcedo, it is much more appropriate these days since one doesnt have to set hard-coded

to the above element or wrapper. The outdated approaches are highly upvoted because of being on the top (since they appeared earlier)

(or even better one by Temani Afif, without an extra spacer element)

Have adivwithclass=wrapperfor your content.

Rightbeforethe closing/divof thewrapperplace thediv class=push/div.

Rightafterthe closing/divof thewrapperplace thediv class=footer/div.

* margin: 0; html, body height: 100%; .wrapper min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -142 /* the bottom margin is the negative value of the footers height */ .footer, .push height: 142 /* .push must be the same height as .footer */

It does not work in with form tag

@jlp: You need to add the form tag to the height:100% statement, else it will break the sticky footer. Like this: html, body, form height: 100%

I noticed that adding padding to the footer screws it, but figured out that that can be fixed by subtracting the extra padding on the footer from the footer, push height.

The detailed explanation with the demo is provided in this site:CSS Sticky Footer

@Syk Ive found that reducing the min-height helps. 94% is an ok value, but you still see the issue on mobile 🙁 Not sure theres a real solution here.

Probably the most obvious and non-hacky way to go about a sticky footer would be to make use of the newcss viewport units.

Take for example the following simple markup:

headerheader goes here/header div class=contentThis page has little content/div footerThis is my footer/footer

If the header is say 80px high and the footer is 40px high, then we can make our sticky footerwith one single ruleon the content div:

Which means: let the height of the content div beat least100% of the viewport height minus the combined heights of the header and footer.

* margin:0; padding:0; header background: yellow; height: 80 .content min-height: calc(100vh – 120px); /* 80px header + 40px footer = 120px */ background: pink; footer height: 40 background: aqua; headerheader goes here/header div class=contentThis page has little content/div footerThis is my footer/footer

… and heres how the same code works with lots of content in the content div:* margin:0; padding:0; header background: yellow; height: 80 .content min-height: calc(100vh – 120px); /* 80px header + 40px footer = 120px */ background: pink; footer height: 40 background: aqua; headerheader goes here/header div class=contentLorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum. /div footer This is my footer /footer

1) The height of the header and footer must be known

2) Old versions of IE (IE8-) and Android (4.4-) dont support viewport units. (caniuse)

3) Once upon a time webkit had a problem with viewport units within a calc rule. This has indeed been fixed (see here) so theres no problem there. However if youre looking to avoid using calc for some reason you can get around that using negative margins and padding with box-sizing –

Like so:* margin:0;padding:0; header background: yellow; height: 80 position:relative; .content min-height: 100vh; background: pink; margin: -80px 0 -40 padding: 80px 0 40 box-sizing:border-box; footer height: 40 background: aqua; headerheader goes here/header div class=contentLorem ipsum /div footer This is my footer /footer

This is pretty much the best solution Ive seen here, worked even in my strange case with some contents of the ntent overflowing into the footer for who-knows-what-reason. And I guess that with sth like Sass and variables, it could be ever more flexible.

Indeed, this one works like a charm. Easy to fallback for a non-supporting browsers too.

How is messing with absolute measurements not still hacky? At best its perhaps

But and if the height of footer and header is mensured in percent and not px? Like 15% of the pages height?

Viewport units dont always work as expected on mobile browsers that hide or show address bar depending on scroll position

You could useposition: absolutefollowing to put the footer at the bottom of the page, but then make sure your 2 columns have the appropriatemargin-bottomso that they never get occluded by the footer.

footer position: absolute; bottom: 0 width: 100%; content, sidebar margin-bottom: 5em;

Ive tried this with my similar setup (two columns + footer) and it does not work.

It overlap with content if content grow.

thats why content has the margin-bottom. you have to set it to whatever fixed height you make the footer.

Solution inspired byPhilip Waltons sticky footer.

It is based on theflexdisplay, leveraging theflex-growproperty, which allows an element togrowin eitherheightorwidth(when theflow-directionis set to eithercolumnorrowrespectively), to occupy the extra space in the container.

We are going to leverage also thevhunit, where1vhisdefined as:

1/100th of the height of the viewport

Therefore a height of100vhits a concise way to tell an element to span the full viewports height.

This is how you would structure your web page:

In order to have the footer stick to the bottom of the page, you want the space between the body and the footer to grow as much as it takes to push the footer at the bottom of the page.

———– body ———– —————————- ———- spacer ———- – This element must grow in height —————————- ———- footer ———- —————————-

body margin: 0; display: flex; flex-direction: column; min-height: 100vh; .spacer flex: 1; /* make it visible for the purposes of demo */ .footer height: 50 background-color: red; body div class=contentHello World!/div div class=spacer/div footer class=footer/footer /body

You can play with it atthe JSFiddle.

Be aware that Safari has aflawed implementation of theflex-shrinkproperty, which allows items to shrink more than the minimum height that would be required to display the content. To fix this issue you will have to set theflex-shrinkproperty explicitly to 0 to theand thefooterin the above example:

.content flex-shrink: 0; .footer flex-shrink: 0;

I feel this is the correct answer, since its actually the only approach which works even when the height of the footer is not known.

I request the OP to accept this as the answer. This is the only non-hacky and general solution. Due to other answers being severely high voted, users often overlook this answer and later regret — first-hand experience. 🙂

This messes up the grid with Neat 2

But why not the Philip Waltons solution itself, why an extra spacer element?

You will then need to add apaddingormarginto the bottom of yoursidebarandcontentto match the height offooteror when they overlap, thefooterwill cover them.

Also, if I remember correctly, IE6 has a problem with thebottom: 0CSS. You might have to use a JS solution for IE6 (if you care about IE6 that is).

Here is a solution with jQuery that works like a charm. It checks if the height of the window is greater than the height of the body. If it is, then it changes the margin-top of the footer to compensate. Tested it in Firefox, Chrome, Safari and Opera.

$( function () var height_diff = $( window ).height() – $( body ).height(); if ( height_diff 0 ) $( footer ).css( margin-top, height_diff ); );

If your footer already has a margin-top (of 50 pixels, for example) you will need to change the last part for:

Use absolute positioning and z-index to create a sticky footer div at any resolution using the following steps:

Set the padding of the footer to add whitespace between the content bottom and the window bottom

position: relative; min-height: 100%;

Add bottom padding to the main content

that is equal to the height plus padding of the footer

of the footer greater than the container

!doctype html html head titleSticky Footer/title meta charset=utf-8 style .wrapper position: relative; min-height: 100%; .footer position: absolute; bottom:0; width: 100%; height: 200 padding-top: 100 background-color: gray; lumn height: 2000 padding-bottom: 300 background-color: green; /* Set the `html`, `body`, and container `div` to `height: 100%` for IE6 */ /style /head body div class=wrapper div class=column spanhello/span /div div class=footer pThis is a test. This is only a test…/p /div /div /body /html

A similar solution out the need of adding an intermediate content in order to push the footer down. We can simply addmargin-top:autoto the footer and it will be pushed to the bottom of the page regardless his height or the height of the content above.

body display: flex; flex-direction: column; min-height: 100vh; margin:0; ntent padding: 50 background: red; .footer margin-top: auto; padding:10 background: green; div class=content some content here /div footer class=footer some content /footer

to make it growable and non-shinkable, but

is a nice trick that involves styling footer, not non-related

which is nice. Actually, I wonder why flex is needed in this approach..

@YakovL yes the main idea here is the margin-top trick 😉 I know that I can make the content like this but it will be almost the same as a previous answer where the idea is to push the footer by the content … and here I wanted to avoid this and push the footer only with margin;)

@YakovL flex is needed for the margin:auto 🙂 we cannot use it without it … as margin:auto behave slightly different with flex item then block items. If you remove

it wont work, you will have a normal block element flow

Yeah, I can see that it wont work without it, but I dont understand why (whats slightly different)

@YakovL its simple, using normal block element the flow is always a row direction so only margin right/left used with auto will work (like the famous

to center block element) BUT we dont have any column direction so there is no margin auto with top/bottom. Flexbox has both row/column direction ;). This is the slight difference, but margin is also used within flexbox to align element so even within a row direction you can use margin-top/bottom auto to align vertically .. You can read more here /TR/css-flexbox-1/auto-margins

Try putting a container div (with overflow:auto) around the content and sidebar.

If that doesnt work, do you have any screenshots or example links where the footer isnt displayed properly?

One solution would be to set the min-height for the boxes. Unfortunately it seems thatits not well supported by IE(surprise).

None of these pure css solutions work properly with dynamically resizing content (at least on firefox and Safari) e.g., if you have a background set on the container div, the page and then resize (adding a few rows) table inside the div, the table can stick out of the bottom of the styled area, i.e., you can have half the table in white on black theme and half the table complete white because both the font-color and background color is white. Its basically unfixable with themeroller pages.

Nested div multi-column layout is an ugly hack and the 100% min-height body/container div for sticking footer is an uglier hack.

The only none-script solution that works on all the browsers Ive tried: a much simpler/shorter table with thead (for header)/tfoot (for footer)/tbody (tds for any number of columns) and 100% height. But this have perceived semantic and SEO disadvantages (tfoot must appear before tbody. ARIA roles may help decent search engines though).

This should do the trick if you are looking for a responsive footer aligned at the bottom of the page,which always keeps a top-margin of 80% of the viewport height.

For this question many of the answers I have seen are clunky, hard to implement and inefficient so I thought Id take a shot at it and come up with my own solution which is just a tiny bit of css and html

html, body height: 100%; margin: 0; .body min-height: calc(100% – 2rem); width: 100%; background-color: grey; .footer height: 2rem; width: 100%; background-color: yellow; body div class=bodytest as body/div div class=footertest as footer/div /body

this works by setting the height of the footer and then using css calc to work out the minimum height the page can be with the footer still at the bottom, hope this helps some people 🙂

I have myself struggled with this sometimes and I always found that the solution with all those divs within each other was a messy solution. I just messed around with it a bit, and I personally found out that this works and it certainly is one of the simplest ways:

What I like about this is that no extra HTML needs to be applied. You can simply add this CSS and then write your HTML as whenever

Multiple people have put the answer to this simple problem up here, but I have one thing to add, considering how frustrated I was until I figured out what I was doing wrong.

As mentioned the most straightforward way to do this is like so..

html position: relative; min-height: 100%; body background-color: transparent; position: static; height: 100%; margin-bottom: 30 .site-footer position: absolute; height: 30 bottom: 0 left: 0 right: 0

However the property not mentioned in posts, presumably because it is usually default, is theposition: staticon the body tag. Position relative will not work!

My wordpress theme had overridden the default body display and it confused me for an obnoxiously long time.

An old thread I know, but if you are looking for a responsive solution, this jQuery addition will help:

$(window).on(resize,sticky); $(document).bind(ready, function() sticky(); ); function sticky() var fh = $(footer).outerHeight(); $(push).css(height: fh); $(wrapper).css(margin-bottom: -fh);

I have created a very simple library

It is very simple in use. After including library, just call this line of code.

Footers can be dynamically changed by recalling above function with different parameter/id.

Note:- You havent to alter or add any CSS. Library is dynamic which implies that even if screen is resized after loading page it will reset the position of footer. I have created this library, because CSS solves the problem for a while but when size of display changes significantly,from desktop to tablet or vice versa, they either overlap the content or they no longer remains sticky.

Another solution is CSS Media Queries, but you have to manually write different CSS styles for different size of screens while this library does its work automatically and is supported by all basic JavaScript supporting browser.

@media only screen and (min-height: 768px) /* or height/length of body content including footer*/ /* For mobile phones: */ footer width: 100%; position:fixed; bottom:0;

Now, if the height of display is more than your content length, we will make footer fixed to bottom and if not, it will automatically appear in very end of display as you need to scroll to view this.

And, it seems a better solution than JavaScript/library one.

I wasnt having any luck with the solutions suggested on this page before but then finally, this little trick worked. Ill include it as another possible solution.

Flex layout is preferred for natural header and footer heights. This flex solution is tested in modern browsers and actually works 🙂 in IE11.

html height: 100%; body height: 100%; min-height: 100vh; overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 0; display: flex; flex-direction: column; main flex-grow: 1; flex-shrink: 0; header, footer flex: none;

For me the nicest way of displaying it (the footer) is sticking to the bottom but not covering content all the time:

jQuery CROSSBRAWSER CUSTOM PLUGIN – $.footerBootom()

Or use jQuery like I do, and set your footer height toautoor tofix… what ever you like, it will work anyway. this plugin uses jQuery selectors so to make it work you will have to include jQuery library to your file. Anyway…

Here is how You run the plugin. Import jQuery, copy the code of this custom jQuery plugin and import it after importing jQuery!. It is very simple and basic but important.

When you do it all you have to do is run this code:

$.footerBootom(target:footer); //as html5 tag footer. // You can change it to your preferred div with for example class footer // by setting target to target:div.footer

there is no need to place it inside the document ready event. It will run well as it is. It will recalculate position of your footer when page is loaded and when window get resized.

Here is the code of the plugin which u do not have to understand. Just know how to implement it. It does the job for you. However if you like to know how it works just look through the code. I left there comments for you.

//import jQuery library before this script //our custom jQuery Plugin (function($) $.footerBootom = function(options) //or use $.fn.footerBootom or $.footerBootom to call it globaly directly from $.footerBootom(); var defaults = target: footer, container: html, innercontainer: body, css: footer: position: absolute, left: 0, bottom: 0, , html: position: relative, minHeight: 100% ; options = $.extend(defaults, options); //JUST SET SOME CSS DEFINED IN THE DEFAULTS SETTINGS ABOVE $(options.target).css( position: options.css.footer.position, left: options.css.footer.left, bottom: options.css.footer.bottom, ); ntainer).css( position: options.css.html.position, min-height: options.css.html.minHeight, ); function logic() var footerOuterHeight = $(options.target).outerHeight(); //get outer footer height nercontainer).css(padding-bottom, footerOuterHeight + px); //set padding equal to footer heigth on body element $(options.target).css(height, footerOuterHeight + !important); //set outerHeight of footer element to … footer console.log(jQ custom plugin footerBottom runs); // disply text in console so ou can check that it works in your browser. Delete it if you like. ; //DEFINE WHEN TO RUN FUNCTION $(window).on(load resize, function() //run on page loaded and on window resized logic(); ); // RETURN OBJECT FOR CHAINING IF NEEDED – IF NOT DELETE // return this.each(function() // this.checked = true; // ); // return this; ; )(jQuery); //end of plugin // USE EXAMPLE $.footerBootom(); //run our plugin with all default settings for HTML5/* Set your footer CSS to what ever you like it will work anyway */ footer box-sizing: border-box; height: auto; width: 100%; padding: 30px 0; background-color: black; color: white; script src= !– structure dont matter much you will always have html and body tag just make sure to point to your footer as neede if you use html5 as it should just do nothing run plugin with no settings it will work by default with footer html5 tag — body div class=content header nav ul lilink/li lilink/li lilink/li lilink/li lilink/li lilink/li /ul /nav /header section p/p pLorem ipsum…/p /section /div footer pCopyright 2009 Your name/p pCopyright 2009 Your name/p pCopyright 2009 Your name/p /footer

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10reputationon this site (theassociation bonus does not count).

Would you like to answer one of theseunanswered questionsinstead?

Humanoid that has a low terminal velocity

Drawing lines within circle using TikZ

Not having to explain my reasons for wanting to keep my last name

The psychology of finishing a piece of fiction

Can travel agents reissue tickets?

If a Chrome Extension is installed but turned off, can it still spy on me?

Is there a RAW limit on the DMs power regarding a Player Characters emotions?

As the DM am I allowed to nerf character stats?

Advantages of Spider Mechs over Tanks?

How to get work done whilst feeling crippling shame?

Does blocking an attack with the Shield spell still trigger Armor of Agathys?

Is there a single word for both atom and ion?

Plot several graphs at the same time and changing options independently

Intuition for Formal Definition of Linear Independence

Why do music directors use keyboard (or similar) instruments for composing music?

How to enable lightning component only for a particular page?

Whats a possible justification for orcs not taking over the world?

How to quickly remove yourself from a homophobic conversation?

Does a blueshift change the energy of a photon?

Career prospects in theoretical physics after nightmare PhD

Can visible light be blocked while still allowing for light for plants to survive to pass through?

Give a permutation with no two consecutive integers next to each other

Emissitivity of copper – Why are copper heatsinks all shiny?

site design / logo 2018 Stack Exchange Inc; user contributions licensed undercc by-sa 3.0withattribution required.rev2018.5.14.30376