CSS recipes for @media and @container

Copy the HTML and CSS from the examples. Plain and nested CSS are two ways to write the same recipe. Each example starts with base styles that keep the content available when its condition does not match.

@media

Read the @media guide

@media (width >= 600px)

@media (width >= 600px)
<article class="card">
  <section>
    <h2>First section</h2>
    <p>Content starts in one column.</p>
  </section>
  <section>
    <h2>Second section</h2>
    <p>The viewport decides when two columns fit.</p>
  </section>
</article>
.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  font: 1rem / 1.5 system-ui;
  overflow-wrap: anywhere;
}

@media (width >= 600px) {
  .card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  font: 1rem / 1.5 system-ui;
  overflow-wrap: anywhere;

  @media (width >= 600px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-color-scheme: dark)

@media (prefers-color-scheme: dark)
<div class="preference-example">The condition adapts the style of this content.</div>
.preference-example {
  padding: 1rem;
  border: 2px solid currentColor;
}

@media (prefers-color-scheme: dark) {
  .preference-example {
    background: #202124;
    color: #fff;
  }
}
.preference-example {
  padding: 1rem;
  border: 2px solid currentColor;

  @media (prefers-color-scheme: dark) {
    background: #202124;
    color: #fff;
  }
}

@media (pointer: fine)

@media (pointer: fine)
<details>
  <summary class="interaction-action">Open the example content</summary>
  <p>Open this content with a click, tap, Enter or Space. Access remains available without hover or a pointer.</p>
</details>
.interaction-action {
  min-block-size: 2.75rem;
  padding: 0.5rem 1rem;
  border: 2px solid currentColor;
}

.interaction-action:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 3px;
}

@media (pointer: fine) {
  .interaction-action {
    border-width: 4px;
    border-style: double;
  }
}
.interaction-action {
  min-block-size: 2.75rem;
  padding: 0.5rem 1rem;
  border: 2px solid currentColor;

  @media (pointer: fine) {
    border-width: 4px;
    border-style: double;
  }
}

.interaction-action:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 3px;
}

@media (color >= 8)

@media (color >= 8)
<p class="output-sample">The border changes from dashed to double when the query applies. This is a CSS signal, not a color quality or HDR test.</p>
.output-sample {
  border: 2px dashed currentColor;
  padding: 1rem;
}

@media (color >= 8) {
  .output-sample {
    border-width: 6px;
    border-style: double;
  }
}
.output-sample {
  border: 2px dashed currentColor;
  padding: 1rem;

  @media (color >= 8) {
    border-width: 6px;
    border-style: double;
  }
}

@media (scripting: enabled)

@media (scripting: enabled)
<p class="environment-sample">A double border means this environment query applies; the dashed border keeps content available when it does not.</p>
.environment-sample {
  border: 2px dashed currentColor;
  padding: 1rem;
}

@media (scripting: enabled) {
  .environment-sample {
    border-width: 6px;
    border-style: double;
  }
}
.environment-sample {
  border: 2px dashed currentColor;
  padding: 1rem;

  @media (scripting: enabled) {
    border-width: 6px;
    border-style: double;
  }
}

@media print

@media print
<article class="print-document">
  <h1>CSS query notes</h1>
  <nav class="screen-only" aria-label="Skip to content">
    <a href="#print-section-1">Skip to content</a>
  </nav>
  <p>A reusable document preserves its content from screen to paper. Navigation is useful on screen; text and link destinations should remain available in the printed version.</p>
  <div class="print-sections" id="print-section-1" tabindex="-1">
    <section>
      <h2>Section 1</h2>
      <p>Review the content in reading order. On screen, sections use columns when space allows. For printing, the document returns to block flow and requests that each section stay together. The browser may split a block that cannot fit on a page; paper size, scale and margins change the result.</p>
      <p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Media_queries/Printing">Read the printing guide</a> <span class="print-link-url">(https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Media_queries/Printing)</span></p>
    </section>
    <section>
      <h2>Section 2</h2>
      <p>Review the content in reading order. On screen, sections use columns when space allows. For printing, the document returns to block flow and requests that each section stay together. The browser may split a block that cannot fit on a page; paper size, scale and margins change the result.</p>
      <p><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Media_queries/Printing">Read the printing guide</a> <span class="print-link-url">(https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Media_queries/Printing)</span></p>
    </section>
  </div>
</article>
.print-document {
  font: 1rem / 1.5 system-ui;
  overflow-wrap: anywhere;
}

.print-document .print-sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 1rem;
}

.print-document .print-link-url {
  display: none;
}

@media print {
  .print-document .screen-only {
    display: none;
  }
  
  .print-document .print-sections {
    display: block;
  }
  
  .print-document .print-sections section {
    break-inside: avoid;
  }
  
  .print-document h2 {
    break-after: avoid;
  }
  
  .print-document .print-link-url {
    display: inline;
  }
}
.print-document {
  font: 1rem / 1.5 system-ui;
  overflow-wrap: anywhere;

  .print-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
    gap: 1rem;
  }

  .print-link-url {
    display: none;
  }

  @media print {
    & .screen-only {
      display: none;
    }
    
    & .print-sections {
      display: block;
    }
    
    & .print-sections section {
      break-inside: avoid;
    }
    
    & h2 {
      break-after: avoid;
    }
    
    & .print-link-url {
      display: inline;
    }
  }
}

@media (width >= 600px) → @media (scripting: enabled)

@media (width >= 600px) → @media (scripting: enabled)
<article class="card">
  <section>
    <h2>First section</h2>
    <p>Content starts in one column.</p>
  </section>
  <section>
    <h2>Second section</h2>
    <p>The viewport decides when two columns fit.</p>
  </section>
</article>
.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  font: 1rem / 1.5 system-ui;
  overflow-wrap: anywhere;
}

@media (width >= 600px) {
  @media (scripting: enabled) {
    .card {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }
}
.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  font: 1rem / 1.5 system-ui;
  overflow-wrap: anywhere;

  @media (width >= 600px) {
    @media (scripting: enabled) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }
}

@container

Read the @container guide

@container (width >= 400px)

@container (width >= 400px)
<div class="outer">
  <div class="box box-a">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>

<div class="outer">
  <div class="box box-b">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>
.outer {
  container: layout / normal;
  inline-size: 720px;
}

.box {
  container-name: card;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;
}

@container (width >= 400px) {
  .card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}
.outer {
  container: layout / normal;
  inline-size: 720px;
}

.box {
  container-name: card;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;

  @container (width >= 400px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}

@container card

@container card
<div class="outer">
  <div class="box box-a">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>

<div class="outer">
  <div class="box box-b">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>
.outer {
  container: layout / normal;
  inline-size: 720px;
}

.box {
  container-name: card;
  container-type: normal;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;
}

@container card {
  .card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}
.outer {
  container: layout / normal;
  inline-size: 720px;
}

.box {
  container-name: card;
  container-type: normal;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;

  @container card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}

@container (width >= 400px) and (height >= 250px)

@container (width >= 400px) and (height >= 250px)
<div class="outer">
  <div class="box box-a">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>

<div class="outer">
  <div class="box box-b">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>
.outer {
  container: layout / size;
  inline-size: 720px;
  block-size: 300px;
}

.box {
  container-name: card;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;
}

@container (width >= 400px) and (height >= 250px) {
  .card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}
.outer {
  container: layout / size;
  inline-size: 720px;
  block-size: 300px;
}

.box {
  container-name: card;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;

  @container (width >= 400px) and (height >= 250px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}

@container layout (height >= 250px) → @container card (width >= 400px)

@container layout (height >= 250px) → @container card (width >= 400px)
<div class="outer">
  <div class="box box-a">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>

<div class="outer">
  <div class="box box-b">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>
.outer {
  container: layout / size;
  inline-size: 720px;
  block-size: 300px;
}

.box {
  container-name: card;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;
}

@container layout (height >= 250px) {
  @container card (width >= 400px) {
    .card {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      border-style: double;
    }
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}
.outer {
  container: layout / size;
  inline-size: 720px;
  block-size: 300px;
}

.box {
  container-name: card;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;

  @container layout (height >= 250px) {
    @container card (width >= 400px) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      border-style: double;
    }
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}

@container card (width >= 400px), layout (height >= 250px)

@container card (width >= 400px), layout (height >= 250px)
<div class="outer">
  <div class="box box-a">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>

<div class="outer">
  <div class="box box-b">
    <article class="card">
      <h3>The same component</h3>
      <p>CSS adapts this content to the available space.</p>
      <p class="measure">20cqi</p>
    </article>
  </div>
</div>
.outer {
  container: layout / size;
  inline-size: 720px;
  block-size: 300px;
}

.box {
  container-name: card component;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;
}

@container card (width >= 400px), layout (height >= 250px) {
  .card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}
.outer {
  container: layout / size;
  inline-size: 720px;
  block-size: 300px;
}

.box {
  container-name: card component;
  container-type: inline-size;
  writing-mode: horizontal-tb;
  font-size: 16px;
  box-sizing: content-box;
  padding: 16px;
  border: 2px solid;
}

.box-a {
  inline-size: 280px;
  block-size: 180px;
}

.box-b {
  inline-size: 560px;
  block-size: 180px;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;

  @container card (width >= 400px), layout (height >= 250px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

.measure {
  inline-size: 20px;
  inline-size: 20cqi;
  border-block-end: 4px solid;
}

@container card-context (style(--accent: red) or style(--density: compact)) and (inline-size >= 400px)

@container card-context (style(--accent: red) or style(--density: compact)) and (inline-size >= 400px)
<div class="contexts">
  <div class="context context-a">
    <article class="card">
      <h3>The same component</h3>
      <p>This card adapts to the CSS context of its box.</p>
    </article>
  </div>
  <div class="context context-b">
    <article class="card">
      <h3>The same component</h3>
      <p>This card adapts to the CSS context of its box.</p>
    </article>
  </div>
</div>
.context {
  container-name: card-context;
  container-type: inline-size;
}

.context-a {
  inline-size: 280px;
  --density: comfortable;
  --accent: red;
}

.context-b {
  inline-size: 560px;
  --density: compact;
  --accent: blue;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;
}

@container card-context (style(--accent: red) or style(--density: compact)) and (inline-size >= 400px) {
  .card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}
.context {
  container-name: card-context;
  container-type: inline-size;
}

.context-a {
  inline-size: 280px;
  --density: comfortable;
  --accent: red;
}

.context-b {
  inline-size: 560px;
  --density: compact;
  --accent: blue;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;

  @container card-context (style(--accent: red) or style(--density: compact)) and (inline-size >= 400px) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

@container card-context style(500ms <= --level < 2s)

@container card-context style(500ms <= --level < 2s)
<div class="contexts">
  <div class="context context-a">
    <article class="card">
      <h3>The same component</h3>
      <p>This card adapts to the CSS context of its box.</p>
    </article>
  </div>
  <div class="context context-b">
    <article class="card">
      <h3>The same component</h3>
      <p>This card adapts to the CSS context of its box.</p>
    </article>
  </div>
</div>
.context {
  container-name: card-context;
}

.context-a {
  inline-size: 280px;
  --density: comfortable;
  --level: 2s;
}

.context-b {
  inline-size: 560px;
  --density: compact;
  --level: 1s;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;
}

@container card-context style(500ms <= --level < 2s) {
  .card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}
.context {
  container-name: card-context;
}

.context-a {
  inline-size: 280px;
  --density: comfortable;
  --level: 2s;
}

.context-b {
  inline-size: 560px;
  --density: compact;
  --level: 1s;
}

.card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  overflow-wrap: anywhere;
  border: 2px dashed;

  @container card-context style(500ms <= --level < 2s) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-style: double;
  }
}

@container scroll-demo scroll-state(scrollable: block-end)

@container scroll-demo scroll-state(scrollable: block-end)
<div class="scroll-region scroll-query" role="region" aria-label="Scrollable region" tabindex="0" dir="ltr">
  <div class="scroll-track">
    <p class="scroll-panel">Panel 1</p>
    <p class="scroll-panel">Panel 2</p>
    <p class="scroll-panel">Panel 3</p>
  </div>
</div>
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;
}

@container scroll-demo scroll-state(scrollable: block-end) {
  .scroll-panel {
    border-style: double;
  }
}
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;

  @container scroll-demo scroll-state(scrollable: block-end) {
    border-style: double;
  }
}

@container scroll-demo scroll-state(stuck: block-start)

@container scroll-demo scroll-state(stuck: block-start)
<div class="scroll-region" role="region" aria-label="Sticky heading" tabindex="0" dir="ltr">
  <div class="scroll-track">
    <p class="scroll-start">Start</p>
    <header class="scroll-sticky scroll-query">
      <p class="scroll-panel">Sticky heading</p>
    </header>
    <p class="scroll-end">End</p>
  </div>
</div>
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

.scroll-sticky {
  position: sticky;
  inset-block-start: 0;
  grid-area: 1 / 1 / -1 / -1;
  place-self: center;
  z-index: 1;
}

.scroll-start,
.scroll-end {
  grid-area: 1 / 1 / -1 / -1;
  margin: 0;
  padding: 0.5em;
}

.scroll-start {
  place-self: start;
}

.scroll-end {
  place-self: end;
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;
}

@container scroll-demo scroll-state(stuck: block-start) {
  .scroll-panel {
    border-style: double;
  }
}
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

.scroll-sticky {
  position: sticky;
  inset-block-start: 0;
  grid-area: 1 / 1 / -1 / -1;
  place-self: center;
  z-index: 1;
}

.scroll-start,
.scroll-end {
  grid-area: 1 / 1 / -1 / -1;
  margin: 0;
  padding: 0.5em;
}

.scroll-start {
  place-self: start;
}

.scroll-end {
  place-self: end;
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;

  @container scroll-demo scroll-state(stuck: block-start) {
    border-style: double;
  }
}

@container scroll-demo scroll-state(snapped: inline)

@container scroll-demo scroll-state(snapped: inline)
<div class="scroll-region" role="region" aria-label="Snap panels" tabindex="0" dir="ltr">
  <div class="scroll-track">
    <div class="scroll-snap scroll-query">
      <p class="scroll-panel">Panel 1</p>
    </div>
    <div class="scroll-snap scroll-query">
      <p class="scroll-panel">Panel 2</p>
    </div>
    <div class="scroll-snap scroll-query">
      <p class="scroll-panel">Panel 3</p>
    </div>
  </div>
</div>
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
  scroll-snap-type: inline mandatory;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 300%;
  block-size: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(1, minmax(0, 1fr));
}

.scroll-snap {
  display: grid;
  scroll-snap-align: start;
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;
}

@container scroll-demo scroll-state(snapped: inline) {
  .scroll-panel {
    border-style: double;
  }
}
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
  scroll-snap-type: inline mandatory;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 300%;
  block-size: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(1, minmax(0, 1fr));
}

