Ask any question about Tailwind CSS here... and get an instant response.
Post this Question & Answer:
How can I implement a sticky header using Tailwind CSS?
Asked on Feb 24, 2026
Answer
To create a sticky header using Tailwind CSS, you can use the `sticky` and `top-0` utility classes. This combination will make your header stick to the top of the viewport as you scroll.
<!-- BEGIN COPY / PASTE -->
<header class="sticky top-0 bg-white shadow-md">
<nav class="p-4">
<ul class="flex space-x-4">
<li><a href="#" class="text-blue-500">Home</a></li>
<li><a href="#" class="text-blue-500">About</a></li>
<li><a href="#" class="text-blue-500">Contact</a></li>
</ul>
</nav>
</header>
<!-- END COPY / PASTE -->Additional Comment:
- The `sticky` class makes the element sticky relative to its nearest scrolling ancestor.
- The `top-0` class ensures the header stays at the top of the viewport.
- Use `bg-white` and `shadow-md` for a background color and shadow effect, respectively.
- Ensure the parent container has a defined height to see the sticky effect in action.
Recommended Links:
