Skip to content

add semantic adaptation guide and demo for usage-aware-component-variations#803

Open
castastrophe wants to merge 2 commits into
mainfrom
usage-aware-component-variations-169
Open

add semantic adaptation guide and demo for usage-aware-component-variations#803
castastrophe wants to merge 2 commits into
mainfrom
usage-aware-component-variations-169

Conversation

@castastrophe
Copy link
Copy Markdown
Contributor

@castastrophe castastrophe commented May 13, 2026

Summary

  • Refactored guide.md to focus on Semantic Component Adaptation, a more appropriate use case for style queries than size-based layout density.
  • Updated demo.html to demonstrate a CTA Card adapting its visual logic (button style, badge visibility) based on a inherited --priority flag.
  • Ensured the implementation uses logical properties (inset-block-start, min-block-size) and provides robust fallback strategies.
  • Verified that this use case is distinct from the density-focused design-token-reactivity.

Test plan

  • Manually reviewed the demo.html to ensure style queries correctly trigger variations on a Chromium-based browser (Limited Availability).
  • Verified that the guide.md correctly identifies when to use style queries vs. size queries via a new decision matrix.

@google-cla

This comment was marked as resolved.

@castastrophe castastrophe force-pushed the usage-aware-component-variations-169 branch from cd593a0 to b93ce85 Compare May 13, 2026 17:51
@castastrophe castastrophe marked this pull request as draft May 13, 2026 17:53
@castastrophe castastrophe force-pushed the usage-aware-component-variations-169 branch 3 times, most recently from a1c9484 to 85b8616 Compare May 13, 2026 19:05
@castastrophe castastrophe marked this pull request as ready for review May 13, 2026 19:06
@castastrophe castastrophe force-pushed the usage-aware-component-variations-169 branch from 85b8616 to 8a065c6 Compare May 13, 2026 19:09

