Back to CSS Notes
Topic #230

Static and Relative Position

By the end of this lesson, you will be able to explain CSS static and relative positioning, and use relative offsets to nudge an element without changing the normal document flow.

What it is

Static positioning is the browser default. A static element participates in normal flow: block elements stack vertically, inline elements flow horizontally, and properties like top, right, bottom, and left have no effect.

Relative positioning keeps the element in normal flow but lets you offset it from its original position. The element still reserves its original space, so surrounding content does not reflow around the offset. Related terms include normal flow, offset properties, and containing block. A relatively positioned element is often used as a reference point for absolutely positioned children.

Why it matters

  • Nudge badges, icons, or superscripts without moving nearby text.
  • Create small visual corrections when flex or grid alignment is almost right.
  • Provide a positioned ancestor for absolutely positioned tooltips or dropdowns.
  • Avoid layout shift because the original space remains reserved.

Syntax or steps

  1. Set position: relative; on the element you want to move.
  2. Add one or more offset properties: top, right, bottom, or left.
  3. Use small values such as top: -4px; for visual nudges.
  4. Remember that offsets are measured from the element’s normal-flow position, not from the viewport.

Example

<!DOCTYPE html>
<html>
<head>
<style>
.card {
  width: 260px;
  padding: 16px;
  border: 1px solid #ccc;
  font-family: sans-serif;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  background: #111;
  color: white;
  border-radius: 999px;
  position: relative;
  top: -4px;
}
</style>
</head>
<body>
  <div class="card">
    <h2>Invoice</h2>
    <p>Total: $42.00</p>
    <span class="badge">New</span>
  </div>
</body>
</html>
  • .badge is still in normal flow, so the card layout does not change.
  • position: relative makes top work.
  • top: -4px moves the badge 4 pixels upward from its static position.
  • If another element followed the badge, it would stay where the badge originally was.

Common mistakes

  • Forgetting position: relative; offsets do nothing on static elements.
  • Assuming relative positioning removes the element from normal flow.
  • Using large relative offsets for page layout; this can cause overlap because space is not removed.
  • Confusing relative with absolute; absolute positioning removes the element from normal flow.

When to use it

Position Behavior Best for
static Default flow; offsets ignored. Normal content.
relative Offset from original position; original space remains. Small nudges and positioned ancestors.
absolute Removed from flow; positioned relative to nearest positioned ancestor. Overlays, tooltips, badges pinned to corners.

Practice

Guided exercise: Create a paragraph with class note. Add .note { position: relative; top: 8px; }. Expected output: the paragraph appears 8 pixels lower, but following content stays in its original position.

Challenge: Nudge the badge up and right using top: -4px; and left: 4px;. Hint: positive left moves an element right.

Quick check

Question: Does a relative offset change the space reserved for the element? Answer: No. The element moves visually, but its original space remains in normal flow.

Summary

Static positioning is normal flow. Relative positioning lets you offset an element while preserving its original space, making it ideal for small visual adjustments and as a reference point for absolutely positioned children.

Want to go beyond the notes?

Join Coding Now Tech Institute's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Static and Relative Position – FAQs

Quick answers about learning Static and Relative Position in CSS.

This free note from Coding Now Tech Institute explains Static and Relative Position in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on Coding Now Tech Institute, including Static and Relative Position, is 100% free with no signup required.
With focused practice, most students grasp Static and Relative Position in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now