English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML option selected attribute

The selected attribute is a boolean attribute. If present, it specifies that an option should be pre-selected when the page is loaded. The pre-selected option will be displayed first in the dropdown list.

 HTML <option> tag

Online Example

Dropdown list with a pre-selected option:

<!DOCTYPE html>
<html>
<head>
<title>HTML:<option selected attribute - 基础教程网(oldtoolbag.com)</title>
</head>
<body>
<select>
  <option value="PHP">PHP</option>
  <option value="HTML">HTML</option>
  <option value="C++">C++</option>
  <option value="GOLANG" selected>GOLANG</option>
  <option value="JAVA">JAVA</option>
</select>
</body>
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the selected attribute.

Definition and Usage

The selected attribute is a boolean attribute.
If present, it specifies that an option should be pre-selected when the page loads.
Pre-selected options will be displayed first in the drop-down list.
Tip: You can also set the selected attribute using JavaScript after the page has loaded.

HTML 4.01 With HTML5Differences

None.

Differences between HTML and XHTML

In XHTML, attribute shorthand is prohibited, the selected attribute must be defined as <option selected="selected">.

Syntax

<option selected>
 HTML <option> tag