References

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

The HTML selected attribute

Attribute All modern browsers Updated
Quick answer

The HTML selected attribute pre-selects an option in a <select> by default. It is used on the <option> element.

Overview

The selected attribute pre-selects a dropdown option. It is used on the <option> and <optgroup> elements.

It configures the choices in a drop-down — labeling option groups and pre-selecting a default. These sit inside a <select>.

Syntax

<option value="2" selected>Two</option>

Values

Value
A boolean attribute — present or absent.

Example

Live example
<select><option>One</option><option selected>Two</option></select>

Best practices

  • Give an <optgroup> a label to head each section of a long drop-down.
  • Pre-select a default with the selected attribute on an <option>.
  • Always pair the <select> with a <label>.
  • Give each option a value when the submitted data differs from the visible text.

Frequently asked questions

What does the selected attribute do?
Pre-selects a dropdown option.
How do I group options in a drop-down?
Wrap related <option> elements in an <optgroup> and set its label attribute.
How do I pre-select an option?
Add the selected attribute to that <option>.
Which elements use the selected attribute?
It is an element-specific attribute, used on the <option> and <optgroup> elements.