How to create a drop down box with a pre-selected value in a form with HTML/XHTML

A drop-down box can have a pre-selected value. To do so you add the selected attribute to the beginning <option> tag.

The code below shows you how to add a drop-down box with a pre-selected value.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Web Development Tutorials.com</title>
</head>
<body>

<form action="formscript.php" method="post">
<select name="tutorials">
<br />
<option value="html">HTML tutorials</option>
<br />
<option value="css">CSS tutorials</option>
<br />
<option value="javascript" selected="selected">javascript tutorials</option>
</select>
</form>

</body>
</html>

The HTML code above makes the form with a pre-selected example below.

Use the text editor below to practice what you have learned.

Free Website Templates

Free Web Tools

Recommended Websites