# Bad value “” for attribute “action” on element “form”: Must be non-empty.

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

The `action` attribute tells the browser where to send form data when the form is submitted. According to the WHATWG HTML living standard, if the `action` attribute is specified, its value must be a valid non-empty URL potentially surrounded by spaces. An empty string (`""`) does not satisfy this requirement, which is why the W3C validator flags it.

While some developers use `action=""` intending the form to submit to the current page's URL, this approach is non-conforming HTML. Browsers do typically interpret an empty `action` as "submit to the current URL," but relying on this behavior is unnecessary since simply omitting the `action` attribute achieves the same result in a standards-compliant way. When no `action` attribute is present, the form submits to the URL of the page containing the form — this is the defined default behavior per the HTML specification.

This issue matters for several reasons:

- **Standards compliance:** Non-conforming HTML can lead to unexpected behavior across different browsers or future browser versions.
- **Maintainability:** Using the correct approach makes your intent clearer to other developers. Omitting `action` explicitly signals "submit to the current page," while `action=""` looks like a mistake or a placeholder that was never filled in.
- **Tooling:** Build tools, linters, and automated testing pipelines that rely on valid HTML may flag or break on this error.

## How to Fix

You have two options:

1. **Remove the `action` attribute** if you want the form to submit to the current page URL.
2. **Provide a valid URL** if the form should submit to a specific endpoint.

## Examples

### ❌ Invalid: Empty `action` attribute

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

This triggers the error: **Bad value "" for attribute "action" on element "form": Must be non-empty.**

### ✅ Fixed: Remove the `action` attribute

If you want the form to submit to the current page, simply omit `action`:

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

### ✅ Fixed: Provide a valid URL

If the form should submit to a specific endpoint, supply the URL:

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

### ✅ Fixed: Use a hash as a placeholder for JavaScript-handled forms

If your form is entirely handled by JavaScript and should not navigate anywhere, you can use a `#` as the action or, preferably, omit `action` and prevent submission in your script:

```html
<form method="post" id="js-form">
  <label for="query">Search:</label>
  <input type="text" id="query" name="query">
  <button type="submit">Search</button>
</form>
```

```js
document.getElementById('js-form').addEventListener('submit', function(e) {
  e.preventDefault();
  // Handle form data with JavaScript
});
```

In this case, omitting `action` is the cleanest solution. The JavaScript `preventDefault()` call stops the browser from actually submitting the form, so the `action` value is never used.
