Keep your coding agent up to date with the latest web best practices
Release v0.0.87
github-actions[bot]1c64ff25e238
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.jsonindex 9e4db14..0729332 100644--- a/.claude-plugin/marketplace.json+++ b/.claude-plugin/marketplace.json@@ -8,7 +8,7 @@"name": "modern-web-guidance","source": "./","description": "Google Chrome's agent skills collection",- "version": "0.0.86"+ "version": "0.0.87"}]}diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.jsonindex b38d3cc..fe44485 100644--- a/.claude-plugin/plugin.json+++ b/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Google Chrome's agent skills collection",- "version": "0.0.86",+ "version": "0.0.87","author": {"name": "Google Chrome"}diff --git a/README.md b/README.mdindex c99d7ae..0623893 100644--- a/README.md+++ b/README.md@@ -2,10 +2,10 @@This curated collection of skills, tools, and AI-ready documentation injects Chrome's web platform knowledge directly into your workflow, ensuring your coding agent builds apps that are modern, fast, and secure by default.-#### Skill Coverage in `v0.0.86`+#### Skill Coverage in `v0.0.87`<details>-<summary><strong>79 web features with implementation guidance from Chrome's experts</strong>: `::backdrop`, `:autofill`, `:has()`, `:not()`, `:user-valid and :user-invalid`, `@starting-style`, `<details>`, `<dialog closedby>`, `<dialog>`, `<link rel="expect">`, `<link rel="preload">`, `AbortController and AbortSignal`, `accent-color`, `Active view transition`, `Anchor positioning`, `blocking="render"`, `calc-size()`, `color-scheme`, `Container queries`, `content-visibility`, `Cross-document view transitions`, `Customizable <select>`, `Email, telephone, and URL <input> types`, `enterkeyhint`, `Fetch`, `Fetch priority`, `fetchLater`, `field-sizing`, `font-size-adjust`, `Form-associated WebMCP attributes`, `hidden="until-found"`, `image-set()`, `Individual transform properties`, `inert`, `inputmode`, `Interest invokers`, `interpolate-size`, `Intersection observer`, `Intl.DurationFormat`, `Invoker commands`, `Language detector`, `light-dark()`, `linear() easing`, `Long animation frames`, `Masks`, `moveBefore()`, `Mutually exclusive <details> elements`, `Navigation API`, `navigator.modelContext`, `overlay`, `Page visibility`, `Page visibility state`, `Popover`, `popover="hint"`, `prefers-color-scheme media query`, `prefers-contrast media query`, `prefers-reduced-motion media query`, `Registered custom properties`, `Scheduler API`, `Scroll snap`, `Scroll-driven animations`, `scroll-initial-target`, `scrollbar-color`, `scrollbar-width`, `scrollIntoView()`, `sibling-count() and sibling-index()`, `sin(), cos(), tan(), asin(), acos(), atan(), and atan2() (CSS)`, `Speculation rules`, `Summarizer`, `Temporal`, `text-box`, `text-wrap`, `text-wrap: balance`, `text-wrap: pretty`, `Top-level await`, `transition-behavior`, `Translator`, `View transitions`, `view-transition-class`</summary>+<summary><strong>80 web features with implementation guidance from Chrome's experts</strong>: `::backdrop`, `:autofill`, `:has()`, `:not()`, `:user-valid and :user-invalid`, `@starting-style`, `<details>`, `<dialog closedby>`, `<dialog>`, `<link rel="expect">`, `<link rel="preload">`, `AbortController and AbortSignal`, `accent-color`, `Active view transition`, `Anchor position container queries`, `Anchor positioning`, `blocking="render"`, `calc-size()`, `color-scheme`, `Container queries`, `content-visibility`, `Cross-document view transitions`, `Customizable <select>`, `Email, telephone, and URL <input> types`, `enterkeyhint`, `Fetch`, `Fetch priority`, `fetchLater`, `field-sizing`, `font-size-adjust`, `Form-associated WebMCP attributes`, `hidden="until-found"`, `image-set()`, `Individual transform properties`, `inert`, `inputmode`, `Interest invokers`, `interpolate-size`, `Intersection observer`, `Intl.DurationFormat`, `Invoker commands`, `Language detector`, `light-dark()`, `linear() easing`, `Long animation frames`, `Masks`, `moveBefore()`, `Mutually exclusive <details> elements`, `Navigation API`, `navigator.modelContext`, `overlay`, `Page visibility`, `Page visibility state`, `Popover`, `popover="hint"`, `prefers-color-scheme media query`, `prefers-contrast media query`, `prefers-reduced-motion media query`, `Registered custom properties`, `Scheduler API`, `Scroll snap`, `Scroll-driven animations`, `scroll-initial-target`, `scrollbar-color`, `scrollbar-width`, `scrollIntoView()`, `sibling-count() and sibling-index()`, `sin(), cos(), tan(), asin(), acos(), atan(), and atan2() (CSS)`, `Speculation rules`, `Summarizer`, `Temporal`, `text-box`, `text-wrap`, `text-wrap: balance`, `text-wrap: pretty`, `Top-level await`, `transition-behavior`, `Translator`, `View transitions`, `view-transition-class`</summary>- **[::backdrop](https://webstatus.dev/features/backdrop), [<dialog>](https://webstatus.dev/features/dialog), [overlay](https://webstatus.dev/features/overlay), [Popover](https://webstatus.dev/features/popover), [@starting-style](https://webstatus.dev/features/starting-style), [transition-behavior](https://webstatus.dev/features/transition-behavior)**- **animate-to-from-top-layer**: Animate elements such as dialogs, popovers, and tooltips as they're entering/exiting the top layer.@@ -37,6 +37,8 @@ This curated collection of skills, tools, and AI-ready documentation injects Chr- **brand-consistent-forms**: Match checkboxes, radio buttons, range sliders, and progress bars to your site's color palette without replacing them with custom components.- **[Active view transition](https://webstatus.dev/features/active-view-transition), [View transitions](https://webstatus.dev/features/view-transitions)**- **directional-navigation-transitions**: 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.+- **[Anchor position container queries](https://webstatus.dev/features/container-anchor-position-queries), [Popover](https://webstatus.dev/features/popover)**+ - **position-aware-tooltips**: Build tooltips and popovers with directional arrows (or other visual styling) that automatically point the correct way when the element flips to a fallback position.- **[Anchor positioning](https://webstatus.dev/features/anchor-positioning), [prefers-reduced-motion media query](https://webstatus.dev/features/prefers-reduced-motion)**- **anchor-positioning-tab-underline**: Transition an element seamlessly between two target element positions. For example, moving a selected tab underline between the previously selected tab and the currently selected tab.- **[Anchor positioning](https://webstatus.dev/features/anchor-positioning), [Interest invokers](https://webstatus.dev/features/interest-invokers), [Popover](https://webstatus.dev/features/popover), [popover="hint"](https://webstatus.dev/features/popover-hint)**diff --git a/gemini-extension.json b/gemini-extension.jsonindex be1e6e0..bb20417 100644--- a/gemini-extension.json+++ b/gemini-extension.json@@ -1,7 +1,7 @@{"name": "modern-web-guidance","description": "Google Chrome's web development agent skills.",- "version": "0.0.86",+ "version": "0.0.87","author": {"name": "Google Chrome"}diff --git a/package.json b/package.jsonindex 267b98e..23076e5 100644--- a/package.json+++ b/package.json@@ -2,7 +2,7 @@"name": "modern-web-guidance","displayName": "Modern Web Guidance","description": "Curated collection of agent skills for modern web development.",- "version": "0.0.86",+ "version": "0.0.87","publisher": "GoogleChrome","engines": {"vscode": "^1.90.0",diff --git a/skills/modern-web/guides/user-experience/position-aware-tooltips.md b/skills/modern-web/guides/user-experience/position-aware-tooltips.mdnew file mode 100644index 0000000..28966ff--- /dev/null+++ b/skills/modern-web/guides/user-experience/position-aware-tooltips.md@@ -0,0 +1,151 @@+When building tooltips or popovers with CSS Anchor Positioning, the browser can automatically "flip" the element to a fallback position if it would otherwise overflow the viewport. When this happens, you may want to adjust the style of the positioned content, for instance to reposition an arrow that points from the positioned content to the anchor.++**Anchored Container Queries** solve this by allowing you to query the active positioning state of an element and apply styles accordingly.++## The problem++Imagine a tooltip that appears above its anchor by default. It has a "down" arrow at the bottom. If the user scrolls and the tooltip flips to appear *below* the anchor, the arrow is now pointing the wrong way and is on the wrong side of the tooltip.++## The solution: Anchored Container Queries++By setting `container-type: anchored` on your positioned element, you turn it into a query container that knows about its own anchor-positioned state. You can then use the `@container anchored()` query to update its descendants or pseudo-elements.++### 1. Create the tooltip and trigger++Use the Popover API to create a tooltip. This creates an implicit anchor connection that can be used for positioning.++```html+<button popovertarget="tooltip" id="anchor">anchor</button>+<div id="tooltip" popover role="tooltip"></div>+```++Reset the popover inset and margin styles for use with anchor positioning, but only if anchor positioning is supported.++```css+@supports (anchor-name: --my-anchor) {+ [popover] {+ inset: auto;+ margin: unset;+ }+}+```++### 2. Set up the container++Apply `container-type: anchored` to the element being positioned. This element must also have `position-try-fallbacks` defined to enable the flipping behavior.++```css+#tooltip {+ position: fixed;+ position-area: block-start;+ position-try-fallbacks: flip-block;++ /* Enable anchored container queries */+ container-type: anchored;+}+```++### 3. Style based on the fallback++Use `@container anchored(fallback: <value>)` to apply styles when a specific fallback is active.++Like all container queries, `@container` can only style **descendants** of the container. A common strategy to create the arrows is with the `::before` and `::after` pseudo-elements, which are treated as descendants and can be styled directly. However, to style the tooltip itself (as seen in step 4), we will add a child element to the tooltip, and create the arrow in its `::before` pseudo-element.++```html+<div id="tooltip" popover role="tooltip">+ <div class="tooltip-content">Tooltip</div>+</div>+```++```css+.tooltip-content::before {+ /* Default "down" arrow for the 'top' position */+ content: "▼";+ position: absolute;+ inset-block-end: 0;+ inset-inline-start: 1rem;+}++/* Update to an "up" arrow when the 'flip-block' fallback (bottom) is active */+@container anchored(fallback: flip-block) {+ .tooltip-content::before {+ content: "▲";+ inset-block-start: 0;+ inset-block-end: auto;+ }+}+```++## 4. Styling the container itself++If you need to change properties on the container itself (like `margin` or `background-color`) when it flips, you should use an **inner wrapper element**.++1. Apply `container-type: anchored` to the outer positioned element.+2. Target the inner element inside the `@container` block.+++```css+@container anchored(fallback: flip-block) {+ .tooltip-content {+ border-radius: 0 0 .5rem .5rem;+ margin-block-start: 0.25rem;+ }+}+```++## Best practices++- **Prefer logical fallbacks**: Use keywords like `flip-block` and `flip-inline` in `position-try-fallbacks` for simpler queries that handle RTL and different writing modes automatically.+- **Use pseudo-elements for arrows**: Tooltip arrows are purely decorative and are perfect candidates for `::before` or `::after`, which can be styled via anchored container queries without extra DOM.+++## Fallback strategies++Anchor position container queries has limited availability.++Positioning the arrow based on the applied fallback is a progressive enhancement, and there is not another way of reacting to the fallback position. To hide the arrow in browsers that don't support anchor position container queries, test for CSS support with `@supports (container-type: anchored)`.++```css+@supports (container-type: anchored) {+ .tooltip-content::before {+ content: "▼";+ }+}+```++### Polyfilling the Popover Attribute++Baseline status for Popover: Newly available. It's been Baseline since 2025-01-27.++To support the `popover` attribute in older browsers, use the `@oddbird/popover-polyfill`.++MANDATORY: Feature detect popover support by checking for the `popover` property on the `HTMLElement` prototype. Conditionally initialize the polyfill only if native support is missing.++**Option 1: Using a package manager**+Install the package (`npm install @oddbird/popover-polyfill`).++```javascript+// MANDATORY: Feature detect 'popover' on HTMLElement.prototype.+if (!('popover' in HTMLElement.prototype)) {+ import('@oddbird/popover-polyfill/fn').then(({ apply }) => {+ apply();+ });+}+```++**Option 2: Manual installation without npm**+If you are not using a package manager, dynamically import the polyfill directly from a CDN (such as unpkg) inside a `<script type="module">`.++```html+<script type="module">+ // MANDATORY: Feature detect 'popover' on HTMLElement.prototype.+ // Conditionally load the popover-polyfill from a CDN only in browsers lacking native support.+ if (!('popover' in HTMLElement.prototype)) {+ import('https://unpkg.com/@oddbird/popover-polyfill@latest/dist/popover-fn.js').then(({ apply }) => {+ apply();+ });+ }+</script>+```++Browsers without support for the Popover API also do not support anchor positioning, so the tooltip will appear in the center of the screen.\ No newline at end of file