DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • The Box Model
  • Specificity & The Cascade
  • CSS Units Deep Dive
  • Stacking Contexts & Z-Index
  • Flexbox Mastery
  • CSS Grid Mastery
  • Centering, Subgrid & Container Queries
  • CSS Custom Properties & Variables
  • Selectors: :has(), Pseudo-classes & Pseudo-elements
  • Responsive Functions: calc(), clamp(), min(), max()
  • Media Queries & Mobile-First Design
  • Transitions & Animations
  • Transforms, Filters & Clipping
  • CSS Methodologies: BEM, CSS-in-JS & Tailwind
  • Typography, Color Spaces & Dark Mode
  • CSS Performance & Optimization
  • CSS Interview Questions — Part 1
  • CSS Interview Questions — Part 2
← From Beginner to Expert in Fundamentals of Frontend

Centering, Subgrid & Container Queries

18 min read
CenteringContainer QueriesSubgridcqwplace-items@container

Modern Layout Techniques

The Evolution of Centering

EraTechniqueCode
2000smargin: auto + known widthmargin: 0 auto; width: 600px;
2010sAbsolute + Transformposition: absolute; top:50%; left:50%; transform: translate(-50%,-50%);
2015+Flexboxdisplay:flex; justify-content:center; align-items:center;
2020+Grid (shortest)display:grid; place-items:center;

Container Queries — The Game Changer

Media queries respond to viewport size. Container queries respond to the parent element's size. This is revolutionary for reusable components.

A card component can now style itself differently when placed in a narrow sidebar vs. a wide main content area — without knowing anything about the viewport.

How Container Queries Work

  1. Mark a parent as a container: container-type: inline-size
  2. Query its size with @container

Container Query Units

UnitRelative To
cqw1% of container's width
cqh1% of container's height
cqi1% of container's inline size
cqb1% of container's block size

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.