Tryit<!DOCTYPE html><html><head><title>Wikitechy HTML selected attribute</title></head><body><select><optionvalue="css">CSS</option><optionvalue="html">HTML</option><optionvalue="java"selected>JAVA</option><optionvalue="php">PHP</option></select></body></html>
Code Explanation for selected Attribute in HTML:
<option> tag is used to define the list of options in a select list.
The value attribute is used to set the value for the specified <option>.
The selected attribute is used to pre-select a value by default on page load.
Output for selected Attribute in HTML:
The output shows that the <option> JAVA has been pre-selected on page load.
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.