concept

sticky-positioning — CSS reference

Sticky offsets are bounded by a scrollport and the box’s containing block. The box stays in flow. If both insets on an axis are auto, no sticky adjustment occurs on that axis.

Formal Syntax & Structure

css syntaxcss
position: sticky; inset-block-start: 0;

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS positioning lab</title><style>body {margin:0} .sample {background:#dcebe9;color:#182e32}#p{width:240px;height:160px;background:#e6eef2} #a{width:60px;height:30px;background:#128579} #b{height:20px;background:#adcde8}#p{overflow:auto;height:100px}#a{position:sticky;top:10px}</style><body><div id="p"><div style="height:50px"></div><div id="a">Sticky</div><div style="height:300px"></div></div></body></html>
CSS Reference