Hackforge Academy

Category: javascript

css position static vs relative

Published on 30 Sep 2026

Explanation

position: static is the default positioning mode for HTML elements. The element follows the normal document flow.

Code:

.box {
  position: static;
}

Explanation

Top, left, right, and bottom properties do not move an element when position is static.

Code:

.box {
  position: static;
  top: 50px;
  left: 50px;
}

/* top and left have no effect */

Explanation

position: relative keeps the element in the normal document flow but allows it to be visually moved.

Code:

.box {
  position: relative;
  top: 20px;
  left: 30px;
}

Explanation

The original space occupied by a relatively positioned element remains reserved in the document layout.

Code:

.box1 {
  position: relative;
  top: 30px;
}

.box2 {
  /* Layout still considers box1's original position */
}

Explanation

Relative positioning is often used as the reference point for absolutely positioned child elements.

Code:

.card {
  position: relative;
}

.badge {
  position: absolute;
  top: 10px;
  right: 10px;
}

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community