Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
64a6d708f5a43f2cd3fde5d4d7db3905ba1bdf65
4 changes: 2 additions & 2 deletions skills/modern-web-guidance/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Search and retrieve standardized modern web best practices at the **start** of i

### Step 1. Search Use Cases

Run `modern-web-guidance` directly with `npx` using a **2–5 word action-oriented query** for a **single web platform capability or UI pattern**:
Run `modern-web-guidance` directly with `npx` using a **2–5 word action-oriented English query** for a **single web platform capability or UI pattern**:
- **Keep queries focused and generic**: Describe the user-visible capability (`<verb> + <UI/platform object>`, optionally paired with the target HTML/CSS/JS feature name if known). Omit framework/library names (`React`, `Vue`, `Tailwind`, etc.) and app/domain nouns (product, route, or component/file names). Split multi-feature tasks into separate `search` calls.
- **Name implied UI primitives**: When the user's prompt expresses intent without naming the UI primitive (e.g. "confirm first", "delete with confirmation", "pick a date"), translate the domain intent into the implied UI component or platform mechanism (e.g. search `"confirmation modal dialog"` or `"confirm dialog"` rather than `"confirm destructive action"`, or `"date picker input"` rather than `"pick a date"`).
- **Example**: Search `"light dismiss dialog"` or `"responsive data table"`, **not** `"dialog"` (too terse), `"responsive table dark mode"` (compound — split into two searches), or `"close React settings modal on outside click"` (framework/app noise).

```sh
npx -y modern-web-guidance@latest search "<query>" --skill-version 2026_11_09-5bcc021b
npx -y modern-web-guidance@latest search "<query>" --skill-version 2026_11_10-47b4c80e
```

> **Note**: Returns `[{ "id", "description" }, ...]`. Judge results by their `description` fields:
Expand Down
11 changes: 9 additions & 2 deletions skills/modern-web-guidance/guides/built-in-ai/translator.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

The **Translator API** allows developers to perform client-side text translation using built-in AI models in Chrome and Edge. This approach eliminates the need for cloud-based translation services for ephemeral content, reducing costs and improving privacy by keeping data on the user's device.


## Prerequisites & Requirements

### API Surface & Global Scope
Expand Down Expand Up @@ -38,6 +37,7 @@ To run Gemini Nano and associated models, the system needs:
**User Gesture Requirement:** When calling `availability(options)` returns `'downloadable'` or `'downloading'`, calling `Translator.create()` triggers the download of the language pack and **strictly requires a user gesture** (such as a button click) to prevent a `NotAllowedError`.

`Translator.availability(options)` returns one of four string statuses:

- `'available'`: The language pair model is already downloaded on the device and ready for immediate translation.
- `'downloadable'`: The language pair is supported, but the model needs to be downloaded. A user gesture is required to initiate `Translator.create()`.
- `'downloading'`: The language pack is currently in the process of downloading. Calling `Translator.create()` with a user gesture attaches to the download.
Expand Down Expand Up @@ -152,12 +152,18 @@ The API supports a wide range of BCP 47 language codes: Here are the languages s
- **zh**: Chinese
- **zh-Hant**: Chinese (Traditional)

## Accessibility considerations

**MANDATORY:** Apply the `lang` attribute to the container element for the translated content, and make sure that its value matches the BCP 47 language code for the target language, for example `lang="es"` for Spanish.

## Security & Performance

- **Permissions Policy:** Cross-origin iframes require explicit permission.

```html
<iframe src="https://example.com/" allow="translator"></iframe>
```

