# Named conditions

Every preset media and container condition, its expanded query and the scope it measures.

- ID: rules/named-conditions
- Type: rule
- Canonical: /reference/rules/named-conditions
- Version: 2.1.8
- Source revision: 09fc2350ea80ed137ba7ca62c8e5926744b5a5dc (revision)
- Source: site/reference/named-conditions.ts
- Content digest: 2afca66b54a02031e0bc3feb7b1a2b30451b3c94395c0e0d2bad486994f07d1e
- Semantic digest: 83962260d6d56817dd052d2beebf7999a75804215dac050c47b26353145c099a
- Language: en

The preset defines independent media and container conditions. They share short names, but neither registry is a set of theme tokens. A bare `@md` queries the viewport; `@container(--md)` queries an eligible ancestor container.

<a id="conditions"></a>

## Media conditions

Media names come from `media.css`. Width conditions use their authored rem values; orientation and preference conditions use native media features. `@dark` and `@light` test the system preference, not a manually selected site theme.

<a id="viewport-widths"></a>

### Minimum viewport widths

| Suffix | Expanded query |
| --- | --- |
| <a id="condition-4xs"></a> `@4xs` | `(width >= 22.5rem)` |
| <a id="condition-3xs"></a> `@3xs` | `(width >= 30rem)` |
| <a id="condition-2xs"></a> `@2xs` | `(width >= 37.5rem)` |
| <a id="condition-xs"></a> `@xs` | `(width >= 48rem)` |
| <a id="condition-sm"></a> `@sm` | `(width >= 52.125rem)` |
| <a id="condition-md"></a> `@md` | `(width >= 64rem)` |
| <a id="condition-lg"></a> `@lg` | `(width >= 80rem)` |
| <a id="condition-xl"></a> `@xl` | `(width >= 90rem)` |
| <a id="condition-2xl"></a> `@2xl` | `(width >= 100rem)` |
| <a id="condition-3xl"></a> `@3xl` | `(width >= 120rem)` |
| <a id="condition-4xl"></a> `@4xl` | `(width >= 160rem)` |

<a id="below-viewport-widths"></a>

### Below viewport widths

| Suffix | Expanded query |
| --- | --- |
| <a id="condition-max-4xs"></a> `@max-4xs` | `not (width >= 22.5rem)` |
| <a id="condition-max-3xs"></a> `@max-3xs` | `not (width >= 30rem)` |
| <a id="condition-max-2xs"></a> `@max-2xs` | `not (width >= 37.5rem)` |
| <a id="condition-max-xs"></a> `@max-xs` | `not (width >= 48rem)` |
| <a id="condition-max-sm"></a> `@max-sm` | `not (width >= 52.125rem)` |
| <a id="condition-max-md"></a> `@max-md` | `not (width >= 64rem)` |
| <a id="condition-max-lg"></a> `@max-lg` | `not (width >= 80rem)` |
| <a id="condition-max-xl"></a> `@max-xl` | `not (width >= 90rem)` |
| <a id="condition-max-2xl"></a> `@max-2xl` | `not (width >= 100rem)` |
| <a id="condition-max-3xl"></a> `@max-3xl` | `not (width >= 120rem)` |
| <a id="condition-max-4xl"></a> `@max-4xl` | `not (width >= 160rem)` |

<a id="media-features"></a>

### Orientation and preferences

| Suffix | Expanded query |
| --- | --- |
| <a id="condition-dark"></a> `@dark` | `(prefers-color-scheme: dark)` |
| <a id="condition-landscape"></a> `@landscape` | `(orientation: landscape)` |
| <a id="condition-light"></a> `@light` | `(prefers-color-scheme: light)` |
| <a id="condition-motion-reduce"></a> `@motion-reduce` | `(prefers-reduced-motion: reduce)` |
| <a id="condition-motion-safe"></a> `@motion-safe` | `(prefers-reduced-motion: no-preference)` |
| <a id="condition-portrait"></a> `@portrait` | `(orientation: portrait)` |

<a id="container-conditions"></a>

## Container conditions

Container names come from `container.css`. The definition supplies only a query condition: `@container(--md)` uses the nearest eligible container, while `@container(card_--md)` selects an eligible container named `card`. Neither form establishes a container.

<a id="container-widths"></a>

### Minimum container widths

| Suffix | Expanded query |
| --- | --- |
| <a id="container-3xs"></a> `@container(--3xs)` | `(width >= 16rem)` |
| <a id="container-2xs"></a> `@container(--2xs)` | `(width >= 18rem)` |
| <a id="container-xs"></a> `@container(--xs)` | `(width >= 20rem)` |
| <a id="container-sm"></a> `@container(--sm)` | `(width >= 24rem)` |
| <a id="container-md"></a> `@container(--md)` | `(width >= 28rem)` |
| <a id="container-lg"></a> `@container(--lg)` | `(width >= 32rem)` |
| <a id="container-xl"></a> `@container(--xl)` | `(width >= 36rem)` |
| <a id="container-2xl"></a> `@container(--2xl)` | `(width >= 42rem)` |
| <a id="container-3xl"></a> `@container(--3xl)` | `(width >= 48rem)` |
| <a id="container-4xl"></a> `@container(--4xl)` | `(width >= 56rem)` |
| <a id="container-5xl"></a> `@container(--5xl)` | `(width >= 64rem)` |
| <a id="container-6xl"></a> `@container(--6xl)` | `(width >= 72rem)` |
| <a id="container-7xl"></a> `@container(--7xl)` | `(width >= 80rem)` |