.scroll-snap {
  display: grid;
  scroll-snap-align: start;
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;

  @container scroll-demo scroll-state(snapped: inline) {
    border-style: double;
  }
}

@container scroll-demo scroll-state((scrolled: block-end) and (scrollable: block-end)) and (inline-size >= 128px)

@container scroll-demo scroll-state((scrolled: block-end) and (scrollable: block-end)) and (inline-size >= 128px)
<div class="scroll-region scroll-query" role="region" aria-label="Region for testing scroll direction" tabindex="0" dir="ltr">
  <div class="scroll-track">
    <p class="scroll-panel">Panel 1</p>
    <p class="scroll-panel">Panel 2</p>
    <p class="scroll-panel">Panel 3</p>
  </div>
</div>
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

@supports (container-type: inline-size scroll-state) {
  .scroll-query {
    container: scroll-demo / inline-size scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;
}

@container scroll-demo scroll-state((scrolled: block-end) and (scrollable: block-end)) and (inline-size >= 128px) {
  .scroll-panel {
    border-style: double;
  }
}
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

@supports (container-type: inline-size scroll-state) {
  .scroll-query {
    container: scroll-demo / inline-size scroll-state;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;

  @container scroll-demo scroll-state((scrolled: block-end) and (scrollable: block-end)) and (inline-size >= 128px) {
    border-style: double;
  }
}

@container scroll-demo scroll-state(scrolled: block-end) and style(--density: compact)

@container scroll-demo scroll-state(scrolled: block-end) and style(--density: compact)
<div class="scroll-region scroll-query" role="region" aria-label="Region for testing scroll direction" tabindex="0" dir="ltr">
  <div class="scroll-track">
    <p class="scroll-panel">Panel 1</p>
    <p class="scroll-panel">Panel 2</p>
    <p class="scroll-panel">Panel 3</p>
  </div>
</div>
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
    --density: compact;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;
}

@container scroll-demo scroll-state(scrolled: block-end) and style(--density: compact) {
  .scroll-panel {
    border-style: double;
  }
}
.scroll-region {
  writing-mode: horizontal-tb;
  inline-size: 12rem;
  block-size: 12rem;
  max-width: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid;
}

.scroll-region:focus-visible {
  outline: 2px solid Highlight;
  outline-offset: 2px;
}

.scroll-track {
  display: grid;
  inline-size: 100%;
  block-size: 300%;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
}

@supports (container-type: scroll-state) {
  .scroll-query {
    container: scroll-demo / scroll-state;
    --density: compact;
  }
}

.scroll-panel {
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0.5em;
  overflow-wrap: anywhere;
  border: 3px dashed;
  background: Canvas;

  @container scroll-demo scroll-state(scrolled: block-end) and style(--density: compact) {
    border-style: double;
  }
}

@container hint anchored(fallback: flip-block) and (inline-size >= 5rem)

@container hint anchored(fallback: flip-block) and (inline-size >= 5rem)
<div class="anchor-stage">
  <span class="anchor-point" role="img" aria-label="Anchor"></span>
  <div class="anchor-panel">
    <p class="anchor-content">Anchored panel</p>
  </div>
</div>
.anchor-stage {
  position: relative;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 0.5rem;
  box-sizing: border-box;
  block-size: 14rem;
  padding: 0.5rem;
  border: 1px solid;
}

.anchor-point {
  display: block;
  box-sizing: border-box;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  border: 3px solid;
  border-radius: 50%;
}

.anchor-panel {
  inline-size: 7rem;
  max-inline-size: 100%;
}

.anchor-stage {
  direction: ltr;
}

@supports (anchor-name: --point) and (position-anchor: --point) and (position-area: top) and (position-try-fallbacks: flip-block) {
  .anchor-stage > .anchor-point {
    position: absolute;
    anchor-name: --point;
    inset-inline-start: calc(50% - 0.75rem);
    inset-block-start: 0.5rem;
  }

  .anchor-stage > .anchor-panel {
    position: absolute;
    position-anchor: --point;
    position-area: top;
    max-inline-size: none;
    position-try-fallbacks: flip-block;
    container: hint / inline-size anchored;
  }
}

.anchor-content {
  box-sizing: border-box;
  min-block-size: 3rem;
  margin: 0;
  padding: 0.5rem;
  border: 3px dashed;
  overflow-wrap: anywhere;
}

@container hint anchored(fallback: flip-block) and (inline-size >= 5rem) {
  .anchor-content {
    border-style: double;
  }
}
.anchor-stage {
  position: relative;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 0.5rem;
  box-sizing: border-box;
  block-size: 14rem;
  padding: 0.5rem;
  border: 1px solid;
}

.anchor-point {
  display: block;
  box-sizing: border-box;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  border: 3px solid;
  border-radius: 50%;
}

.anchor-panel {
  inline-size: 7rem;
  max-inline-size: 100%;
}

.anchor-stage {
  direction: ltr;
}

@supports (anchor-name: --point) and (position-anchor: --point) and (position-area: top) and (position-try-fallbacks: flip-block) {
  .anchor-stage > .anchor-point {
    position: absolute;
    anchor-name: --point;
    inset-inline-start: calc(50% - 0.75rem);
    inset-block-start: 0.5rem;
  }

  .anchor-stage > .anchor-panel {
    position: absolute;
    position-anchor: --point;
    position-area: top;
    max-inline-size: none;
    position-try-fallbacks: flip-block;
    container: hint / inline-size anchored;
  }
}

.anchor-content {
  box-sizing: border-box;
  min-block-size: 3rem;
  margin: 0;
  padding: 0.5rem;
  border: 3px dashed;
  overflow-wrap: anywhere;

  @container hint anchored(fallback: flip-block) and (inline-size >= 5rem) {
    border-style: double;
  }
}

@container hint anchored(not (fallback: none)) and style(--density: compact)

@container hint anchored(not (fallback: none)) and style(--density: compact)
<div class="anchor-stage">
  <span class="anchor-point" role="img" aria-label="Anchor"></span>
  <div class="anchor-panel">
    <p class="anchor-content">Anchored panel</p>
  </div>
</div>
.anchor-stage {
  position: relative;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 0.5rem;
  box-sizing: border-box;
  block-size: 14rem;
  padding: 0.5rem;
  border: 1px solid;
}

.anchor-point {
  display: block;
  box-sizing: border-box;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  border: 3px solid;
  border-radius: 50%;
}

.anchor-panel {
  inline-size: 7rem;
  max-inline-size: 100%;
}

.anchor-panel {
  --density: compact;
}

.anchor-stage {
  direction: ltr;
}

@supports (anchor-name: --point) and (position-anchor: --point) and (position-area: top) and (position-try-fallbacks: flip-block) {
  .anchor-stage > .anchor-point {
    position: absolute;
    anchor-name: --point;
    inset-inline-start: calc(50% - 0.75rem);
    inset-block-start: 0.5rem;
  }

  .anchor-stage > .anchor-panel {
    position: absolute;
    position-anchor: --point;
    position-area: top;
    max-inline-size: none;
    position-try-fallbacks: flip-block;
    container: hint / anchored;
  }
}

.anchor-content {
  box-sizing: border-box;
  min-block-size: 3rem;
  margin: 0;
  padding: 0.5rem;
  border: 3px dashed;
  overflow-wrap: anywhere;
}

@container hint anchored(not (fallback: none)) and style(--density: compact) {
  .anchor-content {
    border-style: double;
  }
}
.anchor-stage {
  position: relative;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 0.5rem;
  box-sizing: border-box;
  block-size: 14rem;
  padding: 0.5rem;
  border: 1px solid;
}

.anchor-point {
  display: block;
  box-sizing: border-box;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  border: 3px solid;
  border-radius: 50%;
}

.anchor-panel {
  inline-size: 7rem;
  max-inline-size: 100%;
}

.anchor-panel {
  --density: compact;
}

.anchor-stage {
  direction: ltr;
}

@supports (anchor-name: --point) and (position-anchor: --point) and (position-area: top) and (position-try-fallbacks: flip-block) {
  .anchor-stage > .anchor-point {
    position: absolute;
    anchor-name: --point;
    inset-inline-start: calc(50% - 0.75rem);
    inset-block-start: 0.5rem;
  }

  .anchor-stage > .anchor-panel {
    position: absolute;
    position-anchor: --point;
    position-area: top;
    max-inline-size: none;
    position-try-fallbacks: flip-block;
    container: hint / anchored;
  }
}

.anchor-content {
  box-sizing: border-box;
  min-block-size: 3rem;
  margin: 0;
  padding: 0.5rem;
  border: 3px dashed;
  overflow-wrap: anywhere;

  @container hint anchored(not (fallback: none)) and style(--density: compact) {
    border-style: double;
  }
}