Static Positioning
By the end of this lesson you will understand position: static, the value every element starts with. You will know how the browser places static boxes in the normal flow, why top, left and z-index seem to "do nothing" on them, and when you should set position: static on purpose to undo another rule.
CSS Position Property gave you a map of all five values. This lesson and the next four go through them one by one. We will build parts of one screen for an imaginary food-delivery app called TiffinGo, based in Pune. Here we start with its restaurant list.
What "static" really means
The word "static" sounds like "fixed in place", but that is not what it means in CSS. A static element is simply not positioned. The browser places it with the normal rules and nothing else.
Those normal rules are called the normal flow. You met them in Block vs Inline Elements:
- Block boxes, such as
<div>,<p>and<h2>, stack from top to bottom, each on a new line. - Inline content, such as text,
<a>and<span>, runs from left to right inside a line and wraps to the next line when it runs out of space. - Margins, padding and borders push neighbours apart, as you saw in CSS Box Model.
Think of people standing in a queue at a railway ticket counter. Each person stands right behind the one in front. Nobody chooses a spot on the platform; the queue decides. Static elements are that queue.
Every element starts as static, because it is the initial value of position. The property is also not inherited: setting position: relative on a card does not make its children relative.
/* You never need to write this for a fresh element. It is already true. */
.restaurant-card {
position: static;
}Why offsets do nothing
The offset properties top, right, bottom, left and the shorthand inset only apply to positioned elements, meaning any value except static. On a static element the browser stores the value but does not use it for layout.
The same goes for z-index on an ordinary static block: it has no effect. There is one exception you will meet soon. Flex items and grid items accept z-index even when they are static. Z-Index & Stacking Context covers that in detail.
Step 1: see offsets being ignored
Here is the first part of the TiffinGo restaurant list. A developer tried to move the "Pure veg" card down and bring it to the front with top, left and z-index.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Offsets on a static element</title>
<style>
body { font-family: system-ui, sans-serif; padding: 1rem; background: #fff8f0; }
.card {
max-width: 20rem;
padding: 0.8rem 1rem;
margin-bottom: 0.6rem;
border-radius: 10px;
background: white;
border: 1px solid #f0d9c4;
}
.veg {
top: 30px; /* ignored: the card is static */
left: 40px; /* ignored */
z-index: 10; /* ignored */
background: #e6f7ea;
}
</style>
</head>
<body>
<h2>Restaurants near Kothrud</h2>
<div class="card">Annapurna Mess: thali, ₹180</div>
<div class="card veg">Sattvik Kitchen: pure veg, ₹220</div>
<div class="card">Biryani Darbar: dum biryani, ₹260</div>
</body>
</html>What you should see: the three cards sit in a neat column. The green card has not moved at all, even though it has top: 30px and left: 40px. Now add position: relative; inside the .veg rule and run it again. The card shifts 30px down and 40px right, and it now paints over the card below it.
Step 2: check it in DevTools
Remove position: relative again. Right-click the green card, choose Inspect, and open the Computed tab. You will find top: 30px listed, so the value was accepted. It is simply not used. In the Styles tab, recent versions of Chrome, Edge and Firefox can show a small hint icon next to properties that have no effect, such as z-index on a static element. Hover the icon to read the reason. These hints save a lot of guessing.
Static versus relative with no offsets
A common question in reviews is: "This element has position: relative but no offsets. Why not just leave it static?" They look the same on screen, but they are not the same.
| Behaviour | static | relative with no offsets |
|---|---|---|
| Place in the normal flow | Yes | Yes, exactly the same spot |
| Offsets work | No | Yes |
z-index works | No (except flex and grid items) | Yes |
| Containing block for absolute children | No | Yes |
| Painting order | With normal content | Above static siblings |
The last two rows matter most. A relative element becomes the anchor for absolutely positioned children, and it is painted in a higher layer than its static neighbours. So relative is never "free". Use it when you need one of those effects, and leave other elements static.
Resetting position on purpose
Most of the time you never write position: static. You write it when another rule has already positioned an element and you want to undo that. There are two common cases.
Case 1: a layout change at a breakpoint. A sidebar might be position: sticky on wide screens. On a phone you want it back in the normal flow, so a media query resets it to static.
Case 2: moving the anchor for an absolute child. An absolute element is placed against its nearest positioned ancestor. If a shared style made an inner wrapper relative, the child anchors to that wrapper. Setting the wrapper back to static lets the child skip it and anchor to the next positioned ancestor further out.
Step 3: move a badge's anchor with a reset
In this TiffinGo card, a shared style makes every .thumb relative. The "20% off" badge should sit on the corner of the whole card, not on the small thumbnail.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Resetting position</title>
<style>
body { font-family: system-ui, sans-serif; padding: 1.5rem; background: #fff8f0; }
.thumb { position: relative; } /* shared style from another file */
.card {
position: relative;
display: flex;
gap: 0.8rem;
align-items: center;
max-width: 22rem;
padding: 0.8rem;
border-radius: 12px;
background: white;
border: 1px solid #f0d9c4;
}
.thumb { width: 64px; height: 64px; border-radius: 8px; background: #f4a261; }
.badge {
position: absolute;
top: -0.6rem;
right: -0.6rem;
padding: 0.2rem 0.5rem;
border-radius: 999px;
background: #c1121f;
color: white;
font-size: 0.8rem;
}
.card .thumb { position: static; } /* the reset: try deleting this line */
</style>
</head>
<body>
<div class="card">
<div class="thumb"><span class="badge">20% off</span></div>
<div>
<strong>Biryani Darbar</strong><br>
Dum biryani, 35 min
</div>
</div>
</body>
</html>What you should see: the red badge sits on the top-right corner of the white card. Delete the reset line and run again. The badge jumps to the corner of the orange thumbnail, because the thumbnail is now the nearest positioned ancestor.
Common mistakes
- Expecting
toporleftto move a static element. Nothing happens. Give it apositionfirst, or use margins or Flexbox if you only want spacing. - Raising
z-indexto 9999 on a static block. The number is ignored. The element must be positioned, or be a flex or grid item. - Adding
position: relativeto everything "just in case". It changes painting order and creates extra anchors, which leads to badges landing in the wrong place. - Reading "static" as "stays still on screen". That is
fixedorsticky. Static means "not positioned".
Interview questions
1. What is the default value of the position property?
The default is static. It is the initial value, and the property is not inherited, so every element is static unless a rule changes it. A static element is laid out by the normal flow.
2. Why does top: 20px have no effect on some elements?
Offset properties only apply to positioned elements, which means any position value except static. On a static element the value is computed but not used for layout. Set position: relative or another value, or use margins if you only need space.
3. Does z-index work on a static element?
Not on an ordinary static block. It does work on flex items and grid items even when they are static. For other elements you need a positioned value such as relative.
4. What is the difference between position: static and position: relative with no offsets?
Both occupy the same place in the normal flow. The relative element, however, becomes a containing block for absolutely positioned descendants, accepts z-index, and paints above static siblings. So it can change where children land and what overlaps what.
5. When would you write position: static explicitly?
To undo positioning set by another rule, for example to turn off a sticky sidebar on small screens, or to stop an inner wrapper from being the anchor for an absolute child. In new code without such a rule, you never need it.
Key points
staticis the initial value ofposition, andpositionis not inherited.- Static elements follow the normal flow: blocks stack, inline content wraps in lines.
top,right,bottom,leftandinsetdo nothing on static elements.z-indexhas no effect on static elements, except flex and grid items.relativewithout offsets looks the same but changes anchors and painting order.- Write
position: staticonly to reset positioning that another rule added.
Exercise
Build a TiffinGo "Top picks" list of three restaurant cards. A shared rule at the top of your CSS sets .card-media { position: relative; }. Put a "Bestseller" label inside .card-media in the second card and make it position: absolute; top: 0; right: 0;. First observe where the label lands. Then use a reset so the label anchors to the corner of the whole card instead. Finally, try top and z-index on one static card and confirm in DevTools that they are ignored.
Show solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Top picks</title>
<style>
.card-media { position: relative; } /* shared rule */
body { font-family: system-ui, sans-serif; padding: 1rem; }
.card { position: relative; display: flex; gap: 0.75rem; padding: 0.75rem;
margin-bottom: 0.75rem; max-width: 20rem; border: 1px solid #ddd; border-radius: 10px; }
.card-media { width: 56px; height: 56px; background: #e9c46a; border-radius: 8px; }
.label { position: absolute; top: 0; right: 0; background: #2a9d8f; color: white;
padding: 0.15rem 0.5rem; font-size: 0.8rem; border-radius: 0 10px 0 8px; }
.card .card-media { position: static; } /* reset: label anchors to .card */
.test { top: 50px; z-index: 5; } /* ignored: static */
</style>
</head>
<body>
<div class="card test"><div class="card-media"></div><p>Misal Corner, Shivajinagar</p></div>
<div class="card"><div class="card-media"><span class="label">Bestseller</span></div><p>Vada Pav Junction, Deccan</p></div>
<div class="card"><div class="card-media"></div><p>Kolhapuri Rassa, Baner</p></div>
</body>
</html>Without the reset, the label sits on the small media box. With .card .card-media { position: static; } the nearest positioned ancestor becomes .card, so the label moves to the card's corner. The .test card does not move, and DevTools marks its top and z-index as having no effect.
Quick Quiz
1. What is the initial value of position?
Every element starts as static, which means it is not positioned.
2. A static <div> (not a flex or grid item) has z-index: 50. What happens?
z-index needs a positioned element, or a flex or grid item.
3. Why might you write position: static on an inner wrapper?
Resetting the wrapper removes it as a containing block, so the absolute child looks further up.
4. Which statement about relative with no offsets is true?
A relative element keeps its spot in the flow but can anchor absolute descendants and accepts z-index.
Learn CSS with a mentor
Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
