Black Friday: Enjoy a 35% discount on the bundles. Apply the code BLACKFRIDAY35 at checkout! Limited offer.
Today, we are going to create a footer that stays always on the bottom of your page using only Tailwind CSS.
This is a technique where the footer is positioned at the bottom of the page, but it’s not fixed or “sticky” - instead, the main content of the page pushes the footer down to the bottom. This ensures the footer is always visible, but it’s not fixed in place like a traditional sticky footer.
Use cases:
In summary, the “footer pushed by main content” technique provides a simple way to ensure the footer is always visible at the bottom of the page, while allowing the main content to dictate the overall layout and positioning.
This classes, you should add to the wrapper of your content, I would recommend adding it to the body tag for consistency. The key class here is min-h-screen
which sets the minimum height of the element to the height of the viewport. This will push the footer to the bottom of the page.
flex
: This is a utility class that sets the element to be a flex container.flex-col
: This is a utility class that sets the flex-direction property of the element to column.min-h-screen
: This is a utility class that sets the min-height property of the element to the height of the viewport.<body class="flex flex-col min-h-screen">
<!-- Main content goes here -->
</body>
This is the key part of the sticky footer. You should add this class to the main content of your page. This will ensure that the footer is always at the bottom of the page. as you can see in the example below the navigation and footer are outside the main
tag.
grow
: This is a utility class that sets the flex-grow property of the element to 1. ( now is called grow
) on Tailwind CSS. you don’y need to name flex-grow
.<!-- Here goes the navigation -->
<main class="grow ...">
<!-- The whole content goes here -->
</main>
<!-- Here goes the footer -->
After that you can add your content inside the main
tag and the footer will be always at the bottom of the page. You can also add the navigation inside the main
tag, but I would recommend to add it outside the main
tag.
On the tutorial you will see I used a section tag, because thats how is set up on the site, but you have to use a the body
tag.
<body class="flex flex-col min-h-screen">
<main class="max-w-7xl grow px-8 pt-24 mx-auto">
<div>
<div class="max-w-xl mx-auto text-center">
<div class="prose text-neutral-500 prose-sm prose-headings:font-normal prose-headings:text-xl mx-auto max-w-sm w-full">
<h1>Sticky footer</h1>
</div>
</div>
<div class="mt-6 border-t pt-12 max-w-xl mx-auto w-full">
<div class="prose prose-sm 2xl:text-lg text-neutral-500">
<!-- Your content goes here -->
<p> In the throbbing heart of London's vibrant streets, amidst the colorful tapestry of the 1980s, I drew my first breaths at St Thomas’ Hospital Medical School. An intricate blend of European heritage defines my roots - my father's lineage tracing back to the rolling hills of Italy, while my mother embodies the fiery spirit of Spain. </p>
<!-- More content... -->
<p> Thank you for taking the time to acquaint yourself with my story. I am filled with anticipation for the adventures that lie ahead, eagerly anticipating the ongoing evolution of my projects and personal endeavors. May your day be filled with beauty and inspiration. </p>
<p>Michael Andreuzza</p>
</div>
</div>
</div>
</main>
<!-- Footer starts here -->
<footer class="border-t py-6 px-8 w-full mx-auto max-w-xl text-center space-y-4">
<span class="mx-auto text-2xl">✺</span>
<p class="text-neutral-500">I am your Footeer....</p>
</footer>
<!-- Footer ends here -->
</body>
This is a simple sticky footer that demonstrates how to use Tailwind CSS to create a sticky footer with a predefined set of styles.
Hope you enjoyed this tutorial and have a great day!
/Michael Andreuzza
Own all themes forever for $199.
Includes new themes, updates, unlimited projects, and lifetime support. — No subscription required!