Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

CSS property `overflow-anchor`

`overflow-anchor` decides whether the browser compensates for layout changes above the current scroll position.

Version: CSS modules; captured CSSWG editor index includes draft and obsolete features requiring review

Syntax

auto | none

overflow-anchor decides whether the browser compensates for layout changes above the current scroll position.

Two identical scrollers receive new content before the view; the example compares the scrollTop change for auto and none.

Grammar: auto | none. This example does not replace wheel and touch testing on the target device.

The algorithm selects an anchor heuristically and suppresses compensation after some explicit scrolling; none applies to the whole subtree.

Examples

<!doctype html>
<html lang="en"><meta charset="utf-8"><title>CKTIS CSS reference example</title><body><pre id="result"></pre><script>
const make=value=>{const x=document.createElement("div"),body=document.createElement("div"),spacer=document.createElement("div"),anchor=document.createElement("b"),tail=document.createElement("div");x.style.cssText="width:80px;height:40px;overflow:auto;overflow-anchor:"+value;spacer.style.height="100px";anchor.style.cssText="display:block;height:20px";anchor.textContent="anchor";tail.style.height="120px";body.append(spacer,anchor,tail);x.append(body);document.body.prepend(x);x.scrollTop=100;void x.offsetHeight;const before=x.scrollTop;const added=document.createElement("div");added.style.height="20px";body.prepend(added);void x.offsetHeight;return [before,x.scrollTop]};const a=make("auto"),n=make("none");document.querySelector("#result").textContent="auto="+a.join("->")+"; none="+n.join("->");
</script></body></html>

Result

auto=100->120; none=100->100

The example was executed locally in an isolated, network-free Chrome session; the result comes from the browser CSS API.

Sources