What Is z-index?
z-index is a CSS property that controls the vertical stacking order of overlapping HTML elements on a page. It only works on positioned elements (those with position set to relative, absolute, fixed, or sticky). Higher z-index values bring elements closer to the viewer, causing them to render on top of elements with lower values. Understanding z-index also requires understanding stacking contexts—isolated layers that scope how child z-index values are resolved.
How z-index works
By default, HTML elements stack in source order—later elements paint on top of earlier ones. The z-index property overrides this default within a stacking context. A positive z-index (e.g. z-index: 10) places the element above siblings with lower or no z-index values; a negative z-index (e.g. z-index: -1) pushes it behind its parent's background. The property accepts any integer value. Crucially, z-index only applies to elements whose position property is set to something other than static (the default). Setting z-index on a statically positioned element has no effect.
Stacking contexts explained
A stacking context is an isolated layering scope. Within a stacking context, child z-index values are resolved relative to each other—not to elements outside the context. A new stacking context is created whenever an element has: position + z-index (not auto), opacity less than 1, transform/filter/perspective set to any value, will-change targeting opacity or transform, or isolation: isolate. This means an element with z-index: 9999 inside a stacking context with z-index: 1 will still appear behind a sibling element with z-index: 2. Understanding this hierarchy is the key to debugging z-index issues.
Common z-index bugs and fixes
The most common z-index bug is 'z-index not working'—almost always caused by the element having position: static. Fix: add position: relative. The second most common issue is stacking context isolation: a child's high z-index is trapped inside a parent's low stacking context. Fix: restructure the DOM or adjust the parent's z-index. Third, z-index wars—teams escalating values to 99999—indicate missing architectural conventions. Fix: adopt a z-index scale (e.g. 1 = base, 100 = dropdowns, 200 = modals, 300 = tooltips, 400 = toasts). Finally, negative z-index can push elements behind their parent's background, making them invisible. Fix: apply position: relative to the parent without a z-index to avoid creating a new stacking context.
z-index in Bootstrap 5 and Canvas
Bootstrap 5 ships with a well-defined z-index scale documented in its Sass variables: $zindex-dropdown (1000), $zindex-sticky (1020), $zindex-fixed (1030), $zindex-offcanvas (1045), $zindex-modal-backdrop (1050), $zindex-modal (1055), $zindex-popover (1070), $zindex-tooltip (1080), and $zindex-toast (1090). Canvas Builder templates follow this same scale, ensuring that generated navbars, modals, dropdowns, and toasts layer correctly without conflicts. When customising Canvas-generated pages, stay within these documented tiers to avoid stacking issues.
z-index & Canvas Builder
Canvas Builder templates follow Bootstrap 5's z-index scale for all layered components—modals, dropdowns, sticky navbars, and toasts stack correctly out of the box. Custom sections use conservative z-index values to avoid conflicts with framework components.
Try Canvas Builder →