On this page

Z-index

Which element is drawn on top when two overlap. Seven named layers keep floating things in the same order everywhere.

Z-index decides which element is drawn on top when two overlap. Beehexa uses seven named layers instead of free numbers, so a menu never opens behind a dialog and a toast never hides under the scrim.

Each layer covers the ones below it. The step is 100, so a new layer can go between two others.

How it works

  • A higher layer covers a lower one. Values run from 100 to 700 in steps of 100, leaving room for a new layer.
  • Pick the layer by what the element does, not by how high a number you need.
  • A layer only competes with its neighbours. An element with its own z-index, transform, filter or opacity below 1 starts a new stacking context; nothing inside can rise above it. That is why a list inside a dialog is rendered inside the dialog.

Elevation shows how high a surface looks; z-index makes sure it is drawn on top. A menu needs both.

Layer Token Value Elevation Use for
Sticky z-index.sticky 100 Page Sticky table headers and toolbars
Navigation z-index.navigation 200 Page App header, side navigation
Overlay z-index.overlay 300 Overlay Menus, select lists, popovers
Modal z-index.modal 400 Modal Dialogs, drawers and their scrim
Spotlight z-index.spotlight 500 Modal Product tour, onboarding spotlight
Tooltip z-index.tooltip 600 none Tooltips
Toast z-index.toast 700 Overlay Toasts, the skip link

Why this order

  • Menus cover the navigation they open from.
  • A modal blocks the whole page, menus included.
  • A tour can point at something inside a dialog.
  • A tooltip explains a control, wherever that control is.
  • A toast reports on the whole app, so nothing covers it.

On a screen

  1. 1z-index.navigationApp header
  2. 2z-index.stickyTable header while the table scrolls
  3. 3z-index.overlayMenu opened from a button
  4. 4z-index.tooltipTooltip on an icon button
  5. 5z-index.toastToast

Inside one component, values from 1 to 9 need no token, for example to lift the focused button in a button group.

Do and don’t

Do

Give toasts z-index.toast. A toast stays readable while a dialog is open.

Don’t

Don’t give a toast a lower value than the dialog. It ends up under the scrim.

Do

Render a list that opens inside a dialog inside the dialog, so it can run past the dialog’s edge.

Don’t

Don’t let the dialog clip the list. Raising its z-index does not fix that.

Do

Put the scrim before the dialog. Both use z-index.modal, so the dialog draws on top.

Don’t

Don’t put the scrim after the dialog. It dims the dialog too.

Tokens

TokenValueDescription
--bh-z-index-sticky100Sticky table headers and toolbars inside the page.
--bh-z-index-navigation200App header and side navigation.
--bh-z-index-overlay300Dropdowns, menus, popovers and select lists.
--bh-z-index-modal400Dialogs, drawers and their scrim.
--bh-z-index-spotlight500Product tour and onboarding spotlight, above a dialog.
--bh-z-index-tooltip600Tooltips, above everything you can interact with.
--bh-z-index-toast700Toasts and the skip link: always on top.
  • Elevation: how high a surface looks.
  • Motion: how menus, dialogs and toasts appear and leave.