Making a footer stick to the bottom with CSS Chris Bongers on December 26, 2020 Ever wanted to have a footer that's stuck to the bottom, but will push down if the content is bigger? To demonstrate I've created this image. W... Read full post Submit Preview Dismiss Collapse Expand Peter Dietrich Peter Dietrich Peter Dietrich Follow Joined Dec 26, 2020 • Dec 26 '20 • Edited on Dec 26 • Edited Dropdown menu Copy link Hide In some cases, I recommend to use height 100% instead of 100vh as vh might cause issues with the chrome nav bar on mobile Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Dec 27 '20 Dropdown menu Copy link Hide Ah good point Peter! Didn't account for that indeed. There is a fix for the 100vh on mobile though. Collapse Expand Peter Dietrich Peter Dietrich Peter Dietrich Follow Joined Dec 26, 2020 • Dec 27 '20 Dropdown menu Copy link Hide Oh - can you elaborate on that fix? Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Dec 28 '20 Dropdown menu Copy link Hide Sure CSS-tricks has a very good article on that: css-tricks.com/css-fix-for-100vh-i... Collapse Expand Ertan Kara Ertan Kara Ertan Kara Follow Breathing code Work Front End web dev, Full Stack to be at Freelancing Joined Feb 22, 2019 • Dec 26 '20 • Edited on Dec 26 • Edited Dropdown menu Copy link Hide This was a thing that I dealt with a few weeks back on my own blog. I fixed it with JS but I was ashamed of the solution. Thanks for this, I will apply this one instead of following. (() => { if (window.innerHeight >= document.body.scrollHeight) { document.querySelector('footer').classList.add('fixed-footer') } })(); Enter fullscreen mode Exit fullscreen mode Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Dec 27 '20 Dropdown menu Copy link Hide Hi Ertan, It's cool you found your own solutions as well, it's what we do as developers. There are always different quicker solutions. Collapse Expand Tobias Nickel Tobias Nickel Tobias Nickel Follow German Software Engineer sharinh thoughts Location MUNICH Germany Work Technical Lead Joined Jul 15, 2018 • Dec 27 '20 Dropdown menu Copy link Hide is there some reason not to use position: fixed anymore? Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Dec 27 '20 Dropdown menu Copy link Hide You can however in this example I didn't want the footer to be always visible, which it would be with fixed. It's a different solution and imagines those big-ass footers these days, don't want that as a fixed block. Collapse Expand Tobias Nickel Tobias Nickel Tobias Nickel Follow German Software Engineer sharinh thoughts Location MUNICH Germany Work Technical Lead Joined Jul 15, 2018 • Dec 27 '20 Dropdown menu Copy link Hide thanks Collapse Expand maxloh maxloh maxloh Follow Location Hong Kong Work Student at OUHK Joined Dec 16, 2019 • Dec 27 '20 Dropdown menu Copy link Hide Margin collapsing won't work on a flexbox based layout. I think I will stick to the old fixed footer way and add a empty div to occupy spaces for the footer. Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Dec 27 '20 Dropdown menu Copy link Hide What exactly do you mean by margin collapsing? in which sense? Collapse Expand Edson Jr. Edson Jr. Edson Jr. Follow Front-end dev and UX enthusiast. Location Brazil Joined Feb 6, 2020 • Dec 27 '20 • Edited on Dec 27 • Edited Dropdown menu Copy link Hide What about the position sticky? Today its browser support is more than 95%. Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Dec 27 '20 Dropdown menu Copy link Hide Sticky is a valid solution same as fixed. Just remember the footer will always be visible, which I didn't want for this example. If that's what you want it's a propper solution though! Collapse Expand Edson Jr. Edson Jr. Edson Jr. Follow Front-end dev and UX enthusiast. Location Brazil Joined Feb 6, 2020 • Dec 27 '20 Dropdown menu Copy link Hide Perfect! Collapse Expand akshay_magrani akshay_magrani akshay_magrani Follow Joined Dec 27, 2020 • Dec 27 '20 Dropdown menu Copy link Hide Thats a good idea Edson Jr.! How will you account for the footer that keeps being visible on the bottom of your screen though? Collapse Expand Andrew Schimelpfening Andrew Schimelpfening Andrew Schimelpfening Follow Location Las Cruces, NM Education B.S. Computer Science, BYU-Idaho Work Full-stack developer @ https://www.ChurchofJesusChrist.org Joined Nov 11, 2020 • Dec 27 '20 Dropdown menu Copy link Hide This is great, thanks for sharing! I’ll try to use this in my next project. Collapse Expand Chris Bongers Chris Bongers Chris Bongers Follow Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊 Location Cape Town, South Africa Work Solution Architect at Daily Dev Tips Joined Apr 20, 2020 • Dec 28 '20 Dropdown menu Copy link Hide Awesome Andrew, if you want to you can share the end-result always cool to see what people use it for 🤟 Collapse Expand Habdul Hazeez Habdul Hazeez Habdul Hazeez Follow I am a writer interested in Web Development, Computer Security, and Artificial Intelligence. Location Nigeria Education B.Sc. Computer Science Work Web Developer and Technical Writer Joined Feb 25, 2019 • Dec 28 '20 Dropdown menu Copy link Hide Related: How to create a sticky Website footer in 5 different ways Habdul Hazeez ・ Jun 30 ・ 6 min read #css #webdev #html #javascript Code of Conduct • Report abuse
In some cases, I recommend to use height 100% instead of 100vh as vh might cause issues with the chrome nav bar on mobile
Ah good point Peter! Didn't account for that indeed.
There is a fix for the 100vh on mobile though.
Oh - can you elaborate on that fix?
Sure CSS-tricks has a very good article on that:
css-tricks.com/css-fix-for-100vh-i...
This was a thing that I dealt with a few weeks back on my own blog. I fixed it with JS but I was ashamed of the solution. Thanks for this, I will apply this one instead of following.
Hi Ertan, It's cool you found your own solutions as well, it's what we do as developers.
There are always different quicker solutions.
is there some reason not to use
position: fixedanymore?You can however in this example I didn't want the footer to be always visible, which it would be with fixed.
It's a different solution and imagines those big-ass footers these days, don't want that as a fixed block.
thanks
Margin collapsing won't work on a flexbox based layout.
I think I will stick to the old fixed footer way and add a empty div to occupy spaces for the footer.
What exactly do you mean by margin collapsing? in which sense?
What about the position sticky? Today its browser support is more than 95%.
Sticky is a valid solution same as fixed.
Just remember the footer will always be visible, which I didn't want for this example.
If that's what you want it's a propper solution though!
Perfect!
Thats a good idea Edson Jr.! How will you account for the footer that keeps being visible on the bottom of your screen though?
This is great, thanks for sharing! I’ll try to use this in my next project.
Awesome Andrew, if you want to you can share the end-result always cool to see what people use it for 🤟
Related:
How to create a sticky Website footer in 5 different ways
Habdul Hazeez ・ Jun 30 ・ 6 min read