Skip to content

Z-Index

Z-Index utilities in Metro UI provide a consistent system for managing stacking contexts through CSS variables and utility classes. These utilities help maintain predictable layering of elements like modals, dropdowns, tooltips and other components that need specific stacking order.

Metro UI defines the following CSS variables to ensure consistent z-index values across the framework:

VariableValueDescription
--z-index-selected100Selected elements (selected state indicator)
--z-index-absolute500Basic absolutely positioned elements
--z-index-dropdown1000Dropdown menus and basic popups
--z-index-sticy1020Sticky positioned elements
--z-index-fixed1030Fixed positioned elements (navbars, fixed toolbars)
--z-index-modal-backdrop1040Background overlay behind modals
--z-index-modal1050Modal dialogs and windows
--z-index-popover1060Popovers
--z-index-tooltip1070Tooltips
--z-index-top1080Elements that should appear above most other content
--z-index-notify1085Notifications
--z-index-charms1090Charm bars and edge-aligned panels
--z-index-overlay2000System overlays
--z-index-fullscreen2147483647Fullscreen elements (maximum possible value)

These classes apply specific z-index values according to the component type:

ClassDescription
.z-absoluteFor absolutely positioned elements
.z-dropdownFor dropdown menus
.z-stickyFor sticky elements (like sticky headers)
.z-fixedFor fixed position elements
.z-modal-backdropFor modal backgrounds/overlays
.z-modalFor modal dialogs
.z-popoverFor popovers
.z-tooltipFor tooltips
.z-topFor elements that should appear near the top of stacking context
.z-notifyFor notification elements
.z-charmsFor charm bars
.z-overlayFor overlay elements
.z-fullscreenFor fullscreen elements

For more granular control, you can use numbered classes for lower z-index values:

ClassValue
.z-1z-index: 1
.z-2z-index: 2
.z-3z-index: 3
.z-4z-index: 4
.z-5z-index: 5
.z-6z-index: 6
.z-7z-index: 7
.z-8z-index: 8
.z-9z-index: 9
.z-10z-index: 10
<div class="position-absolute z-1">
This appears above normal content but below other positioned elements
</div>
<div class="position-absolute z-5">
This appears above elements with lower z-index
</div>
<!-- Navigation bar that stays on top of content when scrolling -->
<nav class="position-sticky z-sticky">
Sticky navigation
</nav>
<!-- Modal dialog -->
<div class="z-modal-backdrop">
<!-- Overlay background -->
</div>
<div class="z-modal">
Modal content appears above the backdrop
</div>
<!-- Notification that appears above modal -->
<div class="z-notify">
Important system notification
</div>

When developing complex interfaces with multiple overlapping elements, follow these guidelines:

  1. Use the predefined z-index classes where possible instead of custom z-index values
  2. For custom components, use CSS variables (e.g., z-index: var(--z-index-dropdown))
  3. Only increase z-index values when necessary to resolve specific stacking issues
  4. Remember that z-index only works on positioned elements (relative, absolute, fixed, or sticky)
<div class="position-relative">
<div class="position-absolute z-1">
Item 1
</div>
<div class="position-absolute z-2">
Item 2 (appears above Item 1)
</div>
</div>