CKTIS / HTML
HTML element: button
The native button element represents a labeled command and can act as a form control whose type determines its behavior.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<button type="submit" name="action" value="save">Save</button>button supports type values submit, reset, and button; reset discards user changes, so offer it only for a clear requirement.
For an ordinary form button, missing or invalid type leads to submit behavior; explicitly use type="button" for a script-only action to avoid accidental submission.
Only the activated submitter contributes its name and value; SubmitEvent.submitter identifies that control, and the FormData constructor can include it.
disabled prevents activation and data contribution. An ordinary button cannot contain interactive descendants such as a or input, or a descendant with tabindex; visible content should name the action clearly.
Examples
<!doctype html>
<meta charset="utf-8">
<form id="order">
<label>Item <input name="item" value="book"></label>
<button id="save" name="action" value="save">Save order</button>
<button id="preview" type="button">Preview</button>
</form>
<output id="result"></output>
<script>
const order = document.querySelector("#order");
const save = document.querySelector("#save");
const preview = document.querySelector("#preview");
order.addEventListener("submit", event => {
event.preventDefault();
const data = new FormData(order, event.submitter);
document.querySelector("#result").textContent = `submitter=${event.submitter.id}; action=${data.get("action")}; item=${data.get("item")}; saveType=${save.type}; previewType=${preview.type}`;
}, { once: true });
save.click();
</script>
Result
submitter=save; action=save; item=book; saveType=submit; previewType=button
The example calls `click()` on the `submit` button and uses `FormData` to observe the chosen submitter, field data, and explicit preview-button type.