References

Beginner-friendly references for web development, with live, editable examples.

The HTML name attribute

Attribute All modern browsers Updated
Quick answer

The HTML name attribute gives the control a name that is submitted with its value as a name/value pair. It is used on most form controls (<input>, <select>, <textarea>, <button>) as well as <form>, <iframe>, <map> and others.

Overview

The name attribute names a form control so its value is submitted with the <form>. Data is sent as name=value pairs, so a control with no name is not submitted at all — making it essential on every field you want to receive on the server.

It also does the grouping work for radio buttons: controls that share the same name form a mutually-exclusive group, so only one can be selected at a time — that is exactly how a radio group works. Checkboxes that share a name submit multiple values under that name.

Beyond forms, name appears on other elements with different meanings — on an <iframe> or <a> it names a browsing context that a target can point at, and on a <map> it connects to an image's usemap. Do not confuse it with id, which must be unique and is for CSS, JavaScript and anchors.

Syntax

<input type="text" name="username">

Values

Value
A string (the field name used in the submitted data).

Best practices

  • Give every control you want submitted a name — unnamed controls are not sent.
  • Use the same name on a set of radio buttons to group them into a mutually-exclusive choice.
  • Do not confuse name (for submission, can repeat) with id (unique, for CSS/JS/anchors).
  • Choose names the server expects to receive.

Frequently asked questions

What does the name attribute do?
It names a form control so its value is submitted with the form as a name=value pair.
Why isn't my input value being submitted?
It most likely has no name attribute — controls without a name are not included in the submission.
How do I group radio buttons?
Give them all the same name; only one in the group can then be selected.
What is the difference between name and id?
name is for form submission and can repeat; id must be unique and is used for CSS, JavaScript and anchor links.