← Back to Bootstrap Course | Chapter 9: Layout Utilities | Lesson 3 of 7

Position utilities

Position utilities place elements relative, absolute, fixed or sticky and pin them to edges.

In this page:

  1. Position utilities
Syntax
markup
<div class="position-relative">
  <div class="position-absolute top-0 end-0">corner</div>
</div>

Position utilities

Use .position-static, -relative, -absolute, -fixed and -sticky. Then edge helpers .top-0, .start-0, .end-0, .bottom-0 and .translate-middle position the element, and .fixed-top, .fixed-bottom and .sticky-top provide common shortcuts.

Absolute children need a relative parent.

Note: An absolute element positions relative to its nearest positioned ancestor.

Example: Position utilities

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="position-relative bg-light border" style="height: 8rem">
    <span class="position-absolute top-0 start-0 badge text-bg-primary">top-start</span>
    <span class="position-absolute top-50 start-50 translate-middle badge text-bg-success">centre</span>
    <span class="position-absolute bottom-0 end-0 badge text-bg-danger">bottom-end</span>
  </div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting a position-relative parent
  2. Using fixed on many elements
  3. Covering content with fixed bars
Chapter Summary
  • position-relative, absolute, fixed, sticky
  • top-0, start-0, end-0, bottom-0
  • translate-middle centres on the edge
  • Absolute needs a relative parent
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.