DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
  1. Home
  2. Articles
  3. Frontend Engineering
  4. CSS Container Queries: The Future of Responsive Design
XLinkedInReddit
MediumFrontend Engineering

CSS Container Queries: The Future of Responsive Design

D
DevPrep Team
February 10, 2026·1 min read·0
Table of Contents
  • The Problem with Media Queries
  • Container Queries Syntax
  • Container Query Units
  • Practical Example: Responsive Card
  • Style Queries (Experimental)
  • Browser Support and Fallbacks

Media queries respond to the viewport. Container queries respond to the parent container. This changes everything for component-based design.

The Problem with Media Queries

A card component in a sidebar should look different from the same card in a main content area. Media queries can't distinguish — they only know the viewport width.

Container Queries Syntax

/* Define a containment context */
.card-container {
  container-type: inline-size;
  container-name: card;
}

/* Style based on container width */
@container card (min-width: 400px) {
  .card {
    display: grid;
    grid-template-columns: 200px 1fr;
  }
}

@container card (max-width: 399px) {
  .card {
    display: flex;
    flex-direction: column;
  }
}

Container Query Units

.card-title {
  /* cqw = 1% of container width */
  font-size: clamp(1rem, 3cqw, 1.5rem);
}

/* Available units: cqw, cqh, cqi, cqb, cqmin, cqmax */

Practical Example: Responsive Card

.widget-area {
  container-type: inline-size;
}

@container (min-width: 600px) {
  .product-card {
    flex-direction: row;
    .product-image { width: 40%; }
    .product-info { width: 60%; }
  }
}

@container (min-width: 300px) and (max-width: 599px) {
  .product-card {
    flex-direction: column;
    .product-image { aspect-ratio: 16/9; }
  }
}

Style Queries (Experimental)

/* Query custom property values */
@container style(--theme: dark) {
  .card { background: #1a1a1a; }
}

Browser Support and Fallbacks

Container queries are supported in all modern browsers (Chrome 105+, Firefox 110+, Safari 16+). Use @supports (container-type: inline-size) for progressive enhancement.

Related Articles

MediumFrontend Engineering

System Design #12: Design a Multi-Step Form Wizard

7 min read
MediumFrontend Engineering

Mastering Senior-Level JavaScript Interview Concepts

2 min read
MediumFrontend Engineering

System Design #9: Design a Collaborative Text Editor

9 min read

Comments (0)

Sign in to leave a comment.

No comments yet. Be the first to comment.

Table of Contents

  • The Problem with Media Queries
  • Container Queries Syntax
  • Container Query Units
  • Practical Example: Responsive Card
  • Style Queries (Experimental)
  • Browser Support and Fallbacks

Series

View all Frontend Engineering articles →

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.