๐—–๐—ผ๐—ป๐˜๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฟ ๐—ค๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€: ๐—•๐—ฒ๐˜๐˜๐—ฒ๐—ฟ ๐—ง๐—ต๐—ฎ๐—ป ๐— ๐—ฒ๐—ฑ๐—ถ๐—ฎ ๐—ค๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€

Responsive design used to rely on one tool: Media Queries.

Media queries look at the screen size. This works for full page layouts. It fails for individual components.

A component might sit in a narrow sidebar on a desktop. A media query sees a wide screen and keeps the component in a wide layout. The component breaks because it lacks space.

Container Queries solve this. They let a component respond to its parent container instead of the screen.

How to use them:

  1. Define the parent as a container: .wrapper { container-type: inline-size; }

  2. Write a query for the child: @container (max-width: 500px) { .card { flex-direction: column; } }

The component now adapts to the space it occupies.

This makes components truly reusable. You can move a card from a sidebar to a main content area without writing new CSS.

Use Media Queries for:

Use Container Queries for:

Stop asking how wide the screen is. Start asking how much space your component has.

Container Queries are ready for modern browsers. They make your CSS modular and predictable.

Source: https://dev.to/muhammadmedhat/container-queries-the-css-feature-i-wish-i-had-years-ago-2h63