CSS Generators

Position & Z-Index

All tools

Write a positioned layer rule quickly, and understand why z-index sometimes seems to do nothing.

How it works

Four simple steps

1

Choose a position mode

Select relative, absolute, fixed or sticky.

2

Set a z-index

Type the stacking value for this layer.

3

Adjust offsets

Edit top and left in the copied rule to place the element.

4

Copy the rule

Copy the .layer CSS or download position.css.

Position & Z-Index

About Position & Z-Index

A dropdown keeps opening underneath the sticky header no matter how high you set its z-index. Before raising it to 99999, it helps to get the basics right: which position mode the element uses and which stacking context it lives in. This tool writes the starting rule.

Pick a position mode (relative, absolute, fixed or sticky) and type a z-index. The output is a .layer rule with those two values plus top: 0 and left: 0, which you can adjust. It is a starter snippet rather than a visual layering simulator, so the value of the page is in getting the combination right.

The most common z-index mistake is not the number at all. z-index only competes within the same stacking context, and a parent creates a new one when it has, for example, a transform, opacity below 1, a filter, or position with a z-index of its own. A child with z-index 9999 inside such a parent can still sit below a sibling of that parent with z-index 2. Find the nearest ancestor that creates a context and set the z-index there. Also remember that sticky needs a top (or bottom) value and an ancestor that scrolls, and that a filter or transform on an ancestor changes what fixed elements are positioned against. To center a positioned box's content, the flexbox CSS builder helps, and the CSS snippets collection has a visually hidden utility built on absolute positioning.

Keyboard shortcut

Ctrl Enter - Run tool
FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

It needs a positioned element (anything but static) or a flex or grid item. If it already has one, a parent is probably creating a separate stacking context that limits it.

Sticky needs an offset such as top: 0, and it stops at the edge of its parent. An ancestor with overflow: hidden or auto also changes which container it sticks within.

Absolute is placed relative to the nearest positioned ancestor and scrolls with the page. Fixed is placed relative to the viewport and stays put while scrolling, unless an ancestor has a transform or filter.

View more FAQs

Related tools

View all

Tailwind Class Sorter

Sort Tailwind classes and detect conflicting utilities with a winner explanation.

Open

Design System Diff Lab

Diff design tokens and inspect CSS @layer order and selector specificity locally.

Open

SVG Path Inspector

Parse SVG path commands, preview on canvas, round and minify coordinates.

Open

Flexbox Generator

Build flex layouts visually.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools