HTML & CSS
/Advanced
Container Queries
Definition
A revolutionary CSS feature that allows elements to apply styles based on the size of their PARENT container, rather than the size of the overall browser viewport.
Explain Like I'm New
Media Queries ask: 'Is the phone screen small?'. Container Queries ask: 'Is the box I am inside of small?'. If you put a Profile Card in a wide Main area, it can lay out horizontally. If you drag that exact same card into a narrow Sidebar, it magically detects the narrow space and stacks itself vertically.
Real World Example
Building a totally modular 'Product Card' component in React. You can drop it anywhere on your site, and it automatically adjusts its own internal layout to look good in whatever container it was dropped into.
Common Use Cases
- •Component-driven architecture (React/Vue/Angular)
Interactive Example
Interview Questions
basic
- What CSS property must you apply to the parent to 'unlock' container queries for its children?
intermediate
- Why are container queries a game-changer for React developers?