agyanadda@gmail.com

CSS Position

CSS Layout 1 min read Updated Dec 1, 2026 Topic 20 of 39

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>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which value keeps an element in place while the page scrolls?

Exercise 2 True / False

top and left have no effect on position: static elements.

Exercise 3 Fill in the Blank

An absolute child is placed relative to the nearest ancestor with position: ___ (most commonly).

Frequently Asked Questions

Set a top value (e.g. top: 0) and make sure no parent has overflow: hidden.