Keep your coding agent up to date with the latest web best practices
Release v0.0.115
github-actions[bot]5ed8f93482c1
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonindex ebe70de..6eca79a 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.114"+ "version": "0.0.115"}]}diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex 792edf7..eeb59fd 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.114",+ "version": "0.0.115","author": {"name": "Google Chrome"}diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.jsonindex 792edf7..eeb59fd 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.114",+ "version": "0.0.115","author": {"name": "Google Chrome"}diff --git a/README.md b/README.mdindex 8b21893..5d818bf 100644--- a/README.md+++ b/README.md@@ -36,7 +36,7 @@ Just a tiny sampling of the **134+ 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.114)+#### Full Skill Coverage (v0.0.115)<details><summary>Includes expert guidance across <strong>85 modern web features</strong></summary>diff --git a/gemini-extension.json b/gemini-extension.jsonindex 792edf7..eeb59fd 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.114",+ "version": "0.0.115","author": {"name": "Google Chrome"}diff --git a/package.json b/package.jsonindex ab4d0c2..6ca5a6b 100644--- a/package.json+++ b/package.json@@ -2,7 +2,7 @@"name": "modern-web-guidance","displayName": "Modern Web Guidance","description": "Keep your agent up to date on the latest web best practices.",- "version": "0.0.114",+ "version": "0.0.115","publisher": "GoogleChrome","engines": {"vscode": "^1.90.0",diff --git a/skills/modern-web-guidance/guides/user-experience/component-specific-light-dark-theme.md b/skills/modern-web-guidance/guides/user-experience/component-specific-light-dark-theme.mdindex 7d83f50..97697e8 100644--- a/skills/modern-web-guidance/guides/user-experience/component-specific-light-dark-theme.md+++ b/skills/modern-web-guidance/guides/user-experience/component-specific-light-dark-theme.md@@ -2,109 +2,174 @@The `light-dark()` function allows you to define two colors for a single property, which the browser automatically switches based on the current `color-scheme`. By scoping both the `light-dark()` variables and the `color-scheme` property to a specific component, you can create UI elements that can be independently forced into light or dark mode, regardless of the user's global system preference.-## Implementation steps--1. **MANDATORY: Enable `color-scheme` support.** The `light-dark()` function only resolves if the element (or an ancestor) has an explicit `color-scheme` value of `light`, `dark`, or `light dark`.-- ```css- :root {- /*- MANDATORY: Enable system-wide support for both themes.- Without this, the browser will not know how to resolve light-dark().- */- color-scheme: light dark;- }- ```--2. **Define semantic variables or properties using `light-dark()`.** Use the `light-dark(light-color, dark-color)` syntax.-- ```css- .themed-card {- /*- DO: Use semantic variables to define theme-aware colors.- The first argument is used when color-scheme is 'light'.- The second argument is used when color-scheme is 'dark'.- */- --card-bg: light-dark(#ffffff, #2d2e31);- --card-text: light-dark(#202124, #f8f9fa);-- background-color: var(--card-bg);- color: var(--card-text);- padding: 1.5rem;- border-radius: 8px;- }- ```--3. **Create theme overrides.** You can force a component instance into a specific theme by setting its `color-scheme` property using any valid CSS selector (classes, data attributes, etc.). This overrides the inherited system preference for that specific subtree.-- ```css- /*- DO: Use color-scheme to force a specific theme on a component.- You can use classes, data attributes, or any other selector.- */-- /* Using classes */- .themed-card.force-light {- color-scheme: light;- }-- /* Using data attributes (often preferred for state) */- .themed-card[data-theme="dark"] {- color-scheme: dark;- }- ```+## Why use component-specific themes?-## Critical Considerations+While most element's should follow the page-wide color scheme, there are several scenarios where you need more granular control over an element's theme:++- **Content-Driven Aesthetics**: Certain components work best in a specific mode. For example, **code editors**, **video players**, and **photo galleries** often use a particular theme to minimize distraction and make colors "pop," regardless of the user's OS setting.+- **User Preference Overrides**: You can empower users to manually toggle the theme of a specific component, like a chat box or a music player for example. This allows them to view a component in the mode that fits their environment or eye comfort.++## When to Change Colors vs. When to Force `color-scheme`++### 1. Change Colors when:+* You only need to update certain properties of author styled elements (like the background of a `<div>` or the color of an `<h1>`).+* The component doesn't contain any "native" interactive parts.+* **Result:** Only the parts you explicitly styled will change.++### 2. Force `color-scheme` when:+* You've decided that the built-in browser UI like **scrollbars** (e.g., a scrollable code block or sidebar) or **form controls** (like `<select>` menus, checkboxes, or date pickers) should use the colors of a particular color scheme.+* The component is best viewed in a particular color mode based on its content, for example, the dominant colors of a video, image, or graphic.+* **Result:** The browser automatically themes the "hidden" parts you can't easily reach with CSS, or the component is always viewed as intended in the design.++## Implementation Steps++### 1. Declare supported schemes in HTML+OPTIONAL: To help prevent a "flash of un-themed content" (FOUC), place a `<meta>` tag in your `<head>` to ensure the browser knows which themes you support before it even starts rendering. While this `<meta>` tag helps to avoid FOUC by setting the initial canvas color early, it may not completely eliminate flashes in all browsers or loading conditions.++```html+<!-- Optional: Declare support for both light and dark themes -->+<meta name="color-scheme" content="light dark">+```++### 2. Enable `color-scheme` support+OPTIONAL: Enable global support for both color schemes by setting `color-scheme: light dark;` on the `:root`.++```css+:root {+ /* **Optional:** Enable global support for both color schemes */+ color-scheme: light dark;+}+```-- **Supported Types**: Currently, `light-dark()` is only used for color values. It cannot be used for lengths, numbers, or other non-color types (e.g., `padding`, `font-size`, `opacity`).-- **MANDATORY: Two Arguments**: The function must always have exactly two arguments.+### 3. Define theme-aware variables+Using custom properties creates a **semantic abstraction layer** for your component's theme. This allows your styling to remain constant while the *values* of your variables adapt to the theme context. It also simplifies fallback management and provides the essential mechanism for re-resolving values in nested "theme islands" to avoid inheritance issues without repeating complex logic on every property.```css-/*- DO NOT: Attempt to use light-dark() for non-color properties like padding.- This will result in an invalid property value.-*/.themed-card {- padding: light-dark(10px, 20px);+ /* 1. Define raw brand colors for each mode */+ --card-bg-light: #ffffff;+ --card-bg-dark: #2d2e31;+ --card-text-light: #202124;+ --card-text-dark: #f8f9fa;++ /* 2. Modern enhancement using light-dark() */+ --card-bg: light-dark(var(--card-bg-light), var(--card-bg-dark));+ --card-text: light-dark(var(--card-text-light), var(--card-text-dark));++ /* 3. Apply custom properties on relevant properties values */++ background-color: var(--card-bg);+ /* **Mandatory**: Dynamic built-in properties that inherit (like color and accent-color) and are set with light-dark() must be applied on the element where the scheme changes.+ */+ color: var(--card-text);+ padding: 1.5rem;+ border-radius: 8px;}```+### 4. Create theme overrides+Force a component instance into a specific theme by setting its `color-scheme` property. This allows the component to ignore the global system preference.++```css+/* Force this specific card into dark mode */+.themed-card.force-dark {+ /* Dynamic custom properties don't need to be reapplied here since they were already defined on `.themed-card` */+ /* **Mandatory**: force component to use a particular color mode */+ color-scheme: dark;+}++/* Force this specific card into light mode */+.themed-card.force-light {+ /* Dynamic custom properties don't need to be reapplied here since they were already defined on `.themed-card` */+ /* **Mandatory**: Force component to use a particular color mode */+ color-scheme: light;+}+```++## Critical Considerations++- **The `@property` Risk**:+ - **Mandatory**: Do not register properties meant to be design tokens that dynamically switch based on `light-dark()` as `<color>`. If you need to animate a color variable, use a separate property.+- **Mandatory**: Do not set `color-scheme` on elements without a background.+ - The `@property` Risk **:+ - **Mandatory**: Do not register properties meant to be design tokens that dynamically switch based on `light-dark()` as `<color>`. If you need to animate a color variable, use a separate property. `light-dark()` resolves at computed value time, and registered properties inherit resolved, computed values, so the color would no longer be reactive to local theme changes. Descendant elements that change their `color-scheme` (e.g., a dark-themed card on a light page) will inherit the *already-resolved color* instead of the dynamic function.+ - Built-in inherited properties such as `color` and `accent-color` can also be affected by this issue. To prevent this, always reassign the dynamic theme variable on these built-in properties when they are inside of a nested theme.+ - **Example: Handling Built-In Inherited Properties**++ ```css+ :root {+ /* Define browser UI accent color for each mode */+ --brand-accent-light: #0056b3;+ --brand-accent-dark: #00e5ff;+ /* OPTIONAL: Apply dynamic color switching based on light-dark */+ --accent-color: light-dark(var(--brand-accent-light), var(--brand-accent-dark));++ /* MANDATORY: Automatically adapt native UI to user system preferences */+ color-scheme: light dark;+ /* Set built-in inherited property */+ accent-color: var(--accent-color);+ }++ textarea {+ color-scheme: dark;+ /* **Mandatory**: when nesting schemes, dynamic values set with light-dark() on built-in inherited properties must also be re-assigned on the element where the scheme changes */+ accent-color: var(--accent-color);+ }+ ```+- **System Colors**: Use system color keywords like `Canvas` (background) and `CanvasText` (text) for your custom components when you want them to match the browser's native themed surfaces exactly. This is ideal for ensuring consistency between your content and the browser's UI (like scrollbars) while automatically respecting OS-level accessibility features like High Contrast mode.+- **Respect User Preference**: **MANDATORY**: Avoid forcing a single theme on the overall page. While specific components (like a code editor) may benefit from a fixed theme, the main application should respect the user's system preference and ideally provide a manual toggle to allow users to choose between light, dark, or system-default modes.+- **Forcing a Theme**: Use a single value like `color-scheme: dark` or `color-scheme: light` ONLY for specific sections of your site (like a code editor or a video player) that must remain in one theme. Avoid applying this to the root element unless it's the result of an explicit user selection via a theme toggle.+- **Opting out of Auto-Dark Mode**: Use `color-scheme: only light` to prevent browsers (particularly on mobile) from automatically inverting your colors if you haven't yet implemented a dedicated dark theme or prefer not to show the component with a dark theme.+## Fallback strategiesBaseline status for light-dark(): Newly available. It's been Baseline since 2024-05-13.Baseline status for color-scheme: Widely available. It's been Baseline since 2022-02-03.-### Color Fallbacks-For browsers that do not support `light-dark()` or the `color-scheme` property, provide a fallback using `@media (prefers-color-scheme: dark)` or manual variable overrides.+- **Non-Color Properties**: Currently, `light-dark()` only supports color values. For other properties (like `padding` or `border-width`), you must continue using standard media queries or CSS Style Queries.+- **Progressive Enhancement**: Browsers that do not support `color-scheme` will ignore this property and use their default light-mode UI.+- **Handling `light-dark()` Support**: For browsers that support `color-scheme` but not yet `light-dark()`, light and dark versions of colors should first be defined as custom properties, and the `prefers-color-scheme` media query should be used to set colors for the respective mode like in the example below:```css.themed-card {- /*- MANDATORY: Define base fallback colors for browsers without light-dark().- Default to light mode values.+ /* 1. Define raw brand colors */+ --card-bg-light: #ffffff;+ --card-bg-dark: #2d2e31;+ --card-text-light: #202124;+ --card-text-dark: #f8f9fa;++ /* 2. Assign default (light) values */+ --card-bg: var(--card-bg-light);+ --card-text: var(--card-text-light);++ /* 3. Apply custom properties on relevant properties (light) values */++ background-color: var(--card-bg);+ /* **Mandatory**: Dynamic built-in properties that inherit (like color and accent-color) and are set with light-dark() must be applied on the element where the scheme changes.*/- --card-bg: #ffffff;- --card-text: #202124;+ color: var(--card-text);+ padding: 1.5rem;+ border-radius: 8px;}-/*- DO: Update variables based on system preference for older browsers.-*/+/* 3. Fallback for browsers without light-dark() support but with prefers-color-scheme */@media (prefers-color-scheme: dark) {.themed-card {- --card-bg: #2d2e31;- --card-text: #f8f9fa;+ --card-bg: var(--card-bg-dark);+ --card-text: var(--card-text-dark);}}-/*- DO: Use @supports to provide progressive enhancement for light-dark().- This ensures that per-component overrides (via color-scheme) work where supported.-*/+/* 4. Modern enhancement using light-dark() */@supports (color: light-dark(white, black)) {.themed-card {- --card-bg: light-dark(#ffffff, #2d2e31);- --card-text: light-dark(#202124, #f8f9fa);+ --card-bg: light-dark(var(--card-bg-light), var(--card-bg-dark));+ --card-text: light-dark(var(--card-text-light), var(--card-text-dark));}}++/* 5. Force a component into a specific color-scheme */+.themed-card.force-dark {+ color-scheme: dark;+}```