html tutorial - selected Attribute in HTML - html5 - html code - html form




Selected attribute in html

Learn html - html tutorial - Selected attribute in html - html examples - html programs

  • The selected attribute defines that an option has been pre-selected though the page loads.
  • The selected attribute is a Boolean attribute.
  • The pre-selected option will be selected by default in the drop-down list.

Syntax for selected attribute in HTML:

<option selected>

Applies To:

Element Attribute
<option> selected

Sample Coding for selected Attribute in HTML:

Tryit<!DOCTYPE html>
<html>
    <head>
        <title>Wikitechy HTML selected attribute</title>
    </head>
    <body>
        <select>
            <option value="css">CSS</option>
            <option value="html">HTML</option>
            <option value="java" selected>JAVA</option>
            <option value="php">PHP</option>
        </select>
    </body>
</html>

Code Explanation for selected Attribute in HTML:

selected Attribute Code Explanation

  1. <option> tag is used to define the list of options in a select list.
  2. The value attribute is used to set the value for the specified <option>.
  3. The selected attribute is used to pre-select a value by default on page load.

Output for selected Attribute in HTML:

selected Attribute Output

  1. The output shows that the <option> JAVA has been pre-selected on page load.
selected Attribute Output
  1. In the output, the text CSS, HTML, JAVA, PHP has been shown in a drop-down list with four options.

Browser Support for selected Attribute in HTML:

Yes Yes Yes Yes Yes

Tips and Notes

  • If selected attribute not presents the first value will be the default pre-selected value.

Related Searches to selected attribute in html