The Era of Context: Portability through Container Queries
For over a decade, responsive design relied on a single question: "How wide is the browser window?" In the Espalier system, we recognize that this is a coarse and inefficient metric for component-based architecture. We have entered the Era of Context, where components listen to the space they actually occupy rather than the size of the device.
By utilizing CSS Container Queries, we create "Layout-Agnostic" components that can be dropped into a sidebar, a wide content well, or a narrow modal and adapt their internal structure automatically.
The Hierarchy of Responsiveness
From a Startup Strategist’s perspective, container queries are a tool for Modular Scalability. We follow a three-tier escalation model for handling available space:
- Level 1: Intrinsic Math: Elements adapt naturally via interpolation (
clamp,fr,flex-wrap) without any explicit queries. - Level 2: Container Queries: Components adjust their internal arrangement based on the dimensions of their parent orchestrator.
- Level 3: Media Queries: Reserved strictly for global, viewport-wide shifts like toggling primary navigation or adjusting page-level padding.
Technical Implementation: Defining the Context
To enable context-awareness, an ancestor element must be registered as a "containment context." In Espalier, our (/guides/layout/macro-structures) automatically establish these containers.
/* 1. Establish the trellis as a container */
.layout-region {
container-type: inline-size;
container-name: content-well;
}
/* 2. Component responds to its local well, not the screen */
@container content-well (width > 500px) {
.card {
display: grid;
grid-template-columns: 200px 1fr;
}
}
The Evolution of Units: From vw to cqi
In a context-aware system, viewport-based units (vw) are a liability for components. If a card's padding is set to 2vw, it will remain the same size even if the card is moved into a tiny sidebar.
Espalier is transitioning to Container Query Length Units:
1cqi: Represents of the container’s inline size (width).1cqmin: The smaller of the two axes, ideal for maintaining square proportions in responsive grids.
By using cqi within our (/guides/typography/fluid-design) logic, we ensure that font-scaling is proportional to the component's actual width.
Challenge the Assumption: "Breakpoints are Global"
A common assumption is that a "Mobile View" happens at
For a defensible architecture, stop defining Device Breakpoints and start defining Component Thresholds.
Strategic Implementation in Lit
In our Lit Element library, we favor naming our containers to prevent "Query Leakage" where a component accidentally responds to the wrong ancestor.
/**
* @cssprop --esp-container-type - Allows overriding the containment model.
*/
@customElement('esp-container')
export class EspalierContainer extends LitElement {
static styles = css`
:host {
display: block;
container-type: var(--esp-container-type, inline-size);
}
`;
}