codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🎨

HTML & CSS

20 / 59 topics
17Introduction to CSS18CSS Selectors19CSS Box Model20CSS Positioning21CSS Display Properties
Tutorials/HTML & CSS/CSS Positioning
🎨HTML & CSS

CSS Positioning

Updated 2026-05-15
10 min read

CSS Positioning

Introduction

In the world of web development, controlling the layout of elements on a webpage is crucial. CSS provides several positioning properties that allow developers to precisely control where elements appear on the page. In this tutorial, we will explore four fundamental positioning methods: static, relative, absolute, and fixed.

Concept

Static Positioning

The default positioning method for all HTML elements is static. Elements with a static position are positioned according to the normal flow of the document. They do not respond to top, bottom, left, or right properties.

<div style="position: static; width: 100px; height: 100px; background-color: lightblue;">
  Static Element
</div>

Relative Positioning

The relative positioning method allows an element to be positioned relative to its normal position. This means you can adjust the element's position using top, bottom, left, and right properties.

<div style="position: relative; width: 100px; height: 100px; background-color: lightcoral;">
  Relative Element
</div>

Absolute Positioning

The absolute positioning method positions an element absolutely to its nearest positioned ancestor (not static). If no such ancestor exists, it uses the initial containing block.

<div style="position: relative; width: 200px; height: 200px; background-color: lightgreen;">
  <div style="position: absolute; top: 50px; left: 50px; width: 100px; height: 100px; background-color: lightblue;">
    Absolute Element
  </div>
</div>

Fixed Positioning

The fixed positioning method positions an element relative to the viewport, meaning it stays in the same place even when the page is scrolled.

<div style="position: fixed; top: 10px; right: 10px; width: 100px; height: 100px; background-color: lightcoral;">
  Fixed Element
</div>

Examples

Let's dive into some practical examples to solidify our understanding.

Example 1: Static Positioning

<div style="position: static; width: 100px; height: 100px; background-color: lightblue;">
  Static Element
</div>
Output
Static Element

Example 2: Relative Positioning

<div style="position: relative; width: 100px; height: 100px; background-color: lightcoral;">
  Relative Element
</div>
Output
Relative Element

Example 3: Absolute Positioning

<div style="position: relative; width: 200px; height: 200px; background-color: lightgreen;">
  <div style="position: absolute; top: 50px; left: 50px; width: 100px; height: 100px; background-color: lightblue;">
    Absolute Element
  </div>
</div>
Output
Absolute Element inside Relative Parent

Example 4: Fixed Positioning

<div style="position: fixed; top: 10px; right: 10px; width: 100px; height: 100px; background-color: lightcoral;">
  Fixed Element
</div>
Output
Fixed Element at Top-Right Corner

What's Next?

Now that you have a good grasp of CSS positioning, the next topic to explore is HTML Tables. Understanding how to structure and style tables will be invaluable for creating well-organized data presentations on your web pages.

Stay tuned for more tutorials on "HTML Tables"!

Info

Remember, practice is key in mastering CSS positioning. Try experimenting with different combinations of these properties to see how they interact.


PreviousCSS Box ModelNext CSS Display Properties

Recommended Gear

CSS Box ModelCSS Display Properties