Lexington has been awarded a grant from Astro, to celebrate. Get a 30% discount. Apply code LEXINGTON30 at checkout.
Discover how to ensure your website’s footer stays exactly where it should be, at the bottom, with Tailwind CSS techniques and additional strategies for impeccable web design.
Every web developer has faced the challenge of ensuring the footer remains at the bottom of the webpage, regardless of the content’s length. This seemingly small detail can significantly impact the overall aesthetics and user experience of a website. Tailwind CSS, a utility-first CSS framework, offers an elegant solution to this common issue. This blog post expands on a tip I shared on Twitter about using Tailwind CSS to keep the footer in its place, diving deeper into additional methods and best practices for footer placement.
The footer of a website is not just a space for copyright information or a sitemap; it plays a crucial role in website navigation and user experience. A footer that awkwardly floats in the middle of the page or, conversely, one that is too intrusive can detract from the overall design and functionality of the site. Ensuring the footer stays at the bottom of the page where users expect to find it is key to maintaining a clean and effective web design.
The method shared on Twitter utilizes Tailwind CSS’s flexbox utilities to maintain the footer’s position at the bottom of the page, even when the content is sparse. Here’s how you can implement this technique:
Apply Flexbox Utilities to the Body Tag: Start by adding class="flex flex-col min-h-svh"
to the <body>
tag. This ensures that the body of your website behaves as a flex container, arranging its children in a vertical column and stretching to fill the viewport height.
Expanding the Main Content: Next, assign class="grow"
to the <main>
element. This allows the main content area to expand and occupy any available space, pushing the footer to the bottom of the viewport.
By following these steps, you create a layout where the footer gracefully sits at the bottom of the page, regardless of the content length.
<body class="flex flex-col min-h-svh">
<!-- Header (optional) -->
<header>Header content here</header>
<!-- Main Content -->
<main class="grow">
Main content goes here...
</main>
<!-- Footer -->
<footer>
Footer content here...
</footer>
</body>
Another approach is to make the footer sticky. This method ensures that the footer remains at the bottom of the viewport but below the content when the page’s content exceeds the viewport height. Here’s a quick guide:
Footer Setup: Assign class="sticky bottom-0"
to your footer. This makes the footer stick to the bottom of the viewport when scrolling.
Body and Main Content Setup: Ensure the body and main content have the correct Tailwind CSS classes to support this behavior without overlapping content.
This method is particularly useful for pages with varying content lengths, ensuring the footer is always in the right position.
<body class="flex flex-col min-h-svh">
<div class="grow">
<!-- Header (optional) -->
<header>Header content here</header>
<!-- Main Content -->
<main>
Main content goes here...
</main>
</div>
<!-- Sticky Footer -->
<footer class="sticky bottom-0">
Footer content here...
</footer>
</body>
Before Tailwind CSS and other modern CSS frameworks, developers used traditional CSS to tackle the footer placement issue. Techniques such as the “CSS Sticky Footer” involved more complex calculations and CSS properties. While effective, these methods often required more code and fine-tuning compared to the streamlined approach offered by Tailwind CSS.
Designing an effective footer involves more than just keeping it at the bottom of the page. Here are a few tips:
Ensuring your footer stays at the bottom of the page is crucial for a professional-looking website. Tailwind CSS offers practical and efficient solutions to achieve this, whether through flexbox utilities or sticky positioning. By following the methods and best practices outlined in this post, you can enhance your website’s design and user experience.
/Michael Andreuzza
Get access to all themes
Unlock all themes for $199 for forever! Includes lifetime updates,
new themes, unlimited projects, and support
— No subscription
needed.