```css
/* Fallback for browsers without style query support */
@supports not (container-type: inline-size) {
Copy link
Copy Markdown
Contributor

@knowler knowler May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to layer on style queries as a progressive enhancement in the fallback since container-type: inline-size wouldn’t have complete overlap with style queries (i.e. it would go back much farther and would match situations that don’t support style queries). For example, these could be the defaults that the style queries then overrides. Could use :where(section.promo) + order of appearance to ensure the style query wins.

/* Default styles */
.button {}

/* Contextual styles (wide support) */
:where(section.promo) .button {
  background: var(--brand-accent);
  color: white;
}

/* Style query aided contextual styles (limited support) */
@container style(--priority: high) {
  .button {
    /* Automatic switch to Filled promotional style */
    background: var(--brand-accent);
    color: white;
    border: none;
  }
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to what @knowler said. And sadly we don't have a container-type: style to query.

And if you want to apply CSS when style CQs are supported without querying any particular property, you can do something like this: https://codepen.io/leaverou/pen/qEqqZQq

Copy link
Copy Markdown
Contributor

@jamesnw jamesnw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions and tweaks, but it looks good!


.badge {
/* Reveal decorative elements only in high-priority context */
display: block;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure- do you need to show .badge{ display: none} in the guide to show it's being overridden?


## Fallback Strategies

{{ FEATURE_FALLBACKS("container-style-queries") }}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this exists? I could be wrong, but my understanding is there would need to be a file in /features/container-style-queries with a ## Fallbacks section for this to work.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a file doesn't exist, it will just print baseline status (so the next para isn't needed).

That said, we do need to have that content, either there or here! But if the intent is to add this so we can add the fallback later, that's OK, I think? (unsure)

Comment thread guides/user-experience/usage-aware-component-variations/guide.md Outdated
Comment thread guides/user-experience/usage-aware-component-variations/expectations.md Outdated
```css
/* 1. Set the context on a layout container */
.promo {
--priority: high; /* Semantic flag for children */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--priority: high; /* Semantic flag for children */
--priority: promo; /* Semantic flag for children */

For consistency with the demo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I meant to update the demo too - it felt like promo was too "what it is" and not "what the context means".

## Mental Model

- **Size Queries:** Use for layout/density changes (width/height).
- **Name-only Queries** Use for layout context (i.e., breadcrumbs).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what's meant by layout context fully- maybe another example?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK name-only CQs have worse browser support than style queries, and no web-feature id so we can do BASELINE_STATUS.

Just filed web-platform-dx/web-features#4039 about that — laziest bug report ever but at least now there's something!

@LeaVerou
Copy link
Copy Markdown
Collaborator

LeaVerou commented May 14, 2026

Just a quick note that I have seen the review request and plan to take a proper look at this once I'm done with the dark mode rewrite.
Very excited about this use case!

Refactors the guide and demo to focus on semantic component variations
using style queries. Replaced size-dependent layout examples with a
contextual priority pattern (standard vs. promo) better suited for
@container style() logic.
@castastrophe castastrophe force-pushed the usage-aware-component-variations-169 branch from 8a065c6 to f602dd2 Compare May 14, 2026 17:22

Use style queries (`@container style()`) to trigger component variations based on inherited semantic context flags rather than viewport or container dimensions. This replaces deep descendant selectors (e.g., `.sidebar .card`) and improves component encapsulation.

In the context of design system components, style queries become invaluable in allowing styles to respond to their containers without the need for style-specific APIs that need to be pushed down to every descendant.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you mean, but I think this is hard to understand without a lot of context. Perhaps an example would make it clearer?

Copy link
Copy Markdown
Collaborator

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments, but on a high level I think it's still unclear (to me at least!) what use cases are part of this and which ones are part of design-token-reactivity.

E.g. I'd expect that a --priority property would be a high-level property that affects multiple design tokens, and that elements it's applied on themselves need to adapt to it themselves (e.g. a button with --priority would need a different border, background, text color etc). But also I wouldn't expect --priority: promo and I have no idea whether that's higher or lower than --priority: high. Looking at the expectations, button variant also seems more design token-y.

The description does a good job at drawing a clear distinction between the two, so I think it just needs a different example that's closer to real-world usage and clearly distinct from design tokens. I can't think of one offhand, but will try to brainstorm a few examples as well.

A more practical caveat I have discovered when using style queries: there is no way to match the actual element the property was specified on, so if you want to apply any styling that shouldn't be inherited (e.g. add a shadow) in a style query, one way to do that without applying it to every element in that subtree is to register the custom property as non-inheritable. Then it will only match direct children and you can use descendant selectors inside it if needed. You can even set a regular property in that rule, so that you have an inherited and a non-inherited version to query. Happy to expand on this if it comes up, just dropping it here so that if you encounter it while working on these you know it has a solution.

Co-authored-by: James Stuckey Weber <james@oddbird.net>
@rviscomi
Copy link
Copy Markdown
Member

@castastrophe is this ready for another look?

@jamesnw jamesnw linked an issue May 19, 2026 that may be closed by this pull request
7 tasks
@castastrophe
Copy link
Copy Markdown
Contributor Author

@rviscomi Not ready yet - it needs Lea's updates applied as well.

@LeaVerou
Copy link
Copy Markdown
Collaborator

@rviscomi Not ready yet - it needs Lea's updates applied as well.

You mean updates to things mentioned in my review or updates by me? 👀 Fine either way, just asking to make sure it doesn't fall off my radar if it's the latter!

@castastrophe
Copy link
Copy Markdown
Contributor Author

@rviscomi Not ready yet - it needs Lea's updates applied as well.

You mean updates to things mentioned in my review or updates by me? 👀 Fine either way, just asking to make sure it doesn't fall off my radar if it's the latter!

Haha updates by me based on your already provided feedback. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create guide and evals for the usage-aware-component-variations use case

6 participants