<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg" -->

---
title: Style Queries as Conditional Modifiers | daily.dev
description: Container style queries let a component adapt its styles to a custom property set by any ancestor, so one condition can switch layout across many children....
canonical: https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Style Queries as Conditional Modifiers | daily.dev
og:description: Container style queries let a component adapt its styles to a custom property set by any ancestor, so one condition can switch layout across many children....
og:url: https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg
og:image: https://api.daily.dev/og/posts/25IglgSLG.png
og:image:alt: Style Queries as Conditional Modifiers
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.

# Style Queries as Conditional Modifiers

**[CSS-Tricks](https://daily.dev/sources/css_tricks)** · 8 min read · 1 upvotes · 0 comments

## Summary

Container style queries let a component adapt its styles to a custom property set by any ancestor, so one condition can switch layout across many children. They are Baseline Newly Available, need no container-type, and currently work only with custom properties. An element cannot query itself, so the property must be set higher up. Kevin Powell's example has a split layout set a direction property that an overflow grid reads, turning horizontal scroll into vertical. Modifier classes still suit single-element variants like an accent button. The post also promotes his CSS Demystified course.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://css-tricks.com/css-style-queries-as-conditional-modifiers>

## Questions this post answers

### Why isn't my CSS container style query working when the custom property is set on the same element?

An element cannot query itself with a style query. Like size queries, style queries check an ancestor container, so the custom property must be set on something above the element you are styling. Setting --card-layout on .card and then querying it for .card styles will not apply.

_Developers untangling CSS container query quirks follow new layout techniques on daily.dev._

### Do I need to set container-type to use CSS container style queries?

No. Unlike container size queries, every element is a style container by default, so there is no container-type to declare. Style queries currently work only with custom properties, such as style(--theme: high-contrast). Querying regular properties like display: flex is in the spec but not supported anywhere yet.

_Keeping up with which CSS features are truly safe to ship is easier on daily.dev._

### When should I use CSS style queries instead of modifier classes or the upcoming if() function?

Use style queries when the condition and the styles live in different places, or when one condition must affect several things at once. Modifier classes still suit single-element variants like an accent button. if() only works for a single property, while style queries can apply rules with multiple properties.

_Choosing between CSS approaches is easier when you follow how others solve it 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
- [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
- [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

---

Tags: [#css](https://daily.dev/tags/css)

[View this post on daily.dev](https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg)

```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":"Style Queries as Conditional Modifiers","url":"https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg"},"datePublished":"2026-11-25T14:11:12.836Z","dateModified":"2026-11-25T14:11:34.590Z","description":"Container style queries let a component adapt its styles to a custom property set by any ancestor, so one condition can switch layout across many children....","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/dcfa6cdaa5fa3d51ce819d2cca5cac4d?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/dcfa6cdaa5fa3d51ce819d2cca5cac4d?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"CSS-Tricks","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":"CSS-Tricks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/css_tricks","url":"https://daily.dev/sources/css_tricks"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"CSS-Tricks","item":"https://daily.dev/sources/css_tricks"},{"@type":"ListItem","position":3,"name":"Style Queries as Conditional Modifiers"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/style-queries-as-conditional-modifiers-25iglgslg#faq","mainEntity":[{"@type":"Question","name":"Why isn't my CSS container style query working when the custom property is set on the same element?","acceptedAnswer":{"@type":"Answer","text":"An element cannot query itself with a style query. Like size queries, style queries check an ancestor container, so the custom property must be set on something above the element you are styling. Setting --card-layout on .card and then querying it for .card styles will not apply. Developers untangling CSS container query quirks follow new layout techniques on daily.dev."}},{"@type":"Question","name":"Do I need to set container-type to use CSS container style queries?","acceptedAnswer":{"@type":"Answer","text":"No. Unlike container size queries, every element is a style container by default, so there is no container-type to declare. Style queries currently work only with custom properties, such as style(--theme: high-contrast). Querying regular properties like display: flex is in the spec but not supported anywhere yet. Keeping up with which CSS features are truly safe to ship is easier on daily.dev."}},{"@type":"Question","name":"When should I use CSS style queries instead of modifier classes or the upcoming if() function?","acceptedAnswer":{"@type":"Answer","text":"Use style queries when the condition and the styles live in different places, or when one condition must affect several things at once. Modifier classes still suit single-element variants like an accent button. if() only works for a single property, while style queries can apply rules with multiple properties. Choosing between CSS approaches is easier when you follow how others solve it on daily.dev."}}]}
```

