Need to move elements exactly where you want them on the page? The CSS Position property gives you full control over where elements appear in your layout. In this MiniCoursey quick guide, you’ll learn how the different position values — static, relative, absolute, and fixed — work, when to use them, and how they interact with each other in real layouts.
What is the CSS Position Property?
The position property tells the browser how to place an element in the document flow. It affects how an element sits with other elements and how you can move it using top, right, bottom, and left properties.
Position: Static (Default)
By default, all elements are position: static
. This means they follow the normal flow of the document and can’t be moved with top, right, bottom, or left.
Position: Relative
position: relative
keeps the element in the normal flow but allows you to move it relative to its original position. Other elements stay in place.
.box {
position: relative;
top: 20px;
left: 10px;
}
Position: Absolute
position: absolute
removes the element from the normal flow and positions it relative to the nearest positioned ancestor (not static). If no ancestor is positioned, it uses the <html>
element.
.parent {
position: relative;
}
.child {
position: absolute;
top: 0;
right: 0;
}
Position: Fixed
position: fixed
anchors the element to the viewport. It stays in the same place even when the page scrolls — perfect for sticky headers or floating buttons.
.header {
position: fixed;
top: 0;
width: 100%;
}
💡 Pro Tip: Combine relative and absolute to create flexible card layouts or badges.
⚠️ Common Mistake: Using absolute positioning without a positioned parent often leads to unexpected placement.
FAQ
Q: What about sticky?
A: position: sticky
is like relative until a scroll threshold is met — then it sticks in place. Great for menus and sidebars!
Q: Can I mix positioning types?
A: Yes! Many layouts use a mix of static, relative, absolute, and fixed for different parts.
Related Link
👉 Check out previous: CSS Z-Index — How Layering Works
Where to Learn More
Use browser DevTools to experiment with positioning and see how elements move in real time. MDN has excellent examples and visual guides.
Conclusion
Congrats — you now know how to control element placement with CSS Position! Master this and your layouts will instantly level up.
✨ Bookmark MiniCoursey for more quick & free mini courses!