Skip to content

Instantly share code, notes, and snippets.

@jimmynotjim
Created October 9, 2025 16:07
Show Gist options
  • Save jimmynotjim/de9210663c18fed506147f545eaa5ad9 to your computer and use it in GitHub Desktop.
Save jimmynotjim/de9210663c18fed506147f545eaa5ad9 to your computer and use it in GitHub Desktop.
Highlight z-index to find layering bugs
// Drop this in the console and highlight all the elements with a defined z-index.
// Helpful for debugging z-index issues.
function highlightElementsWithZIndex() {
const allElements = document.querySelectorAll('*');
allElements.forEach(element => {
const zIndex = window.getComputedStyle(element).zIndex;
// Check if z-index is explicitly set and is a valid number (not "auto")
if (zIndex !== 'auto' && !isNaN(parseInt(zIndex))) {
element.style.border = '2px solid red';
element.style.boxShadow = '0 0 5px rgba(255, 0, 0, 0.5)';
console.log(`Element:`, element, `Z-index:`, zIndex);
}
});
}
highlightElementsWithZIndex();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment