Position classes
static, relative, absolute, fixed, sticky
Placement
top-0,right-4,bottom-2,left-1/2inset-0— all four sides at 0 (fill the parent)inset-x-0— left and right at 0- Negative:
-top-2
Z-index
z-0, z-10, z-20, z-50 — higher is on top.
Common patterns
- Badge on an avatar: parent
relative, badgeabsolute -top-1 -right-1 - Image overlay: overlay
absolute inset-0 bg-black/40 - Sticky header:
sticky top-0 z-50 - Floating WhatsApp button:
fixed bottom-6 right-6 - Centre with transform:
absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2
Example
Example — Badge, overlay and floating button
HTML
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<header class="sticky top-0 z-50 bg-white/80 backdrop-blur border-b px-6 py-3 font-semibold">Sticky header</header>
<div class="p-6 space-y-6">
<div class="relative inline-block">
<img src="https://picsum.photos/id/91/80/80" class="size-16 rounded-full" alt="User">
<span class="absolute -top-1 -right-1 bg-rose-600 text-white text-xs size-6 rounded-full flex items-center justify-center">3</span>
</div>
<div class="relative h-48 rounded-xl overflow-hidden">
<img src="https://picsum.photos/id/1036/800/300" class="w-full h-full object-cover" alt="Snow">
<div class="absolute inset-0 bg-black/40 flex items-end p-4">
<h3 class="text-white text-xl font-bold">Image with overlay</h3>
</div>
</div>
<div class="h-96">Scroll down to see the sticky header stay on top.</div>
</div>
<a href="#" class="fixed bottom-6 right-6 bg-green-500 hover:bg-green-600 text-white rounded-full px-5 py-3 shadow-lg">Chat on WhatsApp</a>