overflow-anchor CSS property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The overflow-anchor CSS property provides a way to opt out of the browser's scroll anchoring behavior, which adjusts scroll position to minimize content shifts.

Scroll anchoring behavior is enabled by default in any browser that supports it. Therefore, changing the value of this property is typically only required if you are experiencing problems with scroll anchoring in a document or part of a document and need to turn the behavior off.

Try it

overflow-anchor: auto;
overflow-anchor: none;
<section class="default-example" id="default-example">
  <div class="whole-content-wrapper">
    <button id="playback" type="button">Start lottery</button>
    <p>Magic numbers for today are:</p>
    <div id="example-element"></div>
  </div>
</section>
.whole-content-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

#example-element {
  height: 100%;
  border: 2px dashed dodgerblue;
  padding: 0.75em;
  text-align: left;
  overflow: scroll;
}

#playback {
  font-size: 1em;
  width: 10em;
  height: 4em;
  font-weight: bold;
  margin: 1em auto;
  background-color: aliceblue;
  border: solid 2px dodgerblue;
  border-radius: 5px;
}

#playback:hover {
  border-color: lightseagreen;
}

#playback:active {
  filter: brightness(0.9);
}
const example = document.getElementById("example-element");
const button = document.getElementById("playback");
let intervalId;

function setInitialState() {
  example.innerHTML = "";
  Array.from({ length: 10 }, (_, i) => i).forEach(addContent);
  example.scrollTop = example.scrollHeight;
}

function addContent() {
  console.log("adding content");
  const magicNumber = Math.floor(Math.random() * 10000);
  example.insertAdjacentHTML(
    "afterbegin",
    `<div class="new-content-container">New Magic Number: ${magicNumber}</div>`,
  );
}

button.addEventListener("click", () => {
  if (example.classList.contains("running")) {
    example.classList.remove("running");
    button.textContent = "Start lottery";
    clearInterval(intervalId);
  } else {
    example.classList.add("running");
    button.textContent = "Stop lottery";
    setInitialState();
    intervalId = setInterval(addContent, 1000);
  }
});

Syntax

css
/* Keyword values */
overflow-anchor: auto;
overflow-anchor: none;

/* Global values */
overflow-anchor: inherit;
overflow-anchor: initial;
overflow-anchor: revert;
overflow-anchor: revert-layer;
overflow-anchor: unset;

Values

auto

The element becomes a potential anchor when adjusting scroll position.

none

The element won't be selected as a potential anchor.

Formal definition

Initial valueauto
Applies toall elements
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

overflow-anchor = 
auto |
none

Examples

Prevent scroll anchoring

To prevent scroll anchoring in a document, use the overflow-anchor property.

css
* {
  overflow-anchor: none;
}

Specifications

Specification
CSS Scroll Anchoring Module Level 1
# exclusion-api

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
overflow-anchor
Chrome – Full support
Chrome 56 (Release date: 2017-01-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 66 (Release date: 2019-03-19)
footnote Full support
Opera – Full support
Opera 43 (Release date: 2017-02-07)
footnote Full support
Safari – Preview support
Safari TP
footnote
footnote See bug 171099
footnote Preview browser support
Chrome Android – Full support
Chrome Android 56 (Release date: 2017-02-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 66 (Release date: 2019-03-19)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
auto
Chrome – Full support
Chrome 56 (Release date: 2017-01-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 66 (Release date: 2019-03-19)
footnote Full support
Opera – Full support
Opera 43 (Release date: 2017-02-07)
footnote Full support
Safari – No support
Safari
footnote
footnote See bug 171099
Chrome Android – Full support
Chrome Android 56 (Release date: 2017-02-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 66 (Release date: 2019-03-19)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 171099
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 171099
none
Chrome – Full support
Chrome 56 (Release date: 2017-01-25)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 66 (Release date: 2019-03-19)
footnote Full support
Opera – Full support
Opera 43 (Release date: 2017-02-07)
footnote Full support
Safari – No support
Safari
footnote
footnote See bug 171099
Chrome Android – Full support
Chrome Android 56 (Release date: 2017-02-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 66 (Release date: 2019-03-19)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote
footnote See bug 171099
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 56 (Release date: 2017-02-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote
footnote See bug 171099

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support
See implementation notes.

See also