Position
Bootstrap 5 Position
Use these helpers for quickly configuring the position of an element.
Basic examples
Fixed 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.
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.
Sticky top
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.
Responsive sticky top
Responsive variations also exist for .sticky-top
utility.
Position values
Quick positioning classes are available, though they are not responsive.
Arrange elements
Arrange elements easily with the edge positioning utilities. The format is
{property}-{position}
.
Where property is one of:
top
- for the verticaltop
positionleft
- for the horizontalleft
positionbottom
- for the verticalbottom
positionright
- for the horizontalright
position
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.
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.
Additional examples
Here are some real life examples of these classes:
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.