Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

container-type — query container type

The `container-type` property enables queries about an element’s size, scroll state, or active anchor-positioning fallback. It lets descendant styles respond to a container rather than to the viewport.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

container-type: normal | [ [ size | inline-size ] || scroll-state || anchored ];
/* anchored enables container queries for the active anchor-positioning fallback. It can be used alone or combined with scroll-state and either size or inline-size, in any order. */

container-type determines which query types a container supports. Its initial value is normal; the property is neither inherited nor animatable. normal does not enable queries about size, scroll state, or the active anchor-positioning fallback, but leaves style queries available.

inline-size exposes the container’s inline-axis size: usually width in horizontal writing modes. size exposes both axes. Both values apply style containment, size containment in the corresponding axes, and establish an independent formatting context. Content does not determine sizing in the contained axes; especially with size, plan dimensions to avoid a collapsed container.

scroll-state enables scroll-state queries. Use it alone or combine it with size or inline-size, for example inline-size scroll-state. anchored enables queries about which anchor-positioning fallback is active. Use it alone or combine it with scroll-state, with either size or inline-size, or with both a scroll-state and a size keyword. The || operator permits the components in any order, each at most once. Do not combine size with inline-size, or normal with another value. CSS-wide keywords are also available.

An @container rule selects an eligible ancestor of the element being styled, not that element itself. container-name assigns a name independently of the type. In the example, the container is 320px wide, so its descendant text is green; at 280px it remains black. The definition moved from CSS Containment Level 3 to CSS Conditional Rules Level 5. Standard syntax does not replace verification in the target browser.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>container-type example</title>
<style>
  .panel {
    container-type: inline-size;
    writing-mode: horizontal-tb;
    width: 320px;
  }
  .card {
    margin: 0;
    color: black;
  }
  @container (inline-size >= 300px) {
    .card { color: green; }
  }
</style>
<div class="panel">
  <p class="card">Container query</p>
</div>
</html>

Result

Container query

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources