Key takeaway
- Component-driven responsive design styles each component by its container, not just the screen. Learn container queries, media features and first steps.
Component-driven responsive design is an approach in which each interface component adapts to the space and user preferences it is given, rather than relying only on the width of the browser window. In CSS it combines container queries, which respond to a component's container, with media queries, which respond to the viewport, the device and the user's settings.
This guide is for front-end engineers, design system owners and product designers who build reusable components. It explains the shift away from page-level breakpoints, how container queries work, which user-preference media features matter for accessibility, and what to do first. For testing the result, see our guide to responsive design testing with the Galen framework.
What is component-driven responsive design?
The familiar approach to responsive design uses media queries to change the layout when a page moves from desktop to tablet to mobile. That ties every component to the size of the viewport. A card placed in a narrow sidebar on a wide desktop screen still sees a wide viewport, so a viewport rule cannot tell that the card has little room.
Component-driven design reverses the question. Each component asks how much space it has and what the user prefers, then adjusts. The component can be reused anywhere in a page, because its behaviour travels with it. This pairs naturally with design systems, where the same component appears in many layouts and the goal is to avoid duplicated and inconsistent styling.
How do container queries work?
The MDN container queries guide says container queries let you apply styles to an element based on its container's attributes, and calls them "an alternative to media queries, which apply styles to elements based on viewport size or other device characteristics". A container first declares a containment context with container-type, whose value is size, inline-size or normal (the default). With inline-size, the query is based on the inline dimension of the container, usually its width. An @container rule then applies styles to descendants.
.card-wrapper {
container-type: inline-size;
}
@container (width > 700px) {
.card h2 {
font-size: 2em;
}
}
You can name a container with container-name and refer to it in the query, or use the shorthand container: sidebar / inline-size;. MDN also lists container query length units such as cqw, cqh and cqi, which are percentages of the query container's dimensions. If no eligible container exists, the unit falls back to the small viewport unit for that axis. The article says the payoff is that a card "can be reused in multiple areas of a page without needing to know specifically where it will be placed each time". Check MDN's compatibility data for the browsers you support rather than relying on older guidance that treated the feature as experimental. MDN also suggests a grid or flex fallback with a media query for browsers without support.
What is the difference between media queries and container queries?
| Aspect | Media queries | Container queries |
|---|---|---|
| Responds to | Viewport size or device characteristics | The container's size, name, styles and other states |
| Best used for | Page-level layout and user settings | Component-level layout, or micro layouts |
| Reuse | Depends on where the page puts the component | The component adapts wherever it is placed |
| Setup | Write the query | Declare a container with container-type, then write the query |
In practice you use both. Use container queries for the micro layout inside a component, and media queries for the macro layout of the page and for user preferences.
Which user-preference media features should you support?
User-preference media features let CSS follow settings the person has made in their operating system. The MDN guide to media queries for accessibility describes prefers-reduced-motion as a way to provide fewer animations and transitions to users who have asked their system to reduce motion. It has two values: no-preference and reduce.
.animation {
animation: vibrate 0.3s linear infinite both;
}
@media (prefers-reduced-motion: reduce) {
.animation {
animation: none;
}
}
MDN stresses that the value is reduce, not "none": the preference does not mean every animation must go, and non-essential movement should be removed unless it is essential to the function or the information conveyed. MDN notes that motion can affect people with ADHD, vestibular disorders, epilepsy and migraine, and that reducing it can also help users with low battery or low-end devices.
| Media feature | What it lets you do |
|---|---|
| prefers-reduced-motion | Offer fewer animations and transitions; values are no-preference and reduce |
| prefers-contrast | Adjust page styles to the user's contrast preference |
| prefers-color-scheme | Follow the light or dark theme choice (see the MDN reference page for values) |
| prefers-reduced-transparency | Respond to a request for less transparency (see the MDN reference page) |
The MDN accessibility page links to reference pages for each feature; read those for values and browser support before you ship. Pair preference features with the guidance in our piece on principles for conversational UI, and treat accessibility as a design requirement from the start.
How do AI agents change responsive design work?
Component-driven CSS makes interfaces easier for software to reason about, because each component states its own rules. AI agents can help draft component variants, check them at several container widths and flag cases where reduced-motion or contrast preferences are ignored. A person still decides what is essential motion and what the design should do at each size. The AI agents computing platform, ElixirClaw, is where such testing and automation agents are built and run. If your team is working on a larger product, our product engineering consulting covers design and development, and our guide to building scalable and responsive applications covers the back end of the same goal.
What should you do first?
- List the components that appear in more than one layout, such as cards, navigation and tables.
- Give the most reused one a container with
container-type: inline-sizeand move its size rules from media queries to a container query. - Keep page-level layout and user settings in media queries.
- Add a
prefers-reduced-motion: reducerule for every non-essential animation. - Check MDN's compatibility data and add a fallback for browsers you support.
- Write the acceptance criteria as user stories; our guide to design thinking for agile user stories shows how.
To map one decision your agents make, and the data and policy it depends on, book a Context Workshop. See what happens in the workshop.
Frequently asked questions
What is a container query in CSS?
A container query applies styles to an element based on its container's attributes, such as its size, instead of the viewport. You declare a container with container-type and write an @container rule.
Do container queries replace media queries?
No. MDN calls container queries an alternative to media queries. Use container queries for component layout and media queries for page layout and user preferences.
What does prefers-reduced-motion do?
It lets you provide fewer animations and transitions to users who have asked their operating system to reduce motion. Its values are no-preference and reduce.
Does reduced motion mean removing all animation?
No. MDN says the preference does not mean all animations must be removed, but non-essential movement should be, unless it is essential to the function or information conveyed.
Which browsers support container queries?
Check the browser compatibility data on MDN for the browsers you need to support. MDN suggests a grid or flex layout with a media query as a fallback for browsers without support.
Ready to put AI agents to work? See an ElixirClaw demo: the agentic OS to build, orchestrate and govern AI agents across your enterprise systems.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE