CSS

CSS

🎯 CSS position Property

The position CSS property defines how an element is positioned on a web page.

It works together with top, right, bottom, and left to control element placement.

🔹 Why Use position?

The position property is essential for creating modern layouts, overlays, sticky headers, and precise element placement.

  • Controls exact element placement
  • Enables overlays and popups
  • Supports sticky navigation bars
  • Helps build advanced layouts

🧩 position Values

1️⃣ static (Default)

The element stays in the normal document flow. Positioning properties do not apply.

CSS

div {
    position: static;
}
                

2️⃣ relative

The element is positioned relative to its original position.

CSS

div {
    position: relative;
    top: 10px;
    left: 10px;
}
                

3️⃣ absolute

The element is removed from normal flow and positioned relative to the nearest positioned parent.

CSS

div {
    position: absolute;
    top: 0;
    right: 0;
}
                

4️⃣ fixed

The element is fixed to the viewport and does not move when scrolling.

CSS

div {
    position: fixed;
    bottom: 20px;
    right: 20px;
}
                

5️⃣ sticky

The element behaves like relative until it reaches a scroll position, then it becomes fixed.

CSS

div {
    position: sticky;
    top: 0;
}
                

6️⃣ initial

Resets the property to its default value (static).

7️⃣ inherit

Inherits the position value from the parent element.

📌 top, right, bottom, left

These properties are used to control the exact position of elements that are not in static positioning.

  • top → distance from top
  • right → distance from right
  • bottom → distance from bottom
  • left → distance from left

📌 Quick Summary

  • 🧠 Overview

  • position → controls element placement on the page
  • Works with top, right, bottom, left for precise positioning
  • absolute, fixed, and sticky remove or modify normal flow
  • static is default and ignores positioning rules