Added in v5.3

Z-index

Use our low-level z-index utilities to quickly change the stack level of an element or component.

Example

Use z-index utilities to stack elements on top of one another. Requires a position value other than static, which can be set with custom styles or using our position utilities.

We call these “low-level” z-index utilities because of their default values of -1 through 3, which we use for the layout of overlapping components. High-level z-index values are used for overlay components like modals and tooltips.

Z-index - 图1

html

  1. <div class="z-3 position-absolute p-5 rounded-3"><span>z-3</span></div>
  2. <div class="z-2 position-absolute p-5 rounded-3"><span>z-2</span></div>
  3. <div class="z-1 position-absolute p-5 rounded-3"><span>z-1</span></div>
  4. <div class="z-0 position-absolute p-5 rounded-3"><span>z-0</span></div>
  5. <div class="z-n1 position-absolute p-5 rounded-3"><span>z-n1</span></div>

Overlays

Bootstrap overlay components—dropdown, modal, offcanvas, popover, toast, and tooltip—all have their own z-index values to ensure a usable experience with competing “layers” of an interface.

Read about them in the z-index layout page.

Component approach

On some components, we use our low-level z-index values to manage repeating elements that overlap one another (like buttons in a button group or items in a list group).

Learn about our z-index approach.

CSS

Sass maps

Customize this Sass map to change the available values and generated utilities.

scss/_variables.scss

  1. $zindex-levels: (
  2. n1: -1,
  3. 0: 0,
  4. 1: 1,
  5. 2: 2,
  6. 3: 3
  7. );

Sass utilities API

Position utilities are declared in our utilities API in scss/_utilities.scss. Learn how to use the utilities API.

scss/_utilities.scss

  1. "z-index": (
  2. property: z-index,
  3. class: z,
  4. values: $zindex-levels,
  5. )