Bootstrap 5 Z-Index
Z-index
Use our low-levelz-index
utilities to quickly change the stack level of an element or component.
🤖 Looking for the LLM-optimized version?View llm.md
On this page
Example
Usez-index
utilities to stack elements on top of one another. Requires aposition
value other thanstatic
, which can be set with custom styles or using ourposition utilities.
We call these “low-level”
z-index
utilities because of their default values of-1
through3
, which we use for the layout of overlapping components. High-levelz-index
values are used for overlay components like modals and tooltips.z-3
z-2
z-1
z-0
z-n1
html
<divclass="z-3 position-absolute p-5 rounded-3"><span>z-3</span></div><divclass="z-2 position-absolute p-5 rounded-3"><span>z-2</span></div><divclass="z-1 position-absolute p-5 rounded-3"><span>z-1</span></div><divclass="z-0 position-absolute p-5 rounded-3"><span>z-0</span></div><divclass="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 ownz-index
values to ensure a usable experience with competing “layers” of an interface.
Read about them in thez-index
layout page.
CSS
Sass maps
Customize this Sass map to change the available values and generated utilities.
scss/_variables.scss
$zindex-levels:(n1:-1,0:0,1:1,2:2,3:3);
Sass utilities API
Position utilities are declared in our utilities API inscss/_utilities.scss
.Learn how to use the utilities API.
scss/_utilities.scss
"z-index":(property:z-index,class:z,values:$zindex-levels,)