Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a sticky footer that remains at the bottom of the viewport in CSS?
Asked on Apr 05, 2026
Answer
To create a sticky footer that remains at the bottom of the viewport, you can use CSS Flexbox to structure your layout. This method ensures that the footer stays at the bottom even when the content is short.
<!-- BEGIN COPY / PASTE -->
<style>
html, body {
height: 100%;
margin: 0;
}
.container {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.content {
flex: 1;
}
.footer {
background-color: #f1f1f1;
padding: 10px;
text-align: center;
}
</style>
<div class="container">
<div class="content">
<!-- Main content goes here -->
</div>
<div class="footer">
<!-- Footer content -->
Sticky Footer
</div>
</div>
<!-- END COPY / PASTE -->Additional Comment:
- Set the
htmlandbodyelements to 100% height to ensure the container can fill the viewport. - Use
flex-direction: columnon the container to stack the content and footer vertically. - The
flex: 1property on the content area allows it to grow and fill the available space, pushing the footer to the bottom. - This approach works well for most layouts and is responsive by default.
Recommended Links:
