Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Modal opens behind overlay (z-index bug): how to find and fix it

CNV-118Medium impactPartlyBy FunnelGuardPublished Updated
On this page

What this issue is

A modal is a popup box that sits on top of the page, usually with a dark overlay (also called a backdrop) behind it. The browser decides what sits on top using z-index, a CSS number where higher means closer to the viewer. This bug happens when the overlay ends up above the modal. You see the page darken, but the box with the form or offer is hidden, or visible but unclickable because the overlay catches every click.

Where the visitor gets stuck
  1. Visitor clicks CTAButton works and triggers the modal
  2. Modal opensOverlay appears on top of the modal
  3. Form filled inFields can't be reached or typed into
  4. Lead submittedNever happens

The click on the CTA works, the modal opens, but it renders under the overlay.

Why it costs you leads or sales

Modal leads per 1,000 CTA clicksExample numbers
Modal leads per 1,000 CTA clicks (example)Modal works: 60 leads; Modal behind overlay: 2 leads02346602Modal worksModal behind overlayleads

Example: illustrative numbers only. A working modal vs one hidden behind the overlay.

How to check if your site has it

Check by hand in about five minutes
  1. Trigger the modal on desktop and mobile

    Click every button that opens a popup: CTAs, cart, booking, chat, newsletter. Use a private window so cookies don't hide it. Also test on a real phone or Chrome DevTools device mode.

  2. Try to click and type inside it

    If the page is dimmed and the fields don't respond, or the close button does nothing, the overlay is on top.

  3. Inspect the elements

    Right-click the dimmed area, choose Inspect, and see which element receives the click. If it is the overlay or backdrop class, the modal is underneath.

  4. Compare z-index values

    In DevTools, select the modal and the overlay and compare the Computed z-index. Then walk up the modal's parents looking for transform, filter, opacity, or position with z-index. Those create a stacking context.

  5. Check other pages and states

    Test logged in and logged out, with the sticky header showing, with a cookie banner open, and with a chat widget loaded. Another layer is often the culprit.

Paste in the browser console with the modal open to see what is on topjavascript
const el = document.elementFromPoint(window.innerWidth / 2, window.innerHeight / 2);
console.log(el);
let n = el;
while (n) {
  const s = getComputedStyle(n);
  console.log(n.tagName, n.className, 'z-index:', s.zIndex, 'position:', s.position, 'transform:', s.transform);
  n = n.parentElement;
}

How to fix it

Basic fix: modal above overlaycss
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.modal {
  position: fixed;
  z-index: 1001; /* higher than the overlay */
}
Apply the fix on your platform
  1. Find which plugin or theme makes the popup

    Inspect the modal and note its class name (for example from a popup plugin, page builder or theme). Then update that plugin and theme first, as many stacking bugs are fixed in releases.

  2. Add override CSS

    Go to Appearance > Customize > Additional CSS (or your child theme stylesheet) and set a higher z-index on the modal class than on the overlay class. Use the class names you found.

  3. Check sticky headers and other plugins

    If the header, cookie banner or chat widget sits above the modal, lower its z-index or raise the modal above it. Clear page and CDN caches afterwards.

Native dialog: always on top, no z-index neededhtml
<dialog id="quote-modal">
  <form method="dialog">
    <!-- your form fields -->
    <button>Close</button>
  </form>
</dialog>

<script>
  document.getElementById('quote-modal').showModal();
</script>
Modal layering

Before

  • Overlay z-index higher than modal
  • Modal nested in a transformed wrapper
  • Page dims, fields can't be clicked

After

  • Modal z-index higher than overlay and header
  • Modal rendered directly under body
  • Form is clickable and submits

How to confirm it's fixed

Confirmation checks
  • Open the modal on desktop and on a real phone; the box is on top of the dark overlay.
  • Click into each field, type, and press the close button.
  • Submit a test entry and confirm it arrives in your inbox or CRM.
  • Test with the sticky header, cookie banner and chat widget visible.
  • Run the console snippet again: the first element should be inside your modal.
  • Test in at least Chrome and Safari, since stacking behaviour can differ.

How to prevent it happening again

Prevention habits
  • Keep one documented z-index scale and reuse it.
  • Render modals at the top level of the page, or use the native dialog element.
  • Avoid transform, filter and opacity on wrappers that contain modals.
  • Re-test popups after theme, plugin, app or page builder updates.
  • Test again whenever you add a sticky bar, chat widget or cookie banner.
  • Schedule an automatic check of your key popup journeys.
How the bug usually appears
  1. Day 0

    A theme or plugin update changes the overlay's z-index or adds a transform to a wrapper.

  2. Day 1

    Visitors click the CTA, see a dimmed page and leave. Nobody reports it.

  3. Week 2

    Leads from that page drop and you start looking at ads or traffic.

  4. Fix day

    You spot the layering issue, adjust the CSS and re-test.

How FunnelGuard handles this

Questions people ask

Why is my modal opening behind the overlay?

The overlay has a higher z-index than the modal, or the modal sits inside a parent element that creates its own stacking context (for example with transform, filter or opacity). In both cases the overlay renders on top. Raise the modal's z-index above the overlay and move it to the top level of the page.

Why is z-index not working on my popup?

z-index only applies to positioned elements (relative, absolute, fixed or sticky) and only competes within the same stacking context. If a parent has transform, filter, opacity below 1 or its own z-index, your popup is trapped inside it. Move the popup out of that parent or remove the property.

How do I make a modal appear on top of everything?

Render it as a direct child of body and give it a z-index higher than the overlay and any sticky header. Or use the native dialog element with showModal(), which places it in the browser's top layer above all z-index values.

Why is my popup hidden behind the sticky header?

The header's z-index is higher than the popup's, or they are in different stacking contexts. Lower the header's z-index or raise the modal's, and check that the modal isn't nested inside a transformed wrapper.

How can I find which element is covering my modal?

Open the modal, right-click the dimmed area and choose Inspect, or run document.elementFromPoint() in the console at the centre of the screen. The element it returns is what's on top. Then check its z-index and its parents' stacking contexts.

Can a z-index bug cause lost leads without any error?

Yes. The CTA click works and no script error appears, so analytics can look normal while visitors can't use the form. That's why you need to test the modal visually or run a journey check that tries to complete the step.

Does FunnelGuard detect a modal hidden behind an overlay?

Partly. It runs your journey on a schedule and flags when a click is covered by another element or a step can't be completed, with a screenshot and likely cause. It doesn't inspect your CSS or judge visual layering, so check popups by hand after changes.

Does FunnelGuard catch this?

Partly

FunnelGuard checks part of this.

How: covered detection.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.