Web Development
HTML Course
CSS Course
JavaScript Course
PHP Course
Python Course
SQL Course
SEO Course

CSS Positioning

Positioning is an essential CSS technique that allows you to control where elements appear on the page. Unlike the normal document flow, where elements are stacked one under another, positioning gives you the freedom to move, fix, or overlap elements exactly where you need them. It is extremely useful for custom layouts, tooltips, banners, menus, notifications, and much more.

Types of Positioning

CSS offers five main types of positioning, each with different behaviors. Let's explain them one by one:

Example: relative positioning

In this example, the element is moved 20px down and 30px to the right from its initial position. Notice that the space it occupies in the page remains the same.

🔧 Live Example: relative positioning

Example: absolute positioning inside a relative container

Here we have a blue container with position: relative. The red element inside has position: absolute and is positioned relative to the top-right corner of the container. If we had not set relative on the container, the badge would have positioned itself relative to the entire page.

🔧 Live Example: absolute positioning

Example: fixed positioning

The banner below is fixed at the bottom of the screen. Even when you scroll the page, it remains visible. This technique is often used for notifications, navigation bars, or action buttons.

🔧 Live Example: fixed positioning

Example: sticky positioning

The header below behaves normally until it reaches the top of the viewport. Then it "sticks" and remains there while you scroll. This is ideal for section titles or menus that need to stay visible.

🔧 Live Example: sticky positioning

Best Practices

💡 Tip: Positioning is a powerful tool but should be used carefully. It does not replace modern layouts like Flex and Grid, but complements them in specific situations — such as badges, tooltips, banners, or floating elements.


🧠 Quiz – CSS Positioning

Top