Home >Web Front-end >HTML Tutorial >How to specify in HTML that an option should be pre-selected when the page loads?

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

王林
王林forward
2023-09-15 22:01:021285browse

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

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

Example

<!DOCTYPE html>
<html>
   <head>
      <title>HTML selected attribute</title>
   </head>
   <body>
      <p>Here&#39;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>

The above is the detailed content of How to specify in HTML that an option should be pre-selected when the page loads?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete