Webmaster resources

Follow us on Twitter!

Hosting status updates - Click here


Free Tutorials » CSS & HTML » Effective Footers

Code a footer which sticks to the bottom of the page except when content pushes it down.

Step 1

Having the right footer is important in a website, it can be a large part of the look of the page. In this tutorial we will be covering how to make a fixed-height footer, which sticks to the bottom of the page except when content pushes it down using purely HTML and CSS. You can see an example of this here. This is not entirely trivial because position: absolute; or fixed; would not move down when the page was filled with content, and merely placing it at the bottom of the markup would not ensure it was at the bottom of the page when there was not much content. The solution to the problem is that we make everything but the footer altogether have a minimum height of 100%, then we use a negative top margin on the footer equal to its total height to bring it up, placing the bottom of the footer at the bottom of the page when the content doesn't have a height larger than 100%, perfect! The HTML required for this is fairly simple, something like this will suffice:

   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <title>Footer Example</title>
   <!-- Container Divs -->
   <div id="container"><div id="padding">
      <!-- Header -->
      <!-- Content -->
      <h2>Example Content</h2>
         Some content...
   <!-- Footer -->
   <p id="footer">
      Page Footer

You can view what this code (with some basic styling to make things clearer) look like here.

Step 2

Now we can start styling the document to get the footer how we want it. First of all, we need to make the container div have a min-height of 100%, this can be achieved in most browsers with the following CSS:

html, body
   height: 100%;
   margin: 0;
   padding: 0;
   min-height: 100%;

Both html and body need to be set to 100% height so that the container div can take up the space. This does the job in a lot of browsers, but unfortunately IE doesn't understand min-height, for some reason IE's height is equivalent to min-height and min-height does not exist, so to combat this we need to set height: 100%; in IE without affecting compliant browsers. We can achieve this using !important in the CSS like so:

   height: auto !important;
   height: 100%;
   min-height: 100%;

The !important makes compliant browsers use height: auto; instead of height: 100%; while IE uses height: 100%; instead, fixing it nicely. Our layout now looks like this, almost done!

Step 3

Now that our main content area is formatted correctly we can turn our attention to the footer. At the moment it is just below the main content, so we need to apply our negative top margin to pull it up into the correct position. To do this, first we need to calculate its total height, in this case we have made the footer 17px in height, with an additional 9px padding at the top, and another 9px at the bottom. Therefore, the total height of the footer is 17+9+9 = 35px. So we need to move the footer 35 pixels up, which is done with this line:

   margin: -35px 0 0 0;
   /* ... other styles ... */

This makes the top margin negative 35 and sets left, right and bottom to 0. Now, this is now perfect when there is little content, but when more is introduced to the page we see a problem emerge, the content overflows onto the footer which is hardly something we want. We fix this using the "padding" div that was introduced in the HTML at the beginning, we can't use padding on the container div, because that would make the height of the container div 100%+padding, and would push the footer below the bottom of the page again, so instead we have to pad another container inside the first, in this case the "padding" div. The fix is very simple, and is simply this:

div#padding { padding: 0 0 45px 0; }

Once this is in place, content no longer overflows onto the footer when there's a lot of it, and when there is little the page is unaffected.

Step 4

That's pretty much that on making footers like this, it's a useful tool and widely compatible, this method has been tested on:

  • IE 5
  • IE 5.5
  • IE 6
  • IE 7
  • Firefox 2
  • Opera 9
  • Konqueror 3.5.7
  • Safari 2.0.4
NOTE: IE5 and 5.5 don't play well with the dynamic example at the top of the page, but are fine with static pages.

Tutorial comments

13.06.2015 -

wlp says …

burberry outlet, http://www.burberry-outlet.jp.net/
burberry outlet online, http://www.burberryoutlet.org.uk/
burbery outlet store, http://www.burberryoutlet-online.co.com/
burberry outlet, http://www.burberryoutlet-online.in.net/
calvin kleins outlet, http://www.calvinklein.co.com/
celine bags, http://www.celinebags.org/
chanel bags, http://www.chanelhandbags.net.co/
softball bats, http://www.cheapbaseballbats.net/
christian louboutin outlet, http://www.christianlouboutinshoes.ar.com/
air huarache, http://www.air-huarache.co.uk/
air jordans, http://www.airjordans.us/
air jordan 2015, http://www.airjordanshoes2015.com/
air max 2015, http://www.airmax-2015.org/
nike air max, http://www.airmax-90.org/
babyliss, http://www.babyliss-pro.net/
cheap basketball shoes, http://www.basketballshoes.com.co/
monster beats, http://www.beatsbydrdre.co.com/
dre beats, http://www.beatsbydre.com.co/
beats by dre outlet, http://www.beats-by-dre.com.co/
beats by dre, http://www.beatsheadphones.in.net/
bottega veneta, http://www.bottega.us/
burberry, http://www.burberryhandbags.net.co/
baseball jerseys, http://www.cheapjerseys.in.net/
air jordan shoes, http://www.cheap-jordans.net/
michael kors handbags clearance, http://www.cheapmichaelkors.us.org/
nike outlet, http://www.cheap-nikeshoes.com/
oakley sunglasses cheap, http://www.cheapoakley.us.org/
oakley outlet, http://www.cheapoakleysunglasses.ar.com/
oakley sunglasses, http://www.cheap-oakleysunglasses.in.net/
ray bans, http://www.cheaprayban.com.co/
shoes outlet, http://www.cheapshoes.com.co/
ugg boots, http://www.cheapuggboots.eu.com/
flat iron, http://www.chiflatiron.net.co/
christian louboutin shoes, http://www.christian--louboutin.in.net/
louboutin, http://www.christianlouboutin.org.uk/
christian louboutin outlet, http://www.christianlouboutinshoes.jp.net/
burberry, http://burberry.outletnow.net/
christian louboutin shoes, http://christian.louboutin-outlet.net/
tory burch sale, http://toryburch.salesandals.net/
abercrombie kids, http://www.abercrombieand-fitch.com.co/
abercrombie, http://www.abercrombiefitch.us.com/
abercrombie and fitch, http://www.abercrombie-kids.us.com/
coachoutlet.com, http://www.coachfactory-outlet.co.com/
coach factory outlet, http://www.coachfactoryoutletonline.co.com/
coach outlet online usa, http://www.coach-handbags.com.co/
coach outlet online, http://www.coachoutlet-online.com.co/
coach store outlet online, http://www.coachoutletstore.net.co/
coach outlet online, http://www.coachoutletstore-online.com.co/
chanel handbags, http://www.coco-chanelbags.com.co/
converse outlet, http://www.converse.net.co/
michael kors handbags, http://www.designerhandbagsoutlet.com.co/
glasses online, http://www.eyeglassesonline.us.com/
glasses frames, http://www.eyeglassframes.us.com/
juicy couture clothes , http://www.fashion-clothing.us.com/
ferragamo outlet, http://www.ferragamo.com.co/
ferragamo, http://www.ferragamoshoes.net/
straightener, http://www.ghdhairstraightener.com.co/
jimmy choo outlet, http://www.jimmychoo.net.co/
retro jordans, http://www.jordanretro.org/
cheap jordans, http://www.jordan-shoes.com.co/
juicy couture, http://www.juicycouture.com.co/
juicy couture outlet, http://www.juicycoutureoutlet.net.co/
louis vuitton outlet online, http://www.louisvuitton-outlet.com.co/
louis vuitton outlet, http://www.louisvuitton-outlets.us/
marc jacobs handbags, http://www.marcjacobsonsale.com/
mcm handbags, http://www.mcm-bags.net/
mcm world wide, http://www.mcmhandbags.com.co/
michael kors outlet online, http://www.michaelkors.so/
michael kors purses, http://www.michael--kors.us.com/
michael kors outlet, http://www.michaelkorsbags.us.org/
michael kors handbags, http://www.michaelkorshandbags.org.uk/
michael kors handbags clearance, http://www.michael-kors-handbags.us.com/
michael kors clearance, http://www.michaelkorsoutlet.ar.com/
michael kors outlet online sale, http://www.michael-kors-outlet.us.org/
michael kors outlet online sale, http://www.michaelkorsoutlet-online.ar.com/
michael kors, http://www.michael-kors-outlet-online.us.org/
michael kors outlet online sale, http://www.michaelkorsoutletonline-sale.us.com/
michael kors, http://www.michaelkors-uk.org.uk/
mont blanc, http://www.montblanc--pens.net/
new balance shoes, http://www.newbalance-outlet.org/
nike air max 2014, http://www.nike-air-max.us/
nike factory outlet, http://www.nikefactory.org/
nike free 5.0, http://www.nikefree5.net/
free run, http://www.nikefree-run.net/
free running, http://www.nikefree-run.org.uk/
nike jordan shoes, http://www.jordanrelease-dates.com/
soccer shoes, http://www.nikemercurial.net/
nike roshe run, http://www.nikerosherun.us/
nike store, http://www.nikestore.us/
north face outlet, http://www.northface.us.org/
the north face jackets, http://www.northfaceoutlet.com.co/
oakley vault, http://www.oakleyoutlet.us.org/
oakley outlet, http://www.oakley-sunglasses.us.org/
cheap oakley sunglasses, http://www.oakleysunglassescheap.in.net/
oakley sunglasses outlet, http://www.oakleysunglassesoutlet.com.co/
rolex watches, http://www.omegawatches.us.com/
pandora uk, http://www.pandora-charms.org.uk/
pandora charms, http://www.pandorajewelry.com.co/
polo ralph lauren outlet online, http://www.polo-outlets.com/
prada handbags, http://www.pradahandbags.net.co/
prada outlet, http://www.pradahandbags.com.co/
prada shoes for men, http://www.pradashoes.com.co/
polo ralph lauren outlet, http://www.ralph-lauren.org.uk/
ralph lauren outlet, http://www.ralphlaurenoutlet.us.com/
ralph lauren uk, http://www.ralphlauren-outlet.org.uk/
ralph lauren polos, http://www.ralphlaurenoutletonline.com.co/
ralph lauren outlet online, http://www.ralphlaurenoutletonline.in.net/
gucci shoes uk, http://www.gucci.me.uk/
gucci belts, http://www.guccihandbags.com.co/
gucci bags, http://www.gucci-outlet.in.net/
gucci handbags, http://www.gucci--outlet.com.co/
gucci shoes outlet, http://www.guccishoes.net.co/
gucci outlet, http://www.guccishoes.us.org/
hermes belt, http://www.hermesbags.com.co/
hermes belt, http://www.hermesbirkin.com.co/
hermes, http://www.hermesoutlet.net.co/
hollister clothing store, http://www.hollister.us.org/
hollister clothing store, http://www.hollisterclothing-store.in.net/
insanity calendar, http://www.insanityworkout.net.co/
ipad cases, http://www.iphone-cases.us/
ralph lauren outlet, http://www.ralphlaurenpolo.in.net/
ray-ban, http://www.ray-ban-outlet.us.com/
ray ban outlet, http://www.raybans.us.org/
ray ban, http://www.rayban-sunglasses.org.uk/
ray ban sunglasses outlet, http://www.rayban-sunglasses.us.org/
ray ban sunglasses, http://www.raybansunglassesoutlet.net.co/
cheap ray ban, http://www.raybanwayfarer.in.net/
knockoff handbags, http://www.replicahandbags.com.co/
omega watches, http://www.replicawatches.us.com/
jordan release dates, http://www.retro-jordans.com/
replica watches, http://www.rolex-watches.me.uk/
roshe run, http://www.rosherun.org.uk/
roshe runs, http://www.rosheruns.us/
ferragamo shoes, http://www.salvatoreferragamo.in.net/
nike mercurial, http://www.soccer-shoes.org/
softball bats, http://www.softball-bats.us/
supra footwear, http://www.suprashoe.net/
swarovski outlet, http://www.swarovskicrystal.com.co/
swarovski crystal, http://www.swarovskijewelry.com.co/
swarovski uk, http://www.swarovski-uk.org.uk/
north face, http://www.the-northface.com.co/
the north face outlet online, http://www.the-northface.in.net/
the north face, http://www.thenorth-face.org.uk/
the north face outlet, http://www.thenorthface.us.org/
north face jackets, http://www.thenorthfacejackets.in.net/
thomas sabo uk, http://www.thomassabo-uk.org.uk/
tiffany and co outlet, http://www.tiffanyandco.net.co/
tiffany's jewelry, http://www.tiffanyjewelry.us.org/
tory burch sale, http://www.tory-burch-outlet.in.net/
tory burch sale, http://www.tory-burchoutlet.us.com/
louboutin shoes, http://www.louboutin.jp.net/
louis vuitton, http://www.louis-vuittoncanada.ca/
louis vuitton, http://www.louisvuitton.jp.net/
louis vuitton bags, http://www.louis--vuitton.org.uk/
louis vuitton handbags, http://www.louisvuitton.so/
louis vuitton, http://www.louisvuittonas.com/
ed hardy clothing, http://www.edhardy.in.net/
levis jeans, http://www.levisjeans.com.co/
bcbg max azria, http://www.bcbgdresses.net/
bebe clothing, http://www.bebeclothing.net/
harrods london, http://www.harrods-london.co.uk/
gucci handbags, http://www.guccishoes.com.co/
ralph lauren outlet, http://www.ralphlaurenoutletonline.us.org/
cheap true religion, http://www.true-religion.com.co/
true religion jeans women, http://www.truereligionjeans.net.co/
true religion jeans, http://www.truereligion-outlet.com.co/
uggs, http://www.uggaustralia.net.co/
ugg boots clearance, http://www.uggboots.net.co/
uggs on sale, http://www.uggbootsclearance.com.co/
ugg boots, http://www.uggsonsale.com.co/
ugg outlet, http://www.uggsoutlet.com.co/
coach outlet store, http://www.uptocoachoutlet.com/
vans outlet, http://www.vansshoes.us/
wedding dress, http://www.weddingdressesuk.org.uk/
lululemon, http://www.yogapants.com.co/
ugg boots, http://www.ugg-boots.us.org/
polo ralph lauren, http://www.poloralphlaurenoutlet.net.co/
burberry outlet, http://www.burberryoutletonline.ar.com/
toms shoes outlet, http://www.toms-outlet.net.co/
michael kors, http://www.michaelkors.in.net/
louboutin outlet, http://www.christianlouboutinoutlet.net.co/
tory burch outlet, http://www.toryburchsale.com.co/
prada sunglasses, http://www.pradaoutlet.com.co/
longchamp outlet, http://www.longchamp-handbags.in.net/
longchamp handbags, http://www.longchampoutlet.com.co/
chanel handbags, http://www.chanel-bags.com.co/
true religion jeans, http://www.truereligion-outlet.us.org/
abercrombie and fitch, http://www.abercrombie-and-fitch.us.com/
timberland boots, http://www.timberlandboots-outlet.net/
timberland shoes, http://www.timberland-shoes.com/
tommy hilfiger kids, http://www.tommyhilfiger.net.co/
tommy hilfiger outlet, http://www.tommy-hilfigeroutlet.com/
toms outlet, http://www.tomshoesoutlet.com/
toms shoes, http://www.toms-outlet.in.net/
toms outlet, http://www.toms-shoes.com.co/
hollister clothing store, http://www.hollisterclothing.in.net/
new balance, http://www.newbalance-shoes.org/
converse, http://www.converse--shoes.net/
lulu lemon, http://www.lululemonoutlet.com.co/
baseball jerseys, http://www.nfl-jerseys.in.net/
nfl jerseys, http://www.cheapjerseys.us.org/
replica watches, http://www.rolex-watches.us.com/
rolex watches, http://www.rolexwatchesforsale.us.com/
p90x workout, http://www.p90xworkout.in.net/
giuseppe zanotti, http://www.giuseppezanotti.com.co/
m a c cosmetics, http://www.maccosmetics.net.co/
instyler, http://www.instyler.in.net/
mizuno, http://www.mizunorunning.net/
purses and handbags, http://www.handbagsoutlet.com.co/
hilfiger outlet, http://www.hilfigeroutlet.in.net/
katespade, http://www.kate-spade.com.co/
kate spade outlet online, http://www.katespade-outlet.com.co/
kate spade outlet, http://www.kate-spades.com/
longchamp handbags, http://www.longchamp.us.org/
longchamp outlet, http://www.longchamp.com.co/

29.05.2015 -

vanessahill70 says …

Very nice for a beginning web designer.

Life Experience Degrees - http://www.uniofdenton.com/

High School Diploma - http://www.wilsonhighschool.net/

30.04.2015 -

harrybarkman007 says …

There is something to tell you that nice content have variety of attracting more users as compared to others. You would also be glad to know that there are too many research papers written for you online for free, you can go and just click to download your desired topic. It will help you to enhance your knowledge and built a strong relationship between you and your users. Do My Assignment | Assignment Writing Service

17.11.2014 -

bryanparker45 says …

Education tells us the culture of the area. What is the culture in our society, which we should have to maintain our culture and civilization? We should aware about our history which we have reorganization of our culture and civilization with the help of education.


17.11.2014 -

bryanparker45 says …

Superb one! I have never read such a nice article; topic and the comments are good. I have learned many things from all your post and this one was the best post for me. I really enjoyed reading it and craving more tips from you… thank you for such an engaging article.


View all user comments for this tutorial.

Tutorial statistics

Date added:
Alex Elliott
User rating:
Rate tutorial:
Total views:
Total comments: