How to specify that an option should be pre-selected when the page loads in HTML?


Use the selected attribute to specify that the option should be pre-selected when page loads in HTML. You can try to run the following code to implement selected attribute −

Example

<!DOCTYPE html>
<html>
   <head>
      <title>HTML selected attribute</title>
   </head>
   <body>
      <p>Here's the list of subjects. Select any one:</p>
      <form>
         <select name = "dropdown">
            <option value = "Computer Architecture" selected>Computer Architecture</option>
            <option value = "Java">Java</option>
            <option value = "Discrete Mathematics">Discrete Mathematics</option>
         </select>
      </form>
   </body>
</html>

Updated on: 03-Mar-2020

74 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements