---
title: "Keep media and container queries with · Agent Wranglers"
url: https://agentwranglers.se/playbook/html-css/structure-and-files/queries-with-the-component
updated: 2026-10-21
licence: "All rights reserved"
---

# Keep media and container queries with their component

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- Level: Recommended
- Chapter: [Structure and files](https://agentwranglers.se/playbook/html-css/structure-and-files)
- Rule: Write every media or container query inside the stylesheet of the component it changes. Never collect them in a separate file for screen sizes or print.
- How: A file such as `responsive.css` overrides components from the outside, so it breaks the one-owner rule. Put the query next to the styles it changes. Prefer container queries, so the component reacts to its own space, as [Size components with container queries](https://agentwranglers.se/playbook/website/interface/container-queries) describes. A query inside a component file only selects classes with that file's prefix.
- Check: No stylesheet exists whose name contains `responsive`, `mobile`, `print` or `breakpoints`. Inside each component file, every selector within `@media` or `@container` starts with the file's prefix.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### CSS example

```css
/* components/order-card.css: the query lives with the card */
.order-card { container-type: inline-size; }

@container (min-width: 30rem) {
  .order-card-body { display: grid; }
}
```

### HTML example

```html
<article class="order-card">
  <div class="order-card-body">Two sourdough loaves, ready at 9.00</div>
</article>
```

## Related rules

- [Let parts fit the space they get](https://agentwranglers.se/playbook/website/interface/container-queries) in Website

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/html-css/structure-and-files/queries-with-the-component">Agent Wranglers html and css playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Give each component exactly one stylesheet](https://agentwranglers.se/playbook/html-css/structure-and-files/component-stylesheet)
- Next: [Write styles only in stylesheets](https://agentwranglers.se/playbook/html-css/structure-and-files/styles-only-in-stylesheets)
- [Structure and files](https://agentwranglers.se/playbook/html-css/structure-and-files)
