Ask any question about Tailwind CSS here... and get an instant response.
Post this Question & Answer:
How can I use Tailwind to implement a sticky header that works across different screen sizes?
Asked on Feb 13, 2026
Answer
To create a sticky header using Tailwind CSS, you can utilize the `sticky` utility along with `top-0` to ensure it stays at the top of the viewport. Tailwind's responsive utilities allow you to adjust the header's styling for different screen sizes.
<!-- BEGIN COPY / PASTE -->
<header class="sticky top-0 bg-white shadow-md p-4">
<h1 class="text-xl font-bold">My Sticky Header</h1>
</header>
<main class="mt-16">
<p class="p-4">Content goes here...</p>
</main>
<!-- END COPY / PASTE -->Additional Comment:
- Use `sticky` to make the header stick to the top of the viewport.
- The `top-0` class ensures the header starts from the top.
- Responsive classes like `p-4` and `text-xl` adjust padding and text size across screen sizes.
- Ensure the main content has a top margin (`mt-16`) to prevent overlap with the sticky header.
Recommended Links:
