CKTIS / CSS
top — top inset
The top property specifies a positioned element’s top inset. Its meaning depends on position; it has no effect with static.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
top: auto | <length-percentage>;
For an absolutely positioned element (including `position: fixed`), the `<length-percentage>` value can use `anchor()` or `anchor-size()`, subject to the rules of CSS Anchor Positioning.top refers to the physical top. It is not inherited; its initial auto does not simply mean zero. Lengths, percentages, and negative values are allowed.
With relative, it shifts the element from its original position, preserving its space. With absolute and fixed, it specifies an inset from the containing block; for fixed, this is usually the viewport, but not always.
With sticky, it sets a top threshold relative to the nearest scrollport, constrained by the containing block. Percentages reference the containing block’s height, or the scrollport’s height for sticky.
In the example, top: 25% gives 30px because the container is 120px tall. With position: static, the property has no effect.
Examples
<!doctype html>
<meta charset="utf-8">
<title>top</title>
<style>
.container {
position: relative;
width: 200px;
height: 120px;
background: #eee;
}
.box {
position: absolute;
top: 25%;
left: 0;
width: 40px;
height: 40px;
margin: 0;
background: #1565c0;
}
</style>
<div class="container"><div class="box"></div></div>Result
box top − container top = 30 CSS px
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.