Ask any question about Tailwind CSS here... and get an instant response.
Post this Question & Answer:
How can I use Tailwind CSS to implement a sticky header that stays fixed during scroll?
Asked on Feb 23, 2026
Answer
To create a sticky header using Tailwind CSS, you can utilize the "sticky" and "top-0" utilities to keep the header fixed at the top of the viewport while scrolling.
<!-- BEGIN COPY / PASTE -->
<header class="sticky top-0 bg-white shadow-md">
<nav class="container mx-auto p-4">
<h1 class="text-xl font-bold">Sticky Header</h1>
</nav>
</header>
<main class="mt-16">
<p>... your page content ...</p>
</main>
<!-- END COPY / PASTE -->Additional Comment:
- The "sticky" class makes the element stick to the top of its container when scrolling.
- "top-0" positions the element at the top of the viewport.
- Ensure the header has a background color (e.g., "bg-white") to cover content behind it.
- Use "shadow-md" or similar for visual separation from content below.
Recommended Links:
