What is the difference between container queries and media queries?

Media queries test the viewport or user-environment features, while container queries test an ancestor container’s size, style or scroll state. Media queries answer questions about the page environment. Container queries answer whether a particular component has enough local space for another arrangement.
Use a media query for global navigation, print styles, reduced motion, color preference, pointer accuracy or a page grid that follows viewport width. Use a container query for a card that appears in several page regions or a toolbar inside resizable panes. The two systems complement each other.
A viewport can be wide while a sidebar component remains narrow. A media query would see the wide screen and might force the card into a horizontal layout that does not fit. A size container query sees the sidebar’s actual inline size and keeps the card stacked.
Container size queries require containment setup such as container-type: inline-size. Media queries need no ancestor declaration. Container queries also cannot make an element depend directly on its own resulting size; the browser queries an eligible ancestor to avoid circular calculations.
Keep global design tokens consistent while allowing local component thresholds. Test components in real placements and at several catalog widths. Behavior based on input capability or user preference remains a media-query concern even when the component is reusable. Include the pattern in responsive regression tests with long content, browser zoom and at least one narrow embedded context. Record the expected wrapping and focus behavior so later component changes can be checked against a known result.