Position
Use these shorthand utilities for quickly configuring the position of an element.
Bootstrap Position documentationFixed top
Position an element at the top of the viewport, from edge to edge. Be sure you understand the ramifications of fixed position in your project; you may need to add additional CSS.
<div class="fixed-top">...</div>
Fixed bottom
Position an element at the bottom of the viewport, from edge to edge. Be sure you understand the ramifications of fixed position in your project; you may need to add additional CSS.
<div class="fixed-bottom">...</div>
Fixed bottom
Position an element at the top of the viewport, from edge to edge, but only after you scroll past it. The .sticky-top utility uses CSS’s position: sticky, which isn’t fully supported in all browsers.
<div class="sticky-top">...</div>
Position values
Quick positioning classes are available, and they are responsive.
<div class="position-static">...</div>
<div class="position-relative">...</div>
<div class="position-absolute">...</div>
<div class="position-fixed">...</div>
<div class="position-sticky">...</div>
<div class="position-sm-static">...</div>
<div class="position-sm-relative">...</div>
<div class="position-sm-absolute">...</div>
<div class="position-sm-fixed">...</div>
<div class="position-sm-sticky">...</div>
<div class="position-md-static">...</div>
<div class="position-md-relative">...</div>
<div class="position-md-absolute">...</div>
<div class="position-md-fixed">...</div>
<div class="position-md-sticky">...</div>
<div class="position-lg-static">...</div>
<div class="position-lg-relative">...</div>
<div class="position-lg-absolute">...</div>
<div class="position-lg-fixed">...</div>
<div class="position-lg-sticky">...</div>
<div class="position-xl-static">...</div>
<div class="position-xl-relative">...</div>
<div class="position-xl-absolute">...</div>
<div class="position-xl-fixed">...</div>
<div class="position-xl-sticky">...</div>
<div class="position-xxl-static">...</div>
<div class="position-xxl-relative">...</div>
<div class="position-xxl-absolute">...</div>
<div class="position-xxl-fixed">...</div>
<div class="position-xxl-sticky">...</div>
Arrange elements
Arrange elements easily with the edge positioning utilities. The format is {property}-{position}
.
Where property is one of:
top
- for the verticaltop
positionstart
- for the horizontalleft
position (in LTR)bottom
- for the verticalbottom
positionend
- for the horizontalright
position (in LTR)
Where position is one of:
0
- for0
edge position50
- for50%
edge position100
- for100%
edge position
(You can add more position values by adding entries to the $position-values
Sass map variable.)
<div class="top-0">...</div>
<div class="right-0">...</div>
<div class="bottom-0">...</div>
<div class="left-0">...</div>
<div class="top-sm-0">...</div>
<div class="right-sm-0">...</div>
<div class="bottom-sm-0">...</div>
<div class="left-sm-0">...</div>
<div class="top-md-0">...</div>
<div class="right-md-0">...</div>
<div class="bottom-md-0">...</div>
<div class="left-md-0">...</div>
<div class="top-lg-0">...</div>
<div class="right-lg-0">...</div>
<div class="bottom-lg-0">...</div>
<div class="left-lg-0">...</div>
<div class="top-xl-0">...</div>
<div class="right-xl-0">...</div>
<div class="bottom-xl-0">...</div>
<div class="left-xl-0">...</div>
<div class="top-xxl-0">...</div>
<div class="right-xxl-0">...</div>
<div class="bottom-xxl-0">...</div>
<div class="left-xxl-0">...</div>
Center elements
In addition, you can also center the elements with the transform utility class .translate-middle
.
This class applies the transformations translateX(-50%)
and translateY(-50%)
to the element which, in combination with the edge positioning utilities, allows you to absolute center an element.
<div class="position-relative">
<div class="position-absolute top-0 start-0 translate-middle"></div>
<div class="position-absolute top-0 start-50 translate-middle"></div>
<div class="position-absolute top-0 start-100 translate-middle"></div>
<div class="position-absolute top-50 start-0 translate-middle"></div>
<div class="position-absolute top-50 start-50 translate-middle"></div>
<div class="position-absolute top-50 start-100 translate-middle"></div>
<div class="position-absolute top-100 start-0 translate-middle"></div>
<div class="position-absolute top-100 start-50 translate-middle"></div>
<div class="position-absolute top-100 start-100 translate-middle"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-sm-0 start-sm-0 translate-middle-sm"></div>
<div class="position-absolute top-sm-0 start-sm-50 translate-middle-sm"></div>
<div class="position-absolute top-sm-0 start-sm-100 translate-middle-sm"></div>
<div class="position-absolute top-sm-50 start-sm-0 translate-middle-sm"></div>
<div class="position-absolute top-sm-50 start-sm-50 translate-middle-sm"></div>
<div class="position-absolute top-sm-50 start-sm-100 translate-middle-sm"></div>
<div class="position-absolute top-sm-100 start-sm-0 translate-middle-sm"></div>
<div class="position-absolute top-sm-100 start-sm-50 translate-middle-sm"></div>
<div class="position-absolute top-sm-100 start-sm-100 translate-middle-sm"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-lg-0 start-lg-0 translate-middle-lg"></div>
<div class="position-absolute top-lg-0 start-lg-50 translate-middle-lg"></div>
<div class="position-absolute top-lg-0 start-lg-100 translate-middle-lg"></div>
<div class="position-absolute top-lg-50 start-lg-0 translate-middle-lg"></div>
<div class="position-absolute top-lg-50 start-lg-50 translate-middle-lg"></div>
<div class="position-absolute top-lg-50 start-lg-100 translate-middle-lg"></div>
<div class="position-absolute top-lg-100 start-lg-0 translate-middle-lg"></div>
<div class="position-absolute top-lg-100 start-lg-50 translate-middle-lg"></div>
<div class="position-absolute top-lg-100 start-lg-100 translate-middle-lg"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-xl-0 start-xl-0 translate-middle-xl"></div>
<div class="position-absolute top-xl-0 start-xl-50 translate-middle-xl"></div>
<div class="position-absolute top-xl-0 start-xl-100 translate-middle-xl"></div>
<div class="position-absolute top-xl-50 start-xl-0 translate-middle-xl"></div>
<div class="position-absolute top-xl-50 start-xl-50 translate-middle-xl"></div>
<div class="position-absolute top-xl-50 start-xl-100 translate-middle-xl"></div>
<div class="position-absolute top-xl-100 start-xl-0 translate-middle-xl"></div>
<div class="position-absolute top-xl-100 start-xl-50 translate-middle-xl"></div>
<div class="position-absolute top-xl-100 start-xl-100 translate-middle-xl"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-xxl-0 start-xxl-0 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-0 start-xxl-50 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-0 start-xxl-100 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-50 start-xxl-0 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-50 start-xxl-50 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-50 start-xxl-100 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-100 start-xxl-0 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-100 start-xxl-50 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-100 start-xxl-100 translate-middle-xxl"></div>
</div>
By adding .translate-middle-x
or .translate-middle-y
classes, elements can be positioned only in horizontal or vertical direction.
<div class="position-relative">
<div class="position-absolute top-0 start-0"></div>
<div class="position-absolute top-0 start-50 translate-middle-x"></div>
<div class="position-absolute top-0 end-0"></div>
<div class="position-absolute top-50 start-0 translate-middle-y"></div>
<div class="position-absolute top-50 start-50 translate-middle"></div>
<div class="position-absolute top-50 end-0 translate-middle-y"></div>
<div class="position-absolute bottom-0 start-0"></div>
<div class="position-absolute bottom-0 start-50 translate-middle-x"></div>
<div class="position-absolute bottom-0 end-0"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-sm-0 start-sm-0"></div>
<div class="position-absolute top-sm-0 start-sm-50 translate-middle-sm-x"></div>
<div class="position-absolute top-sm-0 end-sm-0"></div>
<div class="position-absolute top-sm-50 start-sm-0 translate-middle-sm-y"></div>
<div class="position-absolute top-sm-50 start-sm-50 translate-middle-sm"></div>
<div class="position-absolute top-sm-50 end-sm-0 translate-middle-sm-y"></div>
<div class="position-absolute bottom-sm-0 start-sm-0"></div>
<div class="position-absolute bottom-sm-0 start-sm-50 translate-middle-sm-x"></div>
<div class="position-absolute bottom-sm-0 end-sm-0"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-lg-0 start-lg-0"></div>
<div class="position-absolute top-lg-0 start-lg-50 translate-middle-lg-x"></div>
<div class="position-absolute top-lg-0 end-lg-0"></div>
<div class="position-absolute top-lg-50 start-lg-0 translate-middle-lg-y"></div>
<div class="position-absolute top-lg-50 start-lg-50 translate-middle-lg"></div>
<div class="position-absolute top-lg-50 end-lg-0 translate-middle-lg-y"></div>
<div class="position-absolute bottom-lg-0 start-lg-0"></div>
<div class="position-absolute bottom-lg-0 start-lg-50 translate-middle-lg-x"></div>
<div class="position-absolute bottom-lg-0 end-lg-0"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-xl-0 start-xl-0"></div>
<div class="position-absolute top-xl-0 start-xl-50 translate-middle-xl-x"></div>
<div class="position-absolute top-xl-0 end-xl-0"></div>
<div class="position-absolute top-xl-50 start-xl-0 translate-middle-xl-y"></div>
<div class="position-absolute top-xl-50 start-xl-50 translate-middle-xl"></div>
<div class="position-absolute top-xl-50 end-xl-0 translate-middle-xl-y"></div>
<div class="position-absolute bottom-xl-0 start-xl-0"></div>
<div class="position-absolute bottom-xl-0 start-xl-50 translate-middle-xl-x"></div>
<div class="position-absolute bottom-xl-0 end-xl-0"></div>
</div>
<div class="position-relative">
<div class="position-absolute top-xxl-0 start-xxl-0"></div>
<div class="position-absolute top-xxl-0 start-xxl-50 translate-middle-xxl-x"></div>
<div class="position-absolute top-xxl-0 end-xxl-0"></div>
<div class="position-absolute top-xxl-50 start-xxl-0 translate-middle-xxl-y"></div>
<div class="position-absolute top-xxl-50 start-xxl-50 translate-middle-xxl"></div>
<div class="position-absolute top-xxl-50 end-xxl-0 translate-middle-xxl-y"></div>
<div class="position-absolute bottom-xxl-0 start-xxl-0"></div>
<div class="position-absolute bottom-xxl-0 start-xxl-50 translate-middle-xxl-x"></div>
<div class="position-absolute bottom-xxl-0 end-xxl-0"></div>
</div>
Examples
Here are some real life examples of these classes:
<button type="button" class="btn btn-primary position-relative">
Mails <span class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-secondary">+99 <span class="visually-hidden">unread messages</span></span>
</button>
<button type="button" class="btn btn-dark position-relative">
Marker <svg width="1em" height="1em" viewBox="0 0 16 16" class="position-absolute top-100 start-50 translate-middle mt-1 bi bi-caret-down-fill" fill="#212529" xmlns="http://www.w3.org/2000/svg"><path d="M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z"/></svg>
</button>
<button type="button" class="btn btn-primary position-relative">
Alerts <span class="position-absolute top-0 start-100 translate-middle badge border border-light rounded-circle bg-danger p-2"><span class="visually-hidden">unread messages</span></span>
</button>
You can use these classes with existing components to create new ones. Remember that you can extend its functionality by adding entries to the $position-values
variable.
<div class="position-relative m-4">
<div class="progress" style="height: 1px;">
<div class="progress-bar" role="progressbar" style="width: 50%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<button type="button" class="position-absolute top-0 start-0 translate-middle btn btn-sm btn-primary btn-icon rounded-pill" style="width: 2rem; height:2rem;">1</button>
<button type="button" class="position-absolute top-0 start-50 translate-middle btn btn-sm btn-primary btn-icon rounded-pill" style="width: 2rem; height:2rem;">2</button>
<button type="button" class="position-absolute top-0 start-100 translate-middle btn btn-sm btn-secondary btn-icon rounded-pill" style="width: 2rem; height:2rem;">3</button>
</div>