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 transitions smoothly on scroll?
Asked on Apr 04, 2026
Answer
In Tailwind CSS, creating a sticky header involves using utility classes to fix the header at the top of the viewport and applying transition utilities for smooth effects. Here's a simple example to demonstrate this.
<!-- BEGIN COPY / PASTE -->
<header class="sticky top-0 bg-white shadow-md transition-shadow duration-300">
<nav class="flex justify-between items-center p-4">
<div class="text-lg font-bold">Logo</div>
<ul class="flex space-x-4">
<li><a href="#" class="hover:text-blue-500">Home</a></li>
<li><a href="#" class="hover:text-blue-500">About</a></li>
<li><a href="#" class="hover:text-blue-500">Contact</a></li>
</ul>
</nav>
</header>
<!-- END COPY / PASTE -->Additional Comment:
- The "sticky" class combined with "top-0" ensures the header sticks to the top of the viewport.
- "bg-white" and "shadow-md" provide a background color and shadow effect, respectively.
- Use "transition-shadow" and "duration-300" for smooth transition effects when the shadow changes on scroll.
- Ensure your content has enough space to scroll for the sticky effect to be noticeable.
Recommended Links:
