Reference

HTML, CSS & browser APIs

Look up semantic HTML, forms, CSS layout, events, DOM operations and common browser APIs.

Scope and conventions

Modern browser platform examples, independent of a framework. HTML/CSS excerpts belong in the appropriate document/style context; DOM snippets assume a browser and named elements/data; TypeScript annotations clarify DOM types and need compilation or removal in plain JavaScript. Check target-browser support for newer features.

Browser APIs

Store strings with origin-scoped browser storage

Web platform

localStorage persists strings across ordinary page sessions; sessionStorage has a tab/session lifetime. Storage access can fail, and storage is not an authorization boundary.

Fragment

Web platform · Store strings with origin-scoped browser storage
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
try {
  localStorage.setItem("draft", JSON.stringify(draft));
  const stored = localStorage.getItem("draft");
} catch (error) {
  showStorageUnavailable();
}

Same-origin script can read these values. Plan quota, privacy-mode and schema-version behavior; do not treat browser storage as a protected credential vault.

Construct URLs and query parameters

Web platform

URL resolves references and exposes structured components. URLSearchParams encodes values; it does not define an application’s duplicate-parameter policy.

Fragment

Web platform · Construct URLs and query parameters
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const url = new URL("/items", location.origin);
url.searchParams.set("q", "tea & milk");
url.searchParams.append("tag", "green");

Observe size or intersection and disconnect

Web platform

ResizeObserver reports size changes; IntersectionObserver reports intersection relative to its configured root. Neither proves a user paid attention to an element.

Fragment

Web platform · Observe size or intersection and disconnect
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const observer = new ResizeObserver(entries => {
  for (const entry of entries) recordSize(entry.contentBoxSize[0]);
});
observer.observe(panel);
// When the owner is disposed:
observer.disconnect();

Avoid synchronous layout-feedback loops that repeatedly resize the observed element.

Schedule visual work with an explicit cancellation handle

Web platform

requestAnimationFrame schedules a callback for a rendering opportunity. The timestamp is useful for time-based motion; one callback does not prove a paint already happened.

Fragment

Web platform · Schedule visual work with an explicit cancellation handle
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const frame = requestAnimationFrame(timestamp => updateVisuals(timestamp));
// If the owner disappears first:
cancelAnimationFrame(frame);

Format an instant in a named time zone

Web platform

Date stores an instant as milliseconds relative to the Unix epoch. Intl.DateTimeFormat applies locale and time-zone presentation; a local calendar date is a different domain concept.

Fragment

Web platform · Format an instant in a named time zone
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const instant = new Date("2026-01-02T15:04:05Z");
const formatted = new Intl.DateTimeFormat("en", {
  dateStyle: "medium", timeStyle: "short", timeZone: "UTC"
}).format(instant);

Do not infer a universal date parser from this explicit ISO timestamp. Calendar arithmetic and elapsed-duration arithmetic differ around time-zone transitions.

Write clipboard text from an allowed user action

Web platform

The async Clipboard API normally requires a secure context and browser permission/activation policy. Handle denial and provide an alternative way to select/copy text.

Fragment

Web platform · Write clipboard text from an allowed user action
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
async function copyText(text: string) {
  try { await navigator.clipboard.writeText(text); }
  catch { showSelectableText(text); }
}