refract v0.1 · beta
Core concepts / Container queries

Container queries

A top-level containers config declares named query containers. A recipe override keyed by { container, size } lowers to an @container rule — styling by the container's width, not the viewport's.

The emitted .dt-cq-card utility establishes the context (container-type: inline-size); any descendant recipe responds. It's a distinct condition axis that composes with viewport @media.

containers.ts
containers: { card: { sizes: { sm: 280, md: 440 } } },

// a recipe override, keyed by container + size
solid.accent: {
  background: "accent",
  responsive: [
    { container: "card", size: "md", background: "brand" },
  ],
}

Worked example

authored
containers: { card: { type: "inline-size", sizes: { sm: 280, md: 440 } } },
solid.brand: {
  background: "brand",
  responsive: [{ container: "card", size: "md", background: "brand.dark" }],
}
emitted
/* the context class establishes the container */
.dt-cq-card { container-type: inline-size; container-name: card; }
/* the recipe override responds to the CONTAINER's width, not the viewport's */
@container card (min-width: 440px) {
  .dt-colors-solid-brand { background: var(--dt-colors-brand-dark); }
}

Rules & edge cases

  • You must place the context class. A descendant only responds if an ancestor carries .dt-cq-<name> — that's what establishes container-type: inline-size.
  • Inline size only. Container queries respond to the container's width; orientation / height / aspect-ratio are rejected as a build error (that's what viewport @media is for).
  • min is the default query for container entries.
  • A separate axis from @media. Container and viewport queries compose — a rule can be inside both.
  • Unknown container or size is a build error — declare them under containers.
The container generators (a structural element that is a container) live in Layout; the .dt-cq- naming is in Token paths & naming.

Live — resize the container

Technical documentation for @theme-registry/refract · all output is compiled client-side by the real library (CSS adapter). The chrome is theme-aware; the render panes carry each preset's own world. · MIT licensed.