<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n" -->

---
title: Styling based on container width made possible with CSS...
description: CSS container queries let developers style elements based on the width of their parent container instead of the viewport, enabling more dynamic and...
canonical: https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Styling based on container width made possible with CSS container queries. | daily.dev
og:description: CSS container queries let developers style elements based on the width of their parent container instead of the viewport, enabling more dynamic and...
og:url: https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n
og:image: https://api.daily.dev/og/posts/FE2u4QJ7n.png
og:image:alt: Styling based on container width made possible with CSS container queries.
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Styling based on container width made possible with CSS container queries.

**[utilitybend](https://daily.dev/sources/utilitybend)** · 8 min read · 0 upvotes · 0 comments

## Summary

CSS container queries let developers style elements based on the width of their parent container instead of the viewport, enabling more dynamic and maintainable component-based styling. The post walks through the container, container-type, and container-name properties, shows card-layout examples using inline-size containment, and demonstrates a CMS use case where card grids adapt based on the number of items without extra classnames or JS/PHP counting logic. It also covers browser support checks via caniuse, a polyfill (cqfill) for older browsers, and notes that block-size containment isn't yet supported. The post was originally written when the feature was behind a Chrome Canary flag and later updated on September 30, 2022 to reflect stable releases in Chrome and Safari.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://utilitybend.com/blog/styling-based-on-container-width-made-possible-with-css-container-queries>

## Questions this post answers

### How do I make an element a query container in CSS for container queries?

Use the container shorthand property (or container-type and container-name separately) on the parent element, for example `container: card/inline-size;`. Then descendants can be styled with an @container rule referencing that name, such as `@container card (min-width: 401px) { ... }`, applying layout, style, and containment based on the container's width rather than the viewport.

_Developers adopting container queries can track browser support changes and CSS updates on daily.dev._

### What values can the container-type property have in CSS?

The container-type property accepts size, inline-size, and normal. Size establishes a query container for dimensional queries on both block and inline axes with layout, style, and size containment; inline-size does the same but only for the inline axis; normal means the element is not a query container for dimensional queries on either axis.

_Track evolving CSS containment specs like this one alongside other frontend changes on daily.dev._

### Is there a polyfill available for CSS container queries to support older browsers?

Yes, a polyfill called cqfill (available on GitHub under jsxtools) can be used to support container queries in browsers that don't natively implement the feature yet. It is recommended to pair this kind of polyfill workflow with PostCSS for easier integration into a build pipeline.

_Developers weighing polyfill options for new CSS features can follow related tooling news on daily.dev._

## Similar posts on daily.dev

- [CSS Container Queries](https://daily.dev/posts/css-container-queries-iq9qajosu) · Flavio Copes · 24 upvotes · 0 comments
- [Container queries in 2026: Powerful, but not a silver bullet](https://daily.dev/posts/container-queries-in-2026-powerful-but-not-a-silver-bullet-zamknhyli) · LogRocket · 7 upvotes · 0 comments
- [How to Build Responsive Designs and Scroll Effects with CSS Container Queries](https://daily.dev/posts/how-to-build-responsive-designs-and-scroll-effects-with-css-container-queries-xw53ucqmc) · freeCodeCamp · 10 upvotes · 0 comments
- [Stop Treating CSS Container Queries Like Traditional Media Queries — Smashing Magazine](https://daily.dev/posts/stop-treating-css-container-queries-like-traditional-media-queries-smashing-magazine-opborjqov) · Smashing Magazine · 8 upvotes · 0 comments
- [CSS Container Queries and Subgrid: Building Context-Aware Component Layouts](https://daily.dev/posts/css-container-queries-and-subgrid-building-context-aware-component-layouts-rddpjlqek) · SitePoint · 3 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css), [#ui-design](https://daily.dev/tags/ui-design), [#google-chrome](https://daily.dev/tags/google-chrome)

[View this post on daily.dev](https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Styling based on container width made possible with CSS container queries.","url":"https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n"},"datePublished":"2026-09-20T07:43:32.107Z","dateModified":"2026-09-20T07:44:45.329Z","description":"CSS container queries let developers style elements based on the width of their parent container instead of the viewport, enabling more dynamic and...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ab666a29d0aa7099c166f6e4714e7122?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ab666a29d0aa7099c166f6e4714e7122?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"utilitybend","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"utilitybend","logo":"https://media.daily.dev/image/upload/s--hONVFSz4--/f_auto,q_auto/v1789890196/logos/utilitybend?_a=BAMAMicg0","url":"https://daily.dev/sources/utilitybend"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css,ui-design,google-chrome","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"utilitybend","item":"https://daily.dev/sources/utilitybend"},{"@type":"ListItem","position":3,"name":"Styling based on container width made possible with CSS container queries."}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/styling-based-on-container-width-made-possible-with-css-container-queries--fe2u4qj7n#faq","mainEntity":[{"@type":"Question","name":"How do I make an element a query container in CSS for container queries?","acceptedAnswer":{"@type":"Answer","text":"Use the container shorthand property (or container-type and container-name separately) on the parent element, for example `container: card/inline-size;`. Then descendants can be styled with an @container rule referencing that name, such as `@container card (min-width: 401px) { ... }`, applying layout, style, and containment based on the container's width rather than the viewport. Developers adopting container queries can track browser support changes and CSS updates on daily.dev."}},{"@type":"Question","name":"What values can the container-type property have in CSS?","acceptedAnswer":{"@type":"Answer","text":"The container-type property accepts size, inline-size, and normal. Size establishes a query container for dimensional queries on both block and inline axes with layout, style, and size containment; inline-size does the same but only for the inline axis; normal means the element is not a query container for dimensional queries on either axis. Track evolving CSS containment specs like this one alongside other frontend changes on daily.dev."}},{"@type":"Question","name":"Is there a polyfill available for CSS container queries to support older browsers?","acceptedAnswer":{"@type":"Answer","text":"Yes, a polyfill called cqfill (available on GitHub under jsxtools) can be used to support container queries in browsers that don't natively implement the feature yet. It is recommended to pair this kind of polyfill workflow with PostCSS for easier integration into a build pipeline. Developers weighing polyfill options for new CSS features can follow related tooling news on daily.dev."}}]}
```

