Skip to content

Style conditions and variants #4249

Description

@kof

Note

Variants are property values styled through this shared system. They are not component-specific. See Builder components.

Problem

  • The active style condition is hidden in the Style Sources menu.
  • Condition selection is too closely tied to the selected token.
  • Users need to style eligible elements by property or attribute value.

Goals

  • Make the active style condition visible in the Style panel.
  • Separate condition selection from style-source selection.
  • Support CSS selectors, component-defined states, and property-value conditions.
  • Keep property-value styling usable without Builder components.
  • Keep the default condition list short; make other conditions searchable.

Model

  • A style condition determines when declarations apply.
  • Condition types:
    • CSS pseudo-classes and pseudo-elements.
    • Component-defined states.
    • Property-value conditions.
    • Custom selectors.
  • “Variant” describes styling one or more property values.
  • A variant is not a special property or component type.
  • Local styles and tokens store declarations for conditions.
  • Tokens do not own the element's available conditions.
  • Select a condition to edit or preview it.
  • Select Local or a token to choose where declarations are saved.

Style panel selector

  • Add an always-visible condition selector.
  • Keep it separate from Style Source selection.
  • Preview the selected condition on the canvas.
  • Default list includes conditions styled on the selected element's applied sources.
  • Always include the currently selected condition.
  • Add More… with search.
  • Group search results by condition type.
  • Do not list unrelated selectors from unapplied project tokens.
  • Show whether the selected source has styles for each condition.
  • After styles are saved, include the condition in the default list.

Selector notation

  • Preserve native CSS syntax: :hover, :focus-visible, ::placeholder.
  • Show component states using their metadata selector, such as [data-state="note"].
  • A state label may be supporting text; never replace the selector.
  • Show property conditions as property: value, using exact property spelling.
  • Keep custom selector syntax intact.
  • Selecting a condition changes the editing and preview context.
  • The selected source still determines where declarations are stored.

Property-value conditions

Fixed-choice properties

  • Define a finite set of values in property authoring.
  • Use each value as its label; do not define separate labels.
  • Set the default in property authoring.
  • Show each value as a one-click condition.
  • Example: select Appearance, then primary to activate appearance: primary.
  • Keep fixed-choice property authoring independent from this selector UI.

Open-value properties

  • Support exact-value conditions for eligible properties.
  • Do not enumerate open-ended values.
  • Let authors enter a specific exact value using the existing custom-selector flow.
  • Example: [data-label="Summer sale"].
  • Offer a known static or default value as a shortcut when available.
  • Only include values that can be serialized for selector matching.
  • Exclude complex values such as objects and arrays.
  • Allow exact string matches for open-ended string values.

CSS output

  • Keep the condition model semantic and independent of CSS output.
  • Do not make @container style() the definition of a variant.
  • @container style() is one possible output strategy.
  • It queries an ancestor container and cannot style that container itself.
  • Use attribute selectors or another scoped strategy when the element carrying the value must be styled.
  • Choose output based on scope, target element, and browser support.
  • Reference: MDN container style queries.
  • Reference: May 2026 Baseline digest.

Implementation batches

Batch 1 — Condition model and discovery

  • Model CSS selectors, component metadata states, property values, and custom selectors as distinct conditions.
  • Keep condition availability independent from Local/token style sources.
  • Find applicable CSS selectors and component states for the selected element.
  • Find conditions already styled on the selected element's applied sources.
  • Build the short default list from those conditions plus the active condition.
  • Exclude conditions from unrelated, unapplied project tokens.

Batch 2 — Style panel selector

  • Add an always-visible condition selector, separate from Style Source.
  • Add More… with search and grouped condition types.
  • Preserve CSS syntax, component state selectors, and exact property spelling.
  • Show whether the selected source has declarations for a condition.
  • Preview the selected condition on the canvas.
  • Save edits to the selected Local or token source.
  • Add newly styled conditions to the default list.

Batch 3 — Property-value conditions

  • Connect fixed-choice property values to one-click conditions.
  • Use option values as labels; keep defaults in property authoring.
  • Add exact-value conditions for eligible open-value properties.
  • Do not enumerate open-ended property values.
  • Exclude non-serializable or complex property values.
  • Keep property-value conditions independent of Builder component creation.

Batch 4 — CSS output and compatibility

  • Select CSS output based on condition scope and target element.
  • Support styling the element carrying the property value.
  • Keep token cascade, breakpoints, and component metadata states working.
  • Preserve existing custom selectors.

Acceptance criteria

  • The active condition is visible independently of Local/token selection.
  • The default list shows used conditions and the active condition.
  • Search finds other applicable conditions under More….
  • CSS selectors, metadata states, property values, and custom selectors are distinguishable.
  • Selector notation preserves CSS syntax and property spelling.
  • Fixed-choice values are selectable with one click.
  • Open-value properties support exact matches without exhaustive option lists.
  • Styles apply to the intended element and compose with tokens and breakpoints.
  • Existing metadata states and custom selectors keep working.
  • CSS output remains an implementation choice, not part of variant semantics.

Related issues

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:stylesStyle Panel is the CSS panel on the rightcomplexity:highMultiple weeks of work or moreprio:1The most important thing to work ontype:featFeatures and enhancements

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions