position controls how an element is placed. Use it with top, right, bottom, left.
| Value | Positioned relative to |
|---|---|
static |
normal flow (default; top/left do nothing) |
relative |
its own normal position |
absolute |
the nearest positioned ancestor |
fixed |
the browser window — stays when you scroll |
sticky |
normal flow until a scroll point, then sticks |
Common pattern
Parent position: relative; + child position: absolute; top: 0; right: 0; places the child in the parent's top-right corner — perfect for badges.
Example
Example — Badge with absolute position
HTML
<style>
.card { position: relative; width: 220px; padding: 30px 16px 16px; border: 1px solid #ccc; border-radius: 8px; }
.badge { position: absolute; top: 8px; right: 8px; background: crimson; color: white; font-size: 12px; padding: 3px 8px; border-radius: 12px; }
.sticky { position: sticky; top: 0; background: #1f386b; color: white; padding: 8px; }
</style>
<div class="sticky">Sticky header</div>
<div class="card">
<span class="badge">NEW</span>
CSS Course card
</div>