utopia-container-queries
Utopia Container Queries
Container setup required for this project's fluid scales
Critical: cqi Units Require Container Context
This project's type and space scales use cqi (container query inline) units:
/* From typography.css */
--step-0: clamp(1.125rem, 1.0739rem + 0.2273cqi, 1.25rem);
/* From space.css */
--space-m: clamp(1.6875rem, 1.6108rem + 0.3409cqi, 1.875rem);
Without a container context, the cqi portion evaluates to 0, meaning values stay at their minimum.
Required Setup
For fluid scaling to work, you must establish a container context:
Option 1: Root Container (Recommended)
Apply to html or body for global container context:
html {
container-type: inline-size;
}
Or in your component:
body {
container-type: inline-size;
}
Option 2: Component-Level Containers
For component-specific containers:
.card-container {
container-type: inline-size;
}
/* Optional: name the container */
.card-container {
container: card / inline-size;
}
Current State
No container-type declarations exist in the CSS files. The fluid scales are defined but will not scale fluidly until container context is added.
Files That Need Container Context
| File | Has cqi Units | Has container-type |
|---|---|---|
typography.css |
Yes | No |
space.css |
Yes | No |
grid.css |
No (uses vw fallback) | No |
Adding Container Support
Minimal Setup
Add to css/styles/index.css:
html {
container-type: inline-size;
}
Per-Component Setup
For isolated components:
.my-component {
container-type: inline-size;
}
Container Query Syntax
Once containers are established, you can use container queries:
@container (inline-size > 400px) {
.card {
display: grid;
grid-template-columns: 150px 1fr;
}
}
/* Named container query */
@container card (inline-size > 600px) {
.card__title {
font-size: var(--step-3);
}
}
Container Units Available
| Unit | Description |
|---|---|
cqi |
1% of container inline size (width in LTR) |
cqb |
1% of container block size (height in LTR) |
cqw |
1% of container width |
cqh |
1% of container height |
cqmin |
Smaller of cqi/cqb |
cqmax |
Larger of cqi/cqb |
What's NOT Defined
The following are not currently in the CSS:
- Any
container-typedeclarations - Any
@containerqueries - Named containers
The infrastructure (cqi-based tokens) exists, but the container context to make it functional does not.
Next Steps
- Add
container-type: inline-sizeto html or body - Verify fluid scaling works by resizing viewport
- Add component-level containers as needed
- Add
@containerqueries for component-level responsiveness
Files
css/styles/index.css- Recommended location for root container setupcss/styles/layouts.css- Empty, available for container utilities
More from matthewharwood/fantasy-phonics
animejs-v4
Anime.js 4.0 animations for Web Components — drag-drop, click feedback, swaps, cancelable motion. Use when adding animations, drag interactions, visual feedback, or motion to custom elements. Combines with web-components-architecture for lifecycle cleanup.
37ux-spacing-layout
Utopia fluid spacing tokens and layout patterns. Use when applying margins, padding, gaps, or creating layouts. Covers space scale, container widths, and responsive spacing. (project)
15html-semantic-engineering
30 pragmatic rules for production HTML covering semantic markup, accessibility (WCAG 2.1 AA), performance optimization, forms, and security. Use when writing HTML, building page structures, creating forms, implementing accessibility, or optimizing for SEO and Core Web Vitals.
14web-components-architecture
Build web components using Custom Elements v1 API with Declarative Shadow DOM, attribute-driven state, handleEvent pattern, and zero DOM selection. Use when creating custom elements, extending built-in HTML elements, or implementing component-based architecture. NO querySelector, NO innerHTML, NO external libraries - pure web platform APIs only.
12ux-iconography
Icon usage patterns using Material Symbols v3. Use when adding icons to buttons, navigation, or status indicators. Covers sizing, accessibility, animations, and color integration with project tokens.
10webgpu-canvas
WebGPU fundamentals for high-performance canvas rendering. Covers device initialization, buffer management, WGSL shaders, render pipelines, compute shaders, and web component integration. Use when building GPU-accelerated graphics, particle systems, or compute-intensive visualizations.
10