- **Web Workers:** Currently **not supported** due to Permission Policy
complexities.
- **Privacy:** No data is sent to Google servers during the translation process
Expand All @@ -179,9 +185,10 @@ if ('Translator' in self) {
}
```

If the `Translator` API is unsupported or availability checks return `'unavailable'`, you must gracefully fall back.
If the `Translator` API is unsupported or availability checks return `'unavailable'`, you must gracefully fall back.

Recommended options:

1. **Remote API Fallback**: Redirect the translation request to a server endpoint or cloud remote API (such as the Vertex AI Gemini API) to deliver translation functionality.
2. **Graceful Degradation**: Visually disable translation control elements or buttons while showing an end-user friendly note (e.g., `"Client-side translation is currently unsupported in this browser"`). Do not allow unhandled exceptions.
3. **Polyfill Fallback**: You can use community-maintained polyfills like `built-in-ai-task-apis-polyfills` or `prompt-api-polyfill` to emulate the API surface using remote services.
Expand Down
10 changes: 6 additions & 4 deletions skills/modern-web-guidance/guides/css/css-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ Baseline status for Popover: Newly available. It's been Baseline since 2025-01-2
Supported by: Chrome 116 (Aug 2023), Edge 116 (Aug 2023), Firefox 125 (Apr 2024), Safari 17 (Sep 2023), and Safari iOS 18.3 (Jan 2025).

Browser support for Anchor positioning: Limited availability.
Supported by: Safari 27 (Sep 2026).
Unsupported in: Chrome, Edge, and Firefox.
Supported by: Chrome 157 (Nov 2026), Edge 157 (Nov 2026), and Safari 27 (Sep 2026).
Unsupported in: Firefox.

**When to use each overlay primitive:**

Expand All @@ -228,7 +228,7 @@ Unsupported in: Chrome, Edge, and Firefox.
**Anchor positioning (spatial layout of overlays):**

- Use `position-area` (or `anchor()` on insets) and `anchor-size()` to position and size an overlay relative to its trigger.
- Use `position-try-fallbacks: flip-block` (or `flip-inline`) to let the browser reposition when the overlay overflows the viewport.
- Use `position-try-fallbacks` to let the browser reposition when the overlay overflows the viewport. `flip-block, flip-inline, flip-block flip-inline` is a reasonable default, or define use-case specific fallbacks.
- Don't mix physical and logical keywords in a single `position-area` value — pick one coordinate system.
- Feature-detect with `@supports (anchor-name: --x)` and provide an absolute-position fallback.

Expand Down Expand Up @@ -288,7 +288,9 @@ Supported by: Chrome 108 (Nov 2022), Edge 108 (Dec 2022), Firefox 101 (May 2022)

## 8 Grid lanes (aka masonry)

Grid lanes is not natively supported by any major browser yet.
Browser support for Grid lanes: Limited availability.
Supported by: Safari 27.2.
Unsupported in: Chrome, Edge, and Firefox.

The specification is in development under the name "grid lanes" (e.g., `display: grid-lanes`), while earlier experimental prototypes used `grid-template-rows: masonry`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Give each form submit button a value that says what it does. Use a clear, recogn
Allow your users to enter their name using a single input, unless you have a good reason for separately storing given names, family names, honorifics, or other name parts. Using a single name input makes forms less complex, enables cut-and-paste, and makes autofill simpler. Use `autocomplete="name"` for a single input for name.

```html
<input type="text" id="full-name" name="ful-name" autocomplete="name">
<input type="text" id="full-name" name="full-name" autocomplete="name">
```

Allow international names. For validation, avoid using regular expressions that only match Latin characters. Latin-only excludes users with names or addresses that include characters that aren't in the Latin alphabet. Allow Unicode letter matching instead—and ensure your backend supports Unicode securely as both input and output. Unicode in regular expressions is well supported by modern browsers.
Expand Down
4 changes: 3 additions & 1 deletion skills/modern-web-guidance/guides/forms/slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ input[type="range"]::-moz-range-thumb {
}
```

Always provide a visible keyboard focus indicator after removing the native appearance. Do not use color alone:
Ensure the track color has a contrast of at least `3:1` with the background color.

Always provide a visible keyboard focus indicator after removing the native appearance. Ensure the focus indicator has a contrast of at least `3:1` with the background color or the adjacent track. Do not use color alone:

```css
input[type="range"]:focus-visible {
Expand Down
4 changes: 2 additions & 2 deletions skills/modern-web-guidance/guides/forms/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Add the boolean `switch` attribute to a standard checkbox input:

## Styling

Customize the control's highlight color using `accent-color` (see `brand-consistent-forms` (via `npx -y modern-web-guidance@latest retrieve "brand-consistent-forms"`)) and ensure visible focus styling:
Customize the control's highlight color using `accent-color` (see `brand-consistent-forms` (via `npx -y modern-web-guidance@latest retrieve "brand-consistent-forms"`)) and ensure visible focus styling with a contrast ratio of at least 3:1 against adjacent colors (WCAG 1.4.11 Non-text Contrast):

```css
input[type="checkbox"][switch] {
Expand All @@ -28,7 +28,7 @@ input[type="checkbox"][switch] {
}

input[type="checkbox"][switch]:focus-visible {
outline: 3px solid var(--focus-color, #ff8c00);
outline: 3px solid var(--focus-color, #d35400);
outline-offset: 4px;
}
```
Expand Down
18 changes: 14 additions & 4 deletions skills/modern-web-guidance/guides/html/custom-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A custom element is a class registered against a tag name via `customElements.define()`. Registration and basic lifecycle are well understood; the rules below target the parts routinely implemented incorrectly.

A custom element has no role or keyboard behavior of its own. That's fine when its content already carries the meaning, for example a layout wrapper around headings and text. If it needs semantics or keyboard support, build it from native elements such as `<button>` inside its template, or give it a role and ARIA state through `ElementInternals`, and focus handling, as described in `accessible-web-components` (via `npx -y modern-web-guidance@latest retrieve "accessible-web-components"`). If its content is purely decorative, hide it from assistive technologies with `aria-hidden="true"`.

## Lifecycle: the parts that get implemented wrong

The callbacks themselves are well documented; these are the misconceptions that cause bugs:
Expand All @@ -22,15 +24,16 @@ Two consequences models routinely miss:
1. **Attributes and children may already be present** when your constructor/`connectedCallback` runs on upgrade. Read existing attributes in `connectedCallback` to sync initial state, and never assume the element started empty.
2. **Children may still be missing** even in `connectedCallback` — the HTML parser can yield mid-parse of long child lists, so the callback sometimes runs before every child is attached. See the constructor bullet in *Lifecycle* above for the pattern (`slotchange` + `attributeChangedCallback`).

Hide undefined elements to avoid a flash of unstyled content — but **fail open**, so the content stays reachable if the script never loads. Animate `opacity` with a delay rather than hard-hiding with `visibility: hidden`, so the element reveals itself after a timeout even when it is never upgraded:
Hide undefined elements to avoid a flash of unstyled content — but **fail open**, so the content stays reachable if the script never loads. Hide them with `visibility: hidden`, which also removes their content from the tab order and the accessibility tree while it can't be seen (`opacity: 0` on its own leaves focusable descendants in the tab order, invisible; WCAG 2.4.7 Focus Visible), and animate `visibility` back with a delay, so the element reveals itself after a timeout even when it is never upgraded. `visibility` switches rather than fades, so if you also want the element to fade in, add `opacity: 0` and animate it alongside `visibility`; the opacity is optional:

```css
my-element:not(:defined) {
opacity: 0;
visibility: hidden;
opacity: 0; /* Optional: fades the element in as it becomes visible. */
/* Reveal anyway after 2s, so a failed or slow script never hides content for good. */
animation: defined-fallback 0.2s 2s forwards;
}
@keyframes defined-fallback { to { opacity: 1; } }
@keyframes defined-fallback { to { visibility: visible; opacity: 1; } }
```

Scope these guards to the elements that need them — or to a specific subtree via `:has(:not(:defined))` — rather than the whole `body`. One slow, non-critical widget (a share button, say) should not delay paint for the entire page.
Expand Down Expand Up @@ -73,6 +76,8 @@ Pitfalls:

- **`observedAttributes` discipline**: list only attributes whose change must re-render or trigger a side effect. Observing everything adds a callback to every mutation for no benefit.
- **Reflection loops**: a setter that writes an attribute will re-enter `attributeChangedCallback`. Guard with an `oldVal !== newVal` check, as above.
- **Accessible state**: derive the state you expose to assistive technologies (ARIA state through `ElementInternals`, or attributes on the native control inside) from the same source of truth as the visible state, and update it on every path that changes it: attributes read on upgrade, `attributeChangedCallback`, property setters, and user interaction. Otherwise a state set from markup or by a consumer's script changes what's shown but not what's announced (WCAG 4.1.2 Name, Role, Value).
- **Re-rendering**: update only the nodes that change rather than rebuilding the shadow tree with `innerHTML`. Replacing an element that has focus moves focus to `<body>`, and keyboard and screen reader users lose their place (WCAG 2.4.3 Focus Order).
- **Style-only state**: for internal state that exists only to drive styling (loading, active, expanded), prefer **custom states** over reflecting a synthetic attribute — see [Custom states](#custom-states) below. Reflect to an attribute only when consumers must be able to set the state from markup.

## Custom states
Expand All @@ -94,21 +99,26 @@ class AsyncButton extends HTMLElement {
async run() {
if (this.#internals.states.has('busy')) return; // guard re-entry
this.#internals.states.add('busy');
this.#internals.ariaBusy = 'true'; // assistive technologies don't see custom states
this.#internals.states.delete('success');
this.#internals.states.delete('error');
try {
await this.#action();
this.#internals.states.add('success');
} catch {
this.#internals.states.add('error');
} finally {
this.#internals.states.delete('busy');
this.#internals.ariaBusy = 'false';
}
}
}
```

`CustomStateSet` is a set, so independent states compose (`busy` plus `error`) without inventing a combined `data-status` enum.

Custom states only reach CSS: assistive technologies don't see them. When a state tells the user something (busy, success, error, invalid, expanded), also expose it to assistive technologies, as ARIA state through `ElementInternals` (as with `ariaBusy` above) or on the native control inside the component, show it in text rather than color alone, and announce the outcome of an action, such as a save succeeding or failing, as a status message (WCAG 4.1.2 Name, Role, Value; 1.4.1 Use of Color; 4.1.3 Status Messages).

**Custom state is runtime-only.** It is not serialized to the DOM, so it does not survive a reload, the element being re-created, or server rendering. If the state must be set declaratively in markup or persist across loads, that is a job for an **attribute** (see [Where the value lives](#where-the-value-lives)) — restore it in `connectedCallback` from your source of truth. Rule of thumb: custom state for what the component derives and owns at runtime and only needs to *style*; an attribute for what must be set from markup or serialized.

For styling these states — both inside the component and from a consumer's stylesheet — see `styling-web-components` (via `npx -y modern-web-guidance@latest retrieve "styling-web-components"`).
Expand All @@ -117,6 +127,6 @@ For styling these states — both inside the component and from a consumer's sty

- True-private state: native `#` fields (`#count`) for hard encapsulation; a `_` prefix only when subclasses must still reach it. Note `#` fields are not inherited — a subclass cannot see a base class's private fields.
- Symbol-keyed properties are a middle ground: hidden from ordinary enumeration, but reachable by any code holding the symbol (export it, or expose it as a `static` field on the class). Because each symbol is unique, two symbols sharing a description never collide — handy when a subclass or sibling needs controlled access that `#` fields can't provide.
- Do **not** shadow global attributes (`style`, `class`, `id`, `slot`, `part`, `title`, `lang`, `dir`) with your own properties; doing so breaks their built-in behavior. Note `disabled` is only global on form controls; on other elements you must implement its effect yourself.
- Do **not** shadow global attributes (such as `style`, `class`, `id`, `slot`, `part`, `title`, `lang`, `dir`) with your own properties, for example a `role` or `ariaLabel` class field; doing so breaks their built-in behavior, and a consumer setting the property no longer changes the attribute or what assistive technologies receive. Note `disabled` is only global on form controls; on other elements you must implement its effect yourself, including ignoring activation and exposing the state to assistive technologies (for example `this.#internals.ariaDisabled = 'true'`). If the component's styles set `display` on `:host`, also add `:host([hidden]) { display: none; }`, or the `hidden` attribute stops hiding the element and its content stays visible, focusable and in the accessibility tree.

When naming a new API surface, follow the platform's own conventions: use lowercase kebab-case with at least one hyphen for custom element tag names (for example `my-toggle`), `lowerCamelCase` for properties and methods, and lowercase attribute names synchronized with their corresponding properties.
Loading