Back to Blog
Frontend

CSS Container Queries vs Media Queries

Published: December 2, 2026 Category: Frontend
CSS Container Queries vs Media Queries

Introduction

Responsive design is an important part of modern frontend development. Websites must display correctly across desktops, laptops, tablets and mobile devices while maintaining a consistent user experience.

CSS provides different techniques for creating responsive layouts. Two important techniques are Media Queries and Container Queries. Media Queries have been used for years to adjust website layouts according to screen size, orientation, colour preferences and other device characteristics. They are commonly used to change navigation menus, page columns, font sizes and spacing.

1. Understanding CSS Media Queries and Container Queries

CSS Media Queries respond to the global browser viewport or device settings, while CSS Container Queries respond to the dimensions of a specific parent element. Together, they form the foundation of modern responsive web design—media queries handle page-level layouts, and container queries handle modular, reusable components.

Viewport size

Media Queries evaluate the browser viewport

Source: MDN Media Queries

Container size

Container Queries evaluate a containing element

Source: MDN Container Queries

Responsive design

Both support conditional CSS styling

Source: web.dev Container Queries

  • Viewport-Based Styling

    Media Queries adapt layouts to the browser window.

  • Component-Based Styling

    Container Queries adapt components to their available space.

  • Responsive Layouts

    Both techniques support flexible website layouts.

  • Conditional CSS

    Apply different styles when defined conditions are satisfied.

2. Practical Implementation: Media Queries vs Container Queries

Understanding the difference becomes easier when both techniques are implemented using the same component.

@media

Apply styles based on viewport conditions

Source: MDN Media Queries

container-type

Establish a query container

Source: MDN Container Queries

@container

Apply styles based on container conditions

Source: MDN Container Size Queries

  • Responsive Product Cards

    Change card layouts according to available space.

  • Viewport Breakpoints

    Use Media Queries to control complete page sections.

  • Container Breakpoints

    Use Container Queries to control individual components.

  • Named Containers

    Target specific containers in nested layouts.

  • Combined Techniques

    Manage page-level and component-level responsiveness together.

  • Reusable CSS

    Create components that work in different website sections.

Key Takeaways

  • CSS Media Queries and Container Queries both support responsive web design but work in different ways. Media Queries adjust styles based on viewport size and user preferences, making them useful for page layouts and global design changes. Container Queries adjust styles based on the size of a containing element, making them ideal for reusable components such as product cards, dashboard widgets and sidebar content.

Conclusion

Container Queries and Media Queries are complementary CSS techniques that solve different responsive design challenges. Media Queries are useful for adapting complete page layouts and user preferences, while Container Queries provide flexibility for individual components used in different layout contexts.

GetSiteGo

Want to take your business online?

Build a professional website with GetSiteGo — designed around your industry, your customers and the enquiries you want to win.

Related articles