DEV Community

Michael Andreuzza
Michael Andreuzza

Posted on

Tailwind CSS Tip: – Keeping the footer at the bottom of your page.

Tailwind CSS Tip

Keeping the footer at the bottom of your page.

When building a website, you might find that if the page content isn't long enough, there's unwanted space beneath the footer. To ensure the footer stays at the bottom, follow this tip.

Image description

This structure uses Tailwind CSS's flexbox utilities to create a full-height (minimum screen height) flexible column layout, where the <main> content grows to fill available space, pushing the <Footer/> to the bottom of the viewport when content is not enough to fill the page.

Tailwind CSS Classes

class="flex flex-col min-h-screen
⏤ These classes are applied to the <body> tag to create a flexible box layout.

flex: This applies a flexible box layout model, allowing you to design a complex layout structure using a more efficient and predictable way than the traditional block model.

⏤ This modifies the flex direction to column, meaning that the children of this element (the navigation, main content, and footer) will be laid out in a vertical column.

⏤ This ensures that the minimum height of the <body> element is at least 100% of the viewport height. If the content is shorter than the viewport height, this rule ensures that the <body> element stretches to fill the entire viewport, preventing the footer from floating up.

⏤ Applied to the <main> element, this class allows the main content area to grow and fill any available space. If there's more space available in the viewport than the content takes up, flex-grow will make the main content area expand to use up that space, effectively pushing the footer to the bottom of the viewport.

Hope you find this helpful!

Top comments (0)