DEV Community

Python Tutorial
Python Tutorial

Posted on

CSS Positioning Explained: Static, Relative, Absolute, and Fixed

CSS tutorial

Image description


Introduction

When you're diving into the world of web development, understanding how to control the placement of elements on a page is absolutely essential. In this CSS tutorial, we’ll walk through one of the most important and often misunderstood parts of styling a website — CSS positioning. If you're searching for a CSS tutorial for beginners, this guide will help you master the core concepts of static, relative, absolute, and fixed positioning.

CSS positioning allows developers to specify exactly where elements should appear within a document. Without proper positioning, even the most beautifully designed elements can end up looking messy or misaligned. Let’s break down each positioning type so you can use them confidently.

Static Positioning (The Default)

When you don't specify any positioning for an element, it defaults to static. Static positioning simply means that elements are placed in the natural flow of the HTML page, one after another, from top to bottom. You can't really move a static element using top, bottom, left, or right properties — they will have no effect.

Static positioning is the least complicated of all positioning types, but it's important to know that it serves as the foundation. By default, most elements on a basic web page are statically positioned.

Example:

<div style="position: static;">This is statically positioned.</div>

Relative Positioning

Next up is relative positioning. When you set an element’s position to relative, it remains in the normal document flow, but now you can shift it around using the top, bottom, left, and right properties. The key thing to remember is that the element still "reserves" its original space, even after being moved.

Relative positioning is often used to create a new positioning context for absolutely positioned child elements, or just to nudge something slightly from its normal spot.

Example:

<div style="position: relative; top: 10px; left: 20px;">This is relatively positioned.</div>

In this CSS tutorial for beginners, always remember: relative moves the element, but leaves a gap where it originally was.

Absolute Positioning

Absolute positioning completely removes an element from the normal document flow. It’s positioned relative to its nearest positioned ancestor (that is, an ancestor with position: relative, absolute, or fixed). If there’s no such ancestor, the element will position itself relative to the element (i.e., the entire page).

Absolute positioning is super powerful but can cause confusion if you’re not careful. It’s best used when you want an element to appear exactly at a certain spot within another container.

Example:

<div style="position: relative;">
  <div style="position: absolute; top: 0; right: 0;">I am absolutely positioned inside the relative container.</div>
</div>

Here, the absolute element sticks to the top-right corner of its relatively positioned parent.

Fixed Positioning

Finally, fixed positioning behaves a lot like absolute positioning, but with one major difference: it’s always positioned relative to the browser window, not any parent element. That means a fixed element stays put even when the user scrolls.

This technique is often used for things like sticky navigation bars, chat buttons, or "back to top" links.

Example:

<div style="position: fixed; bottom: 10px; right: 10px;">Fixed at bottom-right corner!</div>

No matter how far you scroll, this fixed element will remain anchored to the bottom-right of your screen.

Conclusion

Learning how static, relative, absolute, and fixed positioning works is a major milestone for any new developer. This CSS tutorial explained each type clearly, making it easier to decide which positioning strategy best fits your layout goals.

If you’re following a CSS tutorial for beginners, practicing with small examples and slowly experimenting with combining different positioning types will solidify your understanding. Positioning is what transforms a page from a basic list of elements into a thoughtfully arranged, professional-looking design.

Keep practicing and experimenting — soon, positioning elements will become second nature!

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Jetbrains Survey

Calling all developers!

Participate in the Developer Ecosystem Survey 2025 and get the chance to win a MacBook Pro, an iPhone 16, or other exciting prizes. Contribute to our research on the development landscape.

Take the survey

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️