<a id="below-container-widths"></a>

### Below container widths

| Suffix | Expanded query |
| --- | --- |
| <a id="container-max-3xs"></a> `@container(--max-3xs)` | `not (width >= 16rem)` |
| <a id="container-max-2xs"></a> `@container(--max-2xs)` | `not (width >= 18rem)` |
| <a id="container-max-xs"></a> `@container(--max-xs)` | `not (width >= 20rem)` |
| <a id="container-max-sm"></a> `@container(--max-sm)` | `not (width >= 24rem)` |
| <a id="container-max-md"></a> `@container(--max-md)` | `not (width >= 28rem)` |
| <a id="container-max-lg"></a> `@container(--max-lg)` | `not (width >= 32rem)` |
| <a id="container-max-xl"></a> `@container(--max-xl)` | `not (width >= 36rem)` |
| <a id="container-max-2xl"></a> `@container(--max-2xl)` | `not (width >= 42rem)` |
| <a id="container-max-3xl"></a> `@container(--max-3xl)` | `not (width >= 48rem)` |
| <a id="container-max-4xl"></a> `@container(--max-4xl)` | `not (width >= 56rem)` |
| <a id="container-max-5xl"></a> `@container(--max-5xl)` | `not (width >= 64rem)` |
| <a id="container-max-6xl"></a> `@container(--max-6xl)` | `not (width >= 72rem)` |
| <a id="container-max-7xl"></a> `@container(--max-7xl)` | `not (width >= 80rem)` |

Each preset `max-` condition is the complement of its matching minimum condition. The expanded queries below do not overlap at the boundary. The source definitions reference their corresponding names with `not (--name)`.

<a id="scope"></a>

## Same name, different scope

The same key can name different thresholds in different query domains. Container sizing tokens such as `--container-md` belong to a third, independent role: they supply lengths to sizing utilities.

**The same name measures different boundaries**

The preset’s @md threshold is 64rem; @container(--md) is 28rem. These independent definitions query different boundaries even though both use the name md.

- The outer boundary represents a viewport at the preset @md minimum width of 64rem.
- The inner boundary represents a query container at the independent @container(--md) minimum width of 28rem. The queried element is inside that container.
- The two widths use one drawing scale with a 16px initial and root font size. Changing a container sizing token does not change either condition definition.

<a id="usage"></a>

## Usage

This layout uses one column below the preset md viewport threshold and three columns from that threshold onward.

```html
<div class="… grid-cols(1) grid-cols(3)@md">
  <div>Notes</div>
  <div>Drafts</div>
  <div>Archive</div>
</div>
```

```css disclosure=generated-css
@layer utilities{.grid-cols\(1\){display:grid;grid-template-columns:repeat(1, minmax(0, 1fr))}@media (width >= 64rem){.grid-cols\(3\)\@md{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr))}}}
```

<a id="customize"></a>

## Customize

Declare a custom media name for a viewport or preference query, or a custom container name for a component query. Native units are retained. When replacing a condition in an already-compiled manifest, redeclare its complement too if both thresholds must change.

```css
@custom-media --tablet (width >= 48rem);
@custom-container --wide-card (width >= 30rem);
```

```html
<aside class="(container-name:card) container-inline">
  <div class="grid-cols(1) grid-cols(2)@container(card_--wide-card)">Card content</div>
</aside>
<div class="grid-cols(1) grid-cols(3)@tablet">Page content</div>
```

```css disclosure=generated-css
@layer utilities{.grid-cols\(1\){display:grid;grid-template-columns:repeat(1, minmax(0, 1fr))}.container-inline{container-type:inline-size}.\(container-name\:card\){container-name:card}@container card (width >= 30rem){.grid-cols\(2\)\@container\(card_--wide-card\){display:grid;grid-template-columns:repeat(2, minmax(0, 1fr))}}@media (width >= 48rem){.grid-cols\(3\)\@tablet{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr))}}}
```

See [condition grammar](/reference/rules/conditions), [condition definition scope](/reference/rules/conditions#compiled-condition-definitions), [query definitions](/reference/directives/queries#custom-container), [container sizing tokens](/reference/tokens/container) and [Responsive design](/guide/responsive-design).

## Related reference

- [rules/conditions](/reference/rules/conditions.md)
- [tokens/container](/reference/tokens/container.md)
- [directives/theme](/reference/directives/theme.md)
