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.

Forms & controls

Connect a visible label to a control

Web platform

A label’s for matches an input’s id. name supplies the form submission key; id supplies document identity. A placeholder does not replace a persistent label.

Fragment

Web platform · Connect a visible label to a control
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
<label for="email">Email</label>
<input id="email" name="email" type="email" autocomplete="email">

Make submit behavior deliberate

Web platform

Inside a form, a button without an explicit non-submit type commonly submits the form. Use type=button for an unrelated action. disabled controls are not successful submitted controls.

Fragment

Web platform · Make submit behavior deliberate
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
<form>
  <button type="button">Preview</button>
  <button type="submit">Save</button>
</form>

Collect form values and repeated fields

Web platform

FormData collects successful named controls. Repeated names require getAll; an unchecked checkbox is normally absent. Values can be strings or File objects.

Fragment

Web platform · Collect form values and repeated fields
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const form = document.querySelector<HTMLFormElement>("#profile");
if (!form) throw new Error("Missing form");
const data = new FormData(form);
const tags = data.getAll("tag");

FormData does not make client input trusted. Validate the server’s required shape and business rules.

Use native validation as one feedback layer

Web platform

required, type, min/max and length attributes enable browser validation. Applications still need server-side validation and a deliberate policy for values from other clients.

Fragment

Web platform · Use native validation as one feedback layer
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
<input name="quantity" type="number" min="1" max="99" required>
<input name="code" minlength="2" maxlength="20">

Browser number inputs have empty/invalid states; do not assume every input event carries a valid number.