Form Elements

select, textarea and button

Example

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
      body { font-family: Arial, sans-serif; }
      label { display: block; margin-top: 8px; }
      input, select, textarea { padding: 6px; margin-top: 4px; }
      button, input[type=submit] { margin-top: 10px; padding: 6px 14px; }
    </style>
</head>
<body>

<form>
  <label for="city">City</label>
  <select id="city" name="city">
    <option value="hyd">Hyderabad</option>
    <option value="blr" selected>Bengaluru</option>
    <option value="mum">Mumbai</option>
  </select>

  <label for="msg">Message</label>
  <textarea id="msg" name="message" rows="3" cols="30">Hello!</textarea>

  <button type="submit">Send</button>
  <button type="reset">Clear</button>
</form>

</body>
</html>

Result

fieldset, legend and datalist

Example

<fieldset> groups related fields with a caption (<legend>); <datalist> suggests values while typing:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
      body { font-family: Arial, sans-serif; }
      label { display: block; margin-top: 8px; }
      input, select, textarea { padding: 6px; margin-top: 4px; }
      button, input[type=submit] { margin-top: 10px; padding: 6px 14px; }
    </style>
</head>
<body>

<form>
  <fieldset>
    <legend>Shipping address</legend>
    <label>Street <input name="street"></label>
    <label>Course
      <input list="courses" name="course">
      <datalist id="courses">
        <option value="HTML"><option value="CSS"><option value="JavaScript"><option value="SQL">
      </datalist>
    </label>
  </fieldset>
</form>

</body>
</html>

Result

Exercise

Exercise: Create a drop-down list named size with the options Small, Medium and Large, where Medium is selected by default.

Show answer
<select name="size">
  <option value="s">Small</option>
  <option value="m" selected>Medium</option>
  <option value="l">Large</option>
</select>