# Bad value “” for attribute “name” on element “input”: Must not be empty.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-for-attribute-name-on-element-input-must-not-be-empty
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `name` attribute on an `<input>` element identifies the form control's data when the form is submitted. It acts as the key in the key-value pair sent to the server (e.g., `email=user@example.com`). When you set `name=""`, the attribute is present but contains an empty string, which the HTML specification considers an invalid value. An empty name means the input's data will be excluded from the form's submission payload in most browsers, making it functionally useless for form processing.

This issue matters for several reasons:

- **Form functionality**: Inputs with empty names are typically omitted from form data, so the server never receives the user's input.
- **Standards compliance**: The HTML specification requires that if the `name` attribute is present, its value must not be empty.
- **JavaScript references**: An empty `name` makes it difficult to reference the element using methods like `document.getElementsByName()` or `FormData`.
- **Accessibility**: Screen readers and assistive technologies may use the `name` attribute to help identify form controls, and an empty value provides no useful information.

Note that the `name` attribute is not technically *required* on every `<input>` element — it's perfectly valid to omit it entirely. For example, inputs used purely for client-side JavaScript interactions without form submission don't need a `name`. The error specifically arises when the attribute is present but set to an empty string.

To fix the issue, either assign a meaningful name that describes the data the input collects, or remove the `name` attribute altogether if the input isn't part of a form submission.

## Examples

### ❌ Empty `name` attribute triggers the error

```html
<form action="/submit" method="post">
  <label for="email">Email:</label>
  <input type="email" id="email" name="">
  <button type="submit">Submit</button>
</form>
```

### ✅ Providing a meaningful `name` value

```html
<form action="/submit" method="post">
  <label for="email">Email:</label>
  <input type="email" id="email" name="email">
  <button type="submit">Submit</button>
</form>
```

### ✅ Removing `name` when the input isn't submitted

If the input is only used for client-side interaction and doesn't need to be part of form data, simply omit the attribute:

```html
<label for="search">Filter results:</label>
<input type="text" id="search">
```

### ❌ Multiple inputs with empty names

This pattern sometimes appears when inputs are generated dynamically with placeholder attributes:

```html
<form action="/register" method="post">
  <input type="text" name="">
  <input type="password" name="">
  <button type="submit">Register</button>
</form>
```

### ✅ Each input gets a descriptive name

```html
<form action="/register" method="post">
  <label for="username">Username:</label>
  <input type="text" id="username" name="username">
  <label for="password">Password:</label>
  <input type="password" id="password" name="password">
  <button type="submit">Register</button>
</form>
```
