Skip to content

Z-index

Z-index utilities change the stacking order of positioned elements: z-n1 sends an element behind its context, z-0 creates a base layer and z-1, z-2 and z-3 bring elements forward. They only apply to elements with a position, so pair them with position-relative or position-absolute.

1Z-index scale

z-n1, z-0, z-1, z-2 and z-3 stack positioned elements from back to front.

z-3
z-2
z-1
z-0
z-n1

2Order without z-index

Without z-index, later elements paint on top of earlier ones.

first
second (on top)

3Bring the first one forward

z-1 on the first element puts it above its later sibling.

first, z-1
second

4Background shape behind content

z-n1 places a decorative shape behind the text of its positioned parent, which uses z-0 to form a stacking context.

Giving that you can see

Leave a gift in your will and help future generations.

5Overlapping avatars

Decreasing z-index keeps the first avatar on top of the stack.

Elena Larsen Arjun Mensah Samir Harlow Nora Kim

6Active button above its neighbours

In joined button rows the active one gets z-1 so its border is not hidden.

7Badge over a card image

The badge uses z-2 so it stays above an overlay with z-1.

Stories from the families we support
how-to

8Floating label above a chart

A z-3 label stays above grid lines and bars.

Peak 889

9Sticky header layer

A sticky header with z-2 stays above rows that have their own positioned badges.

Team
Aria Silva new
Mason Rossi
Luna Hughes
Chloe Haddad
Lucas Novak

10Cards in a fan

Rotated cards stacked with z-1 to z-3.

z-1
z-2
z-3

11Image behind a heading

The hero image sits on z-n1 inside a z-0 context, the text sits on top.

Change one life, change a community

We have helped more than two hundred thousand people since we started.

12Focus ring over siblings

List group items lift their active item with z-1 so its border shows on both edges.

  • Environment
  • Relief
  • Animals

13Notification over a header

A count badge on z-3 overlaps the next header item.

72

14Stacked paper effect

Two layers on z-n1 behind a card look like a pile of pages.

Environment
40 documents

15Overlapping sections

A card with z-1 overlaps the coloured band above it via a negative top offset.

Real help, where it is needed most

We keep things simple, so you can focus on what matters to you.

16Corner ribbon above a border

A z-2 ribbon overlaps the card border.

Approved
Food relief
Our team has done this many times, so you never have to guess.

17Hover card layer (static preview)

A preview popover on z-3 overlapping a list.

  • Ruby Brennan
  • Omar Nguyen
  • Ravi Lindqvist
We measure success by how many donors come back and tell their friends.

18Z-index needs a position

z-* only works on positioned elements: the left box has no position, the right one has position-relative.

z-3, static (ignored)
z-3, position-relative

19Price tag over a product

A z-1 price tag over the product image and a z-2 heart button above it.

Solar lamp $71.17

20Dropdown above content

An open menu at z-3 overlaps the panel below it.

  • Newest
  • Price low to high
  • Rating
Every donation is tax-deductible, and receipts arrive by email instantly. Monthly gifts let us plan ahead and respond quickly when disaster strikes.