z-index and Stacking Contexts as Figma Layer Order
How CSS z-index and stacking contexts map to Figma layer order: what the Layers panel decides, what creates a context, and why 9999 can still lose.
Introduction
In Figma, z-index is the order of the Layers panel: the top layer is in front, the bottom layer is at the back. In CSS it is an integer, but that integer only competes inside a stacking context, so a bigger number does not always win. This article maps one onto the other so you can read the layer order of an imported page and know why an overlay sits where it does.
It's written for designers who inherit a page as layers and developers who hand one over. Every fact comes from MDN or Figma's own help pages, as of November 2026.
Figma's version: the top of the Layers panel is the front
Figma has no z-index field. Figma's help says you adjust the depth (Z axis) of a layer by changing its order in the Layers panel, and that a layer's depth corresponds to an object's z-index. The top layer is at the front and the bottom layer is at the back.
You change the order three ways:
- Drag the layer up in the Layers panel to bring it forward, or down to send it back.
- Right-click and choose Bring forward, Bring to front, Send backward, or Send to back.
- Use the matching keyboard shortcuts for the same four actions.
Outside an auto layout frame, changing the layer order does not move the layer on the X or Y axis. It only changes what covers what. That's the closest Figma gets to a CSS integer: a place in a list, not a number you pick.
Which elements z-index applies to
On the CSS side, MDN's z-index reference says the property applies to positioned elements (any position other than static) and to flex and grid items. Overlapping elements with a larger z-index cover those with a smaller one.
Two values matter:
autois the initial value. The box does not create a new stacking context, and its level in the current context is 0.- An
<integer>sets the box's level in the current context and also makes the box create a local stacking context. Negative integers place the element behind the normal content of its context.
If two elements share the same level, they stack in DOM order and the later one paints on top. That's why a page often works with no integers at all. If you want the property-by-property view of position, see CSS position in Figma.
Paint order with no z-index at all
When no element sets z-index, MDN's stacking without z-index page gives the order from bottom to top:
- The background and borders of the root element.
- Descendant non-positioned elements, in order of appearance in the HTML.
- Descendant positioned elements, in order of appearance in the HTML.
So a static element is drawn below a positioned one even if it comes later in the markup. MDN also notes that when the flex order property changes the rendered order, it changes the stacking order the same way. "Order of appearance" means the rendered order, not the source order.
For a designer, this is why a tooltip that is position: absolute covers a card that comes after it in the HTML. Nobody wrote a number. The position value did the work.
What creates a stacking context
This is where the trouble starts. MDN's stacking context page lists what creates one. The common ones:
| Trigger | Creates a context when |
|---|---|
| Root element | always |
position: absolute or relative | z-index is not auto |
position: fixed or sticky | always |
| Flex or grid item | z-index is not auto |
opacity | less than 1 |
mix-blend-mode | not normal |
transform, filter, backdrop-filter, clip-path, mask | not none |
isolation | isolate |
contain | layout or paint |
The list also includes container-type set to size or inline-size, will-change naming a property that would create a context, and elements in the top layer. The practical point: you can create a stacking context without ever writing a z-index. A card with opacity: 0.9 or a transform on hover is already one.
Two earlier articles cover the properties behind several of these rows: opacity, blend modes, and filters and CSS transforms in Figma terms.
Stacking contexts are atomic: why 9999 loses
MDN puts it this way: each stacking context is self-contained, and after an element's contents are stacked, the whole element is treated as a single unit in the stacking order of its parent. The z-index values of child contexts only have meaning inside the parent's context.
MDN's worked example makes it concrete. Three articles have z-index 5, 2 and 4, and the third contains sections with 6, 1 and 3. Each container has opacity: 0.85, so each one is a context. The section with z-index 6 renders under the article with z-index 5, because it belongs to the article with z-index 4. MDN writes the levels as version numbers: 4-6 is lower than 5-0.
/* The section's 6 only counts inside #container3 (z-index: 4) */
#container1 { z-index: 5; }
#container3 { z-index: 4; }
#container4 { z-index: 6; } /* child of #container3, still under #container1 */
So a modal with z-index: 9999 loses to a header with z-index: 10 if the modal lives inside a parent whose context sits lower. Raising the number won't help. Move the modal out, or change the parent.
In Figma you see the same thing as nesting. Children sit under their parent frame or group in the Layers panel, and the parent's place in the list is where the whole group lands. This article does not claim that Figma frames behave as isolated groups in every case, because Figma's help pages do not spell that out. Treat nesting as a hint and check the canvas.
Auto layout: order moves things, overlap needs a flag
Figma's help says layer order works the opposite way inside an auto layout frame. Changing the order changes the position of the layer within the frame, because the order is the flow. In a vertical flow, objects you add, remove or reorder follow the y-axis; in a horizontal flow, the x-axis.
To overlap something inside an auto layout frame you turn on Ignore auto layout. Figma's auto layout guide says it was formerly called absolute position, and that like absolute position in CSS the object can be placed precisely relative to its parent while staying in the frame. That is the Figma twin of a positioned child in a flex container, and it is where overlays, badges and floating buttons live.
What to check after an import
UnHTML turns a page into editable layers, not a pixel-exact clone, and its import report lists what fell back. Layer order is worth checking by hand:
- Select every overlay: sticky header, modal, dropdown, toast, badge. Confirm each sits above the content it covers in the Layers panel.
- Look for a layer that is "above" in CSS terms but ended up lower in the list. A parent context, such as an
opacityortransformon an ancestor, is the usual cause. - In auto layout frames, check whether an overlapping child is marked Ignore auto layout. If it is not, reordering will move it instead of restacking it.
Conclusion
Figma gives you one ordered list per parent, where the top is the front. CSS gives you integers, DOM order and nested contexts, and a context is decided by many properties besides z-index. When a CSS stack and a Figma stack disagree, find the ancestor that created the context first, then compare the order of its siblings.
Frequently Asked Questions
Is Figma layer order the same as CSS z-index?
Figma's own help says a layer's depth corresponds to an object's z-index, and that the top layer in the Layers panel is in front. The mapping is by order, not by number: Figma has no z-index field, so any conversion has to turn CSS integers into a sibling order.
Why does my element with a huge z-index stay behind another one?
Usually because a parent creates a stacking context. The z-index of a child only competes inside its parent's context, and the parent counts as one unit in the next one up. MDN's example has a child at z-index 6 painting under an element at 5 for exactly this reason.
Does opacity change stacking in CSS?
Yes. An opacity below 1 creates a stacking context, as do transform, filter and isolation: isolate, even when no z-index is set.
What should I check about z-index after importing a page into Figma?
Treat the Layers panel order as the result of the page's paint order. Check overlapping elements such as sticky headers, modals and dropdowns, and read the import report for anything that fell back.
Questions
- Is Figma layer order the same as CSS z-index?
- Figma's own help says a layer's depth corresponds to an object's z-index, and that the top layer in the Layers panel is in front. The mapping is by order, not by number: Figma has no z-index field, so any conversion has to turn CSS integers into a sibling order.
- Why does my element with a huge z-index stay behind another one?
- Usually because a parent creates a stacking context. The z-index of a child only competes inside its parent's context, and the parent counts as one unit in the next one up. MDN's example has a child at z-index 6 painting under an element at 5 for exactly this reason.
- Does opacity change stacking in CSS?
- Yes. An opacity below 1 creates a stacking context, as do transform, filter and isolation: isolate, even when no z-index is set.
- What should I check about z-index after importing a page into Figma?
- Treat the Layers panel order as the result of the page's paint order. Check overlapping elements such as sticky headers, modals and dropdowns, and read the import report for anything that fell back.