Ask any question about Tailwind CSS here... and get an instant response.
How can I implement a sticky header with Tailwind?
Asked on Nov 15, 2025
Answer
To create a sticky header using Tailwind CSS, you can utilize the `sticky` utility class along with `top-0` to ensure the header sticks to the top of the viewport as you scroll.
<!-- BEGIN COPY / PASTE -->
<header class="sticky top-0 bg-white shadow-md">
<div class="max-w-7xl mx-auto px-4 py-2">
<h1 class="text-xl font-bold">My Sticky Header</h1>
</div>
</header>
<!-- END COPY / PASTE -->Additional Comment:
- The `sticky` class makes the element stick to its nearest ancestor with a scrolling mechanism.
- `top-0` ensures the header remains at the top of the viewport.
- Use `bg-white` and `shadow-md` for a clean look and subtle shadow.
- Adjust padding and margin with `px-4` and `py-2` for spacing.
Recommended Links:
