Mastering CSS Positioning

Go beyond the default flow. Learn to control the exact placement of any element with `static`, `relative`, `absolute`, `fixed`, and `sticky`.

Lesson ProgressStep 1 of 8
Box 1
Box 2
Box 3
Box 4
0 EXP

Welcome! Let's explore CSS `position`. This property controls how elements are placed on the page.

.box { position: static; } /* This is the default */

The Default: position: static

This is the default value for every HTML element. It means the element will follow the normal document flow—block elements will stack vertically, and inline elements will flow horizontally.

You almost never need to write position: static;, but it's the baseline you need to understand. Importantly, the properties top, right, bottom, left, and z-index have no effect on a static element.

System Check

Which of these properties will NOT work on an element with `position: static`?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🏆
Position Master

Correctly use `position: absolute` in a `relative` container.

🏗️
Flow Controller

Use all 5 `position` properties in the skill tree.

✍️
Viewport Captain

Correctly identify `fixed` and `sticky` properties.

Mission: Build a Positioned Layout

Create a layout where `.child` is positioned absolutely within its `.parent`. Give the `.parent` `position: relative` and the `.child` `position: absolute` with `top` and `left` properties.

A.D.A. Feedback:

> System integrity looks stable. Code is valid.

Challenge: Order the Positions

Drag the properties into a logical order, from the default flow to the most detached from the flow.

position: relative; (Stays in flow, can be nudged)
position: static; (Default document flow)
position: fixed; (Sticks to the browser window)
position: absolute; (Removed from flow, relative to ancestor)

Challenge: Complete the Syntax

Fill in the missing properties to make a sticky header and a fixed footer.

.header { position: ; ; }
.footer { position: ; bottom: 0; }

Consult A.D.A.

Community Holo-Net

Mastering the Flow: A Deep Dive into CSS Positioning

In CSS, every element lives in a predictable order called thenormal document flow. By default, block-level elements stack vertically, and inline elements flow horizontally. But what if you want to break that flow? What if you need a notification to pop up over everything, or a sidebar to stay put while the content scrolls? This is where the position property comes in. It's the single most powerful tool you have for controlling layout and creating complex, dynamic interfaces.

The Baseline: position: static

This is the default value for every element. It simply means "stay in the normal document flow." An element with position: staticwill be placed exactly where it appears in the HTML, following the standard stacking order. It's important to remember that top, right, bottom,left, and z-index have no effect on a statically positioned element. It's the "control group" of positioning.

The Nudge: position: relative

This is where things get interesting. When you set an element toposition: relative, it still occupies its original space in the normal flow. However, you can now use top, left, etc., to "nudge" it from that original spot. If you set top: 20px, it will move down 20px from where itwould have been.

But relative has a second, secret power that is even more important: it creates a new positioning context. This means it becomes an "anchor" for any descendant elements that are set to position: absolute. This is the most common and critical concept to grasp for modern CSS layouts.

The Great Escape: position: absolute

This value completely removes the element from the normal document flow. Other elements will behave as if it doesn't even exist. Once removed, the element looks for an "anchor" to position itself against. It searches up its ancestors for the nearest one that has a position value other thanstatic (i.e., relative, absolute, fixed, or sticky).

If it finds one, it positions itself relative to that ancestor's padding-box. If it finds *no* positioned ancestor, it positions itself relative to the initial containing block, which is usually the <body> or <html> element (and often the browser viewport).

✔️ Good Practice

.parent {
  position: relative;
}
.child {
  position: absolute;
  top: 0;
  left: 0;
}

The child is anchored to its parent.

❌ Bad Practice

.parent {
  /* position: static; */
}
.child {
  position: absolute;
  top: 0;
  left: 0;
}

The child will ignore the parent and anchor to the body.

The Viewport Sticker: position: fixed

Like absolute, a fixed element is removed from the normal flow. The key difference is that it *always* positions itself relative to the browser viewport. This means it does not move when the page is scrolled. This is perfect for creating modal pop-ups, "Back to Top" buttons, and navigation bars that should always be visible.

The Smart Sticker: position: sticky

This is the modern hybrid of relative and fixed. A sticky element is treated as relative (it stays in the normal flow) until its container is scrolled to a specific point (defined by top,left, etc.).

For example, position: sticky; top: 0; will make an element scroll normally until it hits the top of the viewport, at which point it will "stick" there (behaving like fixed) as the rest of the content scrolls past it. This is ideal for section headers in an article or a sidebar that should scroll until it hits the top.

The 3rd Dimension: z-index
Once you use any position other than static, you can apply a z-index. This property controls the stacking order (which elements appear "on top" of others). A higher z-indexvalue will appear on top of a lower one. This is essential for drop-down menus, modals, and any overlapping content.

CSS Positioning & Layout Glossary

position
The core CSS property that specifies the type of positioning method used for an element. Its value determines how an element is placed in the document and how it interacts with other elements.
position: static
The default value. The element is positioned according to the Normal Document Flow. The top, right, bottom, left, and z-index properties have no effect.
position: relative
The element remains in the Normal Document Flow, but can be offset from its original position using top, right, bottom, and left. Most importantly, it creates a new Positioning Context for its descendant elements.
position: absolute
The element is removed from the Normal Document Flow. It is positioned relative to its nearest Positioned Ancestor. If no positioned ancestor exists, it is positioned relative to the initial containing block (usually the <html> element).
position: fixed
The element is removed from the Normal Document Flow. It is positioned relative to the Viewport, meaning it will stay in the same place even when the page is scrolled.
position: sticky
A hybrid of relative and fixed. The element is treated as relative until it scrolls to a specific offset threshold (e.g., top: 0), at which point it "sticks" and behaves like fixed.
Normal Document Flow
The default layout of elements on a page before any positioning is applied. Block-level elements stack vertically, and inline elements flow horizontally.
Positioning Context (Positioned Ancestor)
The element that an absolute element uses as its "anchor" for positioning. This is the nearest ancestor that has a position value of relative, absolute, fixed, or sticky.
Viewport
The user's visible area of the web page in the browser window. This is the "anchor" for fixed elements.
z-index
A property that controls the stacking order (depth, or z-axis) of positioned elements (any element not static). An element with a higher z-index will appear in front of an element with a lower one.
Offset Properties
The properties top, right, bottom, and left. They are used to specify the distance a non-static element should be offset from its anchor or original position.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching CSS and building robust and accessible web applications.

Verification and Updates

Last reviewed: November 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest CSS specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!