Ask any question about Tailwind CSS here... and get an instant response.
How do I create a sticky header using Tailwind classes?
Asked on Oct 30, 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 remains fixed at 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 p-4">
<h1 class="text-xl font-bold">Sticky Header</h1>
</div>
</header>
<!-- END COPY / PASTE -->Additional Comment:
- The "sticky" class makes the element stick to its nearest ancestor with a scrollable container.
- "top-0" ensures the header stays at the top of the viewport.
- Adding "bg-white" and "shadow-md" provides a background color and shadow for better visibility.
- Ensure the parent container has enough height to allow scrolling, or the sticky effect won't be visible.
Recommended Links:
