DEV Community

Cover image for How to make footer stick at the bottom of web page.

How to make footer stick at the bottom of web page.

Nehal Ahmad on February 28, 2021

Problem If you are new to web development and have created some HTML page before then you may be in a situation where you find that your...
Collapse
 
ganymede profile image
Rudy Reeves • Edited

I think flex-grow: 1; on the main content (the <article>) would achieve a similar result without margin and also allow the main content to fill the empty space

Collapse
 
iamludal profile image
Ludal 🚀

I often use this one, it seems more intuitive than having an automatic margin on the footer 🤔

Collapse
 
chakudi profile image
Vaishali JS

I also used flex-grow to achieve this effect. Knowing about margin technique is new for me.

Collapse
 
naren67 profile image
naren67

grab that footer's class and do this
for example

.footer{
position:absolute;
bottom:0;
}

thats it

Collapse
 
bgrand_ch profile image
Benjamin Grand

Nope, not the same.

With the example of this article, the footer is pushed to the bottom.

With your example, the footer is placed to the bottom, above all elements.

Collapse
 
eduardonwa profile image
Eduardo Cookie Lifter

The footer placed above all elements, isn't that what we're still looking for? I mean it's still at the bottom of the page, unless it's on top of another element then yes, that's not what we want

Thread Thread
 
cpmech profile image
Dorival Pedroso

I suppose the goal is to handle the cases: do we have more content that needs to push the footer down? is the screen big enough so the footer can stay at the bottom? I use grid for this reason. See the example from here css-tricks.com/the-holy-grail-layo... where you can see what happens to the footer when you expand Article.

Collapse
 
naren67 profile image
naren67

.footer{
position:fixed;
bottom:0;
}
a quick update use position fixed instead of absolute

Thread Thread
 
chrisokwakol profile image
Chris Okwakol

footer {
position:relative;
bottom:0;
}

this worked for me.

Collapse
 
chaitanyavsh profile image
Chaitu Maverick

This is the coolest one TBH. :)

Collapse
 
thecerealcoder profile image
Chris

This could work, but I believe you would also need a margin-bottom the exact height of the footer element added to your page content, otherwise you run the risk of having the footer on top of things.

Collapse
 
naren67 profile image
naren67

yes,I mean position fixed would work better instead of position absolute

Collapse
 
dnjosh10 profile image
Dumte Nwidoobee Joshua

This is the one I'm familiar with

Collapse
 
nehalahmadkhan profile image
Nehal Ahmad

Benjamin Grand is right.

Collapse
 
cpmech profile image
Dorival Pedroso

Good one!

I'd also suggest "display: grid".

For example:

    height: 100vh;
    display: grid;
    grid-template-areas:
      'warning'
      'header'
      'main'
      'footer';
    grid-template-columns: auto;
    grid-template-rows: auto auto 1fr auto;
Enter fullscreen mode Exit fullscreen mode

Where you can also get sticky header and more.

See Gist here: gist.github.com/cpmech/241857a5fe7...

Cheers.

Collapse
 
hamanel profile image
Manel

I'm working with react and what worked for me is:

#root {
  min-height: 100vh;
  position: relative;
}

footer {
  position: absolute;
  bottom: 0;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kaysi profile image
Kerrion

Thanks for this. It definitely works with react.

Collapse
 
lewisingleton profile image
Lewis Ingleton

This worked a treat for react

Collapse
 
naren67 profile image
naren67

Dont forget to use the position fixed property to fix that divison at the bottom of the page

Collapse
 
mukhtaaraziz profile image
MukhtaarAziz

Thank you, great article

Collapse
 
lisichaviano profile image
Lisandra

Amazing! Thanks!

Collapse
 
sbouwnsv profile image
Sukhman

thank you for sharing

Collapse
 
akhilalekha profile image
Akhila

This helped me. Thank youu <3

Collapse
 
jrrohrer profile image
Jessie Rohrer

Thanks so much for this! This was the simplest solution I could find and worked perfect for my project :)

Collapse
 
mrfranks profile image
Franky Blondeel

Thanks for this post and also the resulting comments, they have all been very helpful 🙏

Collapse
 
citronbrick profile image
CitronBrick

You can enable syntax highlighting in Dev.to as follows:

triple_backtick language_name
code
triple_backtick