agyanadda@gmail.com

Tailwind Position and Z-Index

Tailwind Layout 1 min read Updated Dec 1, 2026 Topic 13 of 27

Position classes

static, relative, absolute, fixed, sticky

Placement

  • top-0, right-4, bottom-2, left-1/2
  • inset-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, badge absolute -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>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which class makes an absolute element cover its whole parent?

Exercise 2 True / False

A fixed element stays in the same place on screen while scrolling.

Exercise 3 Fill in the Blank

The parent of an absolute badge usually needs the class ___.

Frequently Asked Questions

Give it a z-index such as z-50 and a background colour, and check no parent has overflow-hidden.