Learn CSS positioning step by step. Understand static, relative, absolute, fixed, sticky positioning and how z-index and stacking context work.
CSS Positioning & Z-Index Explained with Examples
In this lesson, you’ll master CSS positioning and z-index .
Positioning controls where elements live on the page ,
how they move, and how they stack on top of each other.
Most advanced layouts, dropdowns, modals, tooltips, sticky headers,
and floating buttons rely on position + z-index .
Info!
If you understand positioning properly, layout problems become much easier to fix.
1. CSS position Property
The position property defines how an element is placed in the document
and how it reacts to top , right , bottom , and left .
Main position values:
static (default) relative absolute fixed sticky 2. position: static (Default)
This is the default behavior of every HTML element.
Static elements follow the normal document flow.
top / left / right / bottom do not work Element cannot be layered using z-index ✏️ Edit ▶ Run <!DOCTYPE html>
<html>
<head>
<style>
.box {
position: static;
background: #e0f2fe;
padding: 16px;
}
</style>
</head>
<body>
<div class=…