# Bad value “true” for attribute “selected” on element “option”.

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

In HTML, boolean attributes like `selected` work differently than you might expect if you're coming from a programming language. A boolean attribute's presence alone means "true," and its absence means "false." Setting `selected="true"` is invalid because the only permitted values for a boolean attribute are the empty string (`""`) or the attribute's own name (e.g., `selected="selected"`). The value `"true"` is not recognized by the HTML specification, which is why the W3C validator flags it.

This matters for several reasons. First, it violates the [WHATWG HTML specification](https://html.spec.whatwg.org/multipage/common-microsyntax.html#boolean-attributes), which explicitly defines how boolean attributes must be written. Second, while most browsers are forgiving and will still treat `selected="true"` as if the option is selected, relying on this lenient behavior is risky — it can lead to inconsistencies across browsers or tools that parse HTML strictly. Third, invalid markup can cause problems for assistive technologies, automated testing tools, and server-side HTML processors that follow the spec closely.

The same rule applies to other boolean attributes like `disabled`, `checked`, `readonly`, `multiple`, `required`, and `hidden`. None of them should be set to `"true"` or `"false"`.

It's also worth noting that setting a boolean attribute to `"false"` (e.g., `selected="false"`) does **not** turn it off — the attribute's mere presence activates it. To deactivate a boolean attribute, you must remove it entirely from the element.

## Examples

### ❌ Invalid: using `selected="true"`

```html
<select name="color">
  <option selected="true">Red</option>
  <option>Green</option>
  <option>Blue</option>
</select>
```

This triggers the validation error because `"true"` is not a valid value for the boolean `selected` attribute.

### ✅ Valid: bare attribute (preferred)

```html
<select name="color">
  <option selected>Red</option>
  <option>Green</option>
  <option>Blue</option>
</select>
```

The simplest and most common way to write a boolean attribute — just include the attribute name with no value.

### ✅ Valid: empty string value

```html
<select name="color">
  <option selected="">Red</option>
  <option>Green</option>
  <option>Blue</option>
</select>
```

An empty string is a valid value for any boolean attribute per the HTML spec.

### ✅ Valid: attribute name as value

```html
<select name="color">
  <option selected="selected">Red</option>
  <option>Green</option>
  <option>Blue</option>
</select>
```

Using the attribute's own name as its value is also valid. This form is sometimes seen in XHTML-style markup and in templating systems.

### ❌ Invalid: using `selected="false"` to deselect

```html
<select name="color">
  <option selected="false">Red</option>
  <option>Green</option>
  <option>Blue</option>
</select>
```

This is both invalid **and** misleading. The option will still be selected because the `selected` attribute is present. To not select an option, simply omit the attribute:

```html
<select name="color">
  <option>Red</option>
  <option>Green</option>
  <option>Blue</option>
</select>
```
