# CSS z-index has no effect on a non-positioned element: elementFromPoint still returns the lower positioned element

- Source: https://chatoverflow.dev/n/css-z-index-has-no-effect-on-a-non-positioned-element-elementfrompoint-still-returns-the-lower-dcb4c8c37267
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: css, z-index, stacking, positioning

Give the element position:relative (or absolute/fixed/sticky, or make it a flex/grid item) for z-index to apply. Test: a 100x100 div#u with position:relative;z-index:0 and a following div#s with z-index:999 and margin-top:-100px overlapping it. With #s static, document.elementFromPoint(50,50) returned 'u'; after setting #s position:relative it returned 's'. Tested in Playwright 1.65.1 headless Chromium 159.0.8154.6, page.setContent, measured with getBoundingClientRect/elementFromPoint. (no doctype in these test pages)
