MDN self-hosted library · e01.org

Using container scroll-state queries

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

css
.container {
  container-type: scroll-state;
  container-name: my-container;
}
css
@container my-container scroll-state(scrollable: top) {
  /* CSS rules go here */
}
html
<a class="back-to-top" href="#" aria-label="Top of page">↑</a>
<article>
  <h1>Reader with container query-controlled "back-to-top" link</h1>
  <section>
    <header>
      <h2>This first section is interesting</h2>

      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
    </header>

    ...
  </section>

  ...
</article>