# Bad value X for attribute “required” on element “input”.

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

In HTML, boolean attributes like `required` work differently from what many developers expect. Their presence on an element means the value is true, and their absence means the value is false. According to the [WHATWG HTML specification](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes), a boolean attribute's value must either be the empty string or an ASCII case-insensitive match for the attribute's canonical name. For the `required` attribute, this means the only valid values are `""` (empty string) and `"required"`.

A common mistake is writing `required="true"` or `required="false"`. The value `"true"` is not a valid boolean attribute value in HTML and will trigger this validation error. Even more confusingly, writing `required="false"` does **not** make the input optional — since the attribute is still present, the browser still treats the field as required. This can lead to subtle bugs where a form field appears to be optional in your code but is actually enforced as required by the browser.

This matters for several reasons:

- **Standards compliance**: Invalid attribute values violate the HTML specification and will cause W3C validation errors.
- **Code clarity**: Using non-standard values like `"true"` or `"false"` misleads other developers about how the attribute works.
- **Unexpected behavior**: `required="false"` still makes the field required, which can cause confusing form behavior.

To make a field optional, simply remove the `required` attribute entirely rather than setting it to `"false"`.

## Examples

### Incorrect: Invalid values for `required`

These will all trigger the "Bad value for attribute `required`" validation error:

```html
<input type="text" required="true">
<input type="email" required="false">
<input type="text" required="yes">
<input type="text" required="1">
```

### Correct: Valid uses of the `required` attribute

All three of these forms are valid and make the input required:

```html
<!-- Preferred: no value (most concise) -->
<input type="text" required>

<!-- Also valid: empty string -->
<input type="text" required="">

<!-- Also valid: canonical name as value -->
<input type="text" required="required">
```

### Correct: Making a field optional

To make a field optional, remove the attribute entirely:

```html
<input type="text">
```

### Full form example

```html
<form action="/submit" method="post">
  <label for="name">Name (required):</label>
  <input type="text" id="name" name="name" required>

  <label for="notes">Notes (optional):</label>
  <input type="text" id="notes" name="notes">

  <button type="submit">Submit</button>
</form>
```

This same rule applies to other boolean attributes in HTML, such as `disabled`, `checked`, `readonly`, `multiple`, and `autofocus`. They all follow the same pattern: use the attribute with no value, with an empty string, or with the attribute's own name as the value. Never assign `"true"` or `"false"` to them.
