position

Position Values

ValuePositioned relative toIn the normal flow?
static (default)not positionedyes
relativeits own normal positionyes (space kept)
absolutenearest positioned ancestorno
fixedthe viewport (stays when scrolling)no
stickynormal until a scroll threshold, then sticksyes

Positioned elements are moved with top, right, bottom and left.

relative + absolute

Example

The classic pattern: a relative parent and an absolute child, such as a badge on a card:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .card { position: relative; width: 220px; padding: 20px; border: 1px solid #ccc; font-family: Arial; }
    .badge { position: absolute; top: -10px; right: -10px; background: tomato; color: white;
             border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; }
  </style>
</head>
<body>

<div class="card">Notifications <span class="badge">3</span></div>

</body>
</html>

Result

sticky

Example

Scroll inside the preview: the header sticks to the top:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    body { font-family: Arial; margin: 0; }
    header { position: sticky; top: 0; background: #282A35; color: white; padding: 10px; }
    p { padding: 0 10px; }
  </style>
</head>
<body>

<header>Sticky header</header>
<p>Scroll down...</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>.</p><p>The end.</p>

</body>
</html>

Result