Keep your coding agent up to date with the latest web best practices
Release v0.0.150
github-actions[bot]ffc62fc09bcf
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonindex 069a119..8c8b070 100644--- a/.claude-plugin/marketplace.json+++ b/.claude-plugin/marketplace.json@@ -8,7 +8,7 @@"name": "modern-web-guidance","source": "./","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.149"+ "version": "0.0.150"}]}diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex 7ab8ae7..aacd58d 100644--- a/.claude-plugin/plugin.json+++ b/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.149",+ "version": "0.0.150","author": {"name": "Google Chrome"}diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.jsonindex 7ab8ae7..aacd58d 100644--- a/.cursor-plugin/plugin.json+++ b/.cursor-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.149",+ "version": "0.0.150","author": {"name": "Google Chrome"}diff --git a/README.md b/README.mdindex c2c66cf..f047c9b 100644--- a/README.md+++ b/README.md@@ -26,7 +26,7 @@ Our content is evergrowing, we cover the bleeding edge of the web platform as we### Core disciplines-Here's a tiny sampling of the **123 use-case-centric guides**:+Here's a tiny sampling of the **124 use-case-centric guides**:* **User Experience**: Smooth and modern visual states: View Transitions, CSS `scrollbar-color` styling, high-contrast adaptation, entry/exit transition animations, parallax scrolling.* **CSS layout:** container queries (both size and style queries), modern color spaces (`oklch`, `color-mix`) and `subgrid`, text-wrap tuning (`balance`, `pretty`), subgrid, and typography line height trimming (`text-box`)@@ -36,10 +36,10 @@ Here's a tiny sampling of the **123 use-case-centric guides**:* **Accessibility & Security**: accessible error announcements, keyboard focus management.* **Built-in AI**: Leveraging local, on-device client models (native Language Detection, Summarization, and Translation APIs).-#### Full Skill Coverage (v0.0.149)+#### Full Skill Coverage (v0.0.150)<details>-<summary>Includes expert guidance across <strong>98 modern web features</strong></summary>+<summary>Includes expert guidance across <strong>99 modern web features</strong></summary>- [::backdrop](https://web-platform-dx.github.io/web-features-explorer/features/backdrop/)- [:autofill](https://web-platform-dx.github.io/web-features-explorer/features/autofill/)@@ -63,6 +63,7 @@ Here's a tiny sampling of the **123 use-case-centric guides**:- [color-scheme](https://web-platform-dx.github.io/web-features-explorer/features/color-scheme/)- [Container queries](https://web-platform-dx.github.io/web-features-explorer/features/container-queries/)- [Container scroll-state queries](https://web-platform-dx.github.io/web-features-explorer/features/container-scroll-state-queries/)+- [Container style queries](https://web-platform-dx.github.io/web-features-explorer/features/container-style-queries/)- [content-visibility](https://web-platform-dx.github.io/web-features-explorer/features/content-visibility/)- [Cross-document view transitions](https://web-platform-dx.github.io/web-features-explorer/features/cross-document-view-transitions/)- [Custom highlights](https://web-platform-dx.github.io/web-features-explorer/features/highlight/)@@ -142,7 +143,7 @@ Here's a tiny sampling of the **123 use-case-centric guides**:</details><details>-<summary>Covers <strong>123 real-world developer use cases</strong> with production-ready code patterns</summary>+<summary>Covers <strong>124 real-world developer use cases</strong> with production-ready code patterns</summary><h3>accessibility</h3>@@ -237,6 +238,7 @@ Here's a tiny sampling of the **123 use-case-centric guides**:- **[declarative-button-actions](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/user-experience/declarative-button-actions.md)**: Declaratively connect a button to any element to trigger custom, application-specific actions using declarative button commands, invoker commands, button commands, custom commands, or declarative toggle actions.- **[declarative-dialog-popover-control](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/user-experience/declarative-dialog-popover-control.md)**: Toggle the visibility of a dialog or popover from a button without writing JavaScript.- **[deliver-optimized-decorative-images](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/user-experience/deliver-optimized-decorative-images.md)**: Deliver optimized decorative images (such as backgrounds, UI icons, or complex masks) by simultaneously providing next-generation image formats (like AVIF or WebP) alongside multiple pixel densities (like 1x and 2x) so the browser can dynamically negotiate the best combination of file size and visual quality for the user's device capabilities.+- **[design-token-reactivity](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/user-experience/design-token-reactivity.md)**: Define higher-order design tokens, like density modes (compact, comfortable, spacious) or themes and have descendant components react to changes directly and in component-appropriate ways.- **[directional-navigation-transitions](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/user-experience/directional-navigation-transitions.md)**: Animate visual state changes to reflect the direction of a user's navigational flow, such as sliding new content in from the right when advancing forward or from the left when returning to a previous screen.- **[dynamic-sibling-animations](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/user-experience/dynamic-sibling-animations.md)**: Stagger animation or transition timing across sibling elements so each one starts after a computed delay based on its position in the sibling list.- **[dynamic-sibling-styling](https://github.com/GoogleChrome/modern-web-guidance/blob/main/skills/modern-web-guidance/guides/user-experience/dynamic-sibling-styling.md)**: Create dynamic visual spectrums or layout arrangements that automatically adapt to the number of elements in a group.diff --git a/gemini-extension.json b/gemini-extension.jsonindex 7ab8ae7..aacd58d 100644--- a/gemini-extension.json+++ b/gemini-extension.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Keep your coding agent up to date with the latest web best practices",- "version": "0.0.149",+ "version": "0.0.150","author": {"name": "Google Chrome"}diff --git a/package.json b/package.jsonindex 53209cd..7376d31 100644--- a/package.json+++ b/package.json@@ -3,7 +3,7 @@"displayName": "Modern Web Guidance","description": "Keep your agent up to date on the latest web best practices.","license": "Apache-2.0",- "version": "0.0.149",+ "version": "0.0.150","publisher": "GoogleChrome","engines": {"vscode": "^1.90.0",diff --git a/skills/modern-web-guidance/guides/user-experience/design-token-reactivity.md b/skills/modern-web-guidance/guides/user-experience/design-token-reactivity.mdnew file mode 100644index 0000000..0056a70--- /dev/null+++ b/skills/modern-web-guidance/guides/user-experience/design-token-reactivity.md@@ -0,0 +1,175 @@+## Background & Overview++Often an author will need to make contextual changes to the design of a component. Historically authors would need to use selectors to apply such changes. This often meant that while many of their design tokens could exist as custom properties, higher-order design tokens could only be encoded as a selector pattern (i.e. using a class name or attribute convention) or as props/context in a JavaScript framework.++**Container style queries** allow authors to style elements based on the computed custom property value of an ancestor element. This means authors can write meaningful design token values within their stylesheets rather than relying on markup or JavaScript for presentation.++## How to implement++Implementing a reactive design token using a container style query is quite straightforward:++1. Set the higher-order design token as a custom property on a container. This does not need to be a registered custom property.+2. Use the `@container style()` rule to query the value of that custom property.+3. Apply the appropriate styles to a descendant element within the container.++A few things to keep in mind:++- The container being queried with a style query does not need to have a `container-type` or `container-name` set, however, a `container-name` can allow for more specific querying.+- The container itself cannot be styled by the container style query.++The following is a basic example of the above implementation steps.++```html+<div class="features">+ <div class="card"></div>+ <div class="card"></div>+</div>+<div class="bugs">+ <div class="card"></div>+ <div class="card"></div>+ <div class="card"></div>+ <div class="card"></div>+</div>+```++```css+.features {+ --density: spacious;+}++.bugs {+ --density: compact;+}++@container style(--density: compact) {+ .card {+ padding: 8px;+ }+}++@container style(--density: spacious) {+ .card {+ padding: 24px;+ }+}+```++## Fallback strategies++Container style queries has limited availability.+Supported by: Chrome 111 (Mar 2023), Edge 111 (Mar 2023), and Safari 18 (Sep 2024).+Unsupported in: Firefox.++Until there is Baseline support for container style queries it is NOT RECOMMENDED that they be used for core features that must be available across all browsers, since it is not simple to create a fallback for them that does not take away from their benefits or that have their own limitations. For example, if a UI density user preference is not deemed to be a core feature that must be available across all experiences, then container style queries can be use to implement the feature without a fallback.++### Using selectors instead++For core features, an alternate approach using selectors should be used. This example uses a `data-density` attribute to encode the density design token in the markup rather than as a custom property:++```html+<div class="features" data-density="spacious">+ <div class="card"></div>+ <div class="card"></div>+</div>+<div class="bugs" data-density="compact">+ <div class="card"></div>+ <div class="card"></div>+ <div class="card"></div>+ <div class="card"></div>+</div>+```++```css+/* This example uses `:where()` to avoid increasing specificity */+:where([data-density="compact"]) .card {+ padding: var(--card-padding-compact);+}++:where([data-density="spacious"]) .card {+ padding: var(--card-padding-spacious);+}+```++A major limitation of this fallback approach is that it does not support nesting elements with the `data-density` attribute set, since the selector specificity is the same, order of appearance will be used to determine the styles (i.e. `[data-density="spacious"]` will always take precendence over `[data-density="compact"]`).++### Using style queries as a progressive enhancement++While it’s NOT RECOMMENDED, if you want to use style queries as a progressive enhancement for a core feature, then to avoid duplication you can create some custom properties, then include the style queries after. Make sure the fallback approach uses `:where()` when selecting the container elements to avoid increasing the specificity.++```css+.card {+ --card-padding-compact: 8px;+ --card-padding-spacious: 24px;+}++:where([data-density="compact"]) .card {+ padding: var(--card-padding-compact);+}++:where([data-density="spacious"]) .card {+ padding: var(--card-padding-spacious);+}++/* Use style queries as a progressive enhancement: same specificity, so order of appearance is used */++@container style(--density: compact) {+ .card {+ padding: var(--card-padding-compact);+ }+}++@container style(--density: spacious) {+ .card {+ padding: var(--card-padding-spacious);+ }+}+```++### Feature-checking with just CSS++If you need to feature check container style queries to conditionally display some UI that relies on it, you can use a style query to do so:++```css+:root {+ --style-queries-supported: check;+}++.density-toggle {+ display: none;+}++@container style(--style-queries-supported) {+ .density-toggle {+ display: revert;+ }+}+```++### Feature-checking with JavaScript++For feature-checking with JavaScript, it is slightly more complicated as the `CSSContainerRule` interface existed prior to the addition of container style queries, so it is unreliable for this purpose. Instead, you’ll need to check the computed value of a known property that is being set with a style query.++This example uses a custom property as it will have no visual effect:++```css+:root {+ --style-queries-supported: check;+}++@container style(--style-queries-supported: check) {+ body {+ --style-queries-supported: yes;+ }+}+```++Then check the computed value in JavaScript like this:++```js+if (getComputedStyle(document.body).getPropertyValue("--style-queries-supported") === "yes") {+ // Use container style queries+} else {+ // Use fallback strategy+}+```+