Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML name attribute — element-specific meaning

The `name` attribute supplies an element-specific name: a form-data key, navigation target name, image-map name, `details` group, slot name, or metadata name. It is not a global attribute or a replacement for `id`.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

name="value"

name is not a global attribute: its meaning and constraints depend on the element. It does not replace id or a user-facing accessible label. In particular, label[for] references a control's id, not its name.

On form controls, name supplies the name used in submission and the form.elements collection. A specified value must not be empty or isindex. Repeated names can produce multiple entries; a shared name also groups radio buttons belonging to the same form and tree. An ordinary unnamed text input contributes no entry. A name alone does not guarantee submission: disabled controls and unchecked checkboxes, for example, are omitted. Avoid built-in form property names such as submit: they can shadow those properties in the DOM.

On form, the name supports lookup through document.forms; it must be nonempty and unique within that collection. On iframe and, where applicable, object, it names the internal navigation target when that target is created, for example for use with target. It must be a valid navigable target name. On map, the attribute is required: the name referenced by usemap must be nonempty, contain no ASCII whitespace, and be unique in its tree; any specified id must match it.

On details, a shared nonempty name creates a group within the same tree: opening one member closes the others. Do not nest members of the same group or declare multiple members open. Consider whether users need to view several sections simultaneously. On slot, the name identifies a slot in a shadow tree and matches the slot attribute of a host's child; it may be an empty string.

On meta, the name identifies the metadata kind, such as description, while content supplies its value. Metadata names are compared ASCII case-insensitively. Do not combine name with http-equiv, charset, or itemprop on the same meta.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>name example</title>
<form id="profile" name="profileForm">
  <label>City <input id="city" name="city" value="Warsaw"></label>
  <input name="tag" value="html" type="hidden">
  <input name="tag" value="forms" type="hidden">
  <label>Ignored <input value="not submitted"></label>
</form>
<pre id="result"></pre>
<script>
  const form = document.getElementById("profile");
  const pairs = [...new FormData(form).entries()];
  document.getElementById("result").textContent = JSON.stringify(pairs);
</script>
</html>

Result

[["city","Warsaw"],["tag","html"],["tag","forms"]]

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources