HTML Form Elements

select, textarea, button, fieldset and datalist.

✍️ 3 exercises + code challenge in this lesson

Besides <input>, forms can contain:

  • <select> with <option>: a drop-down list.
  • <textarea>: a multi-line text field.
  • <button>: a clickable button.
  • <fieldset> and <legend>: group related fields with a caption.
  • <datalist>: suggestions for an input while typing.

Key Takeaways: HTML Form Elements

Mastering HTML Form Elements helps you write clean and reliable HTML code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

HTML Form Elements Code Example

HTML
<form onsubmit="alert('Sent!'); return false;">
  <fieldset>
    <legend>Course enquiry</legend>

    <label for="course">Course:</label>
    <select id="course" name="course">
      <option>HTML</option>
      <option selected>JavaScript</option>
      <option>Python</option>
    </select><br><br>

    <label for="city">City:</label>
    <input list="cities" id="city" name="city">
    <datalist id="cities">
      <option value="Islamabad"><option value="Lahore"><option value="Karachi">
    </datalist><br><br>

    <label for="msg">Message:</label><br>
    <textarea id="msg" name="msg" rows="3" cols="30">I would like to join.</textarea><br>
    <button type="submit">Send</button>
  </fieldset>
</form>
Free sign-in required · Google login available

HTML Form Elements Practice Exercises

Check what you learned in “HTML Form Elements”.

/ 3 solved
Fill in the blank

Create a drop-down list.

< name="city">
  <option>Lahore</option>
  <option>Karachi</option>
</>
✓ Correct! Not quite. Try again.
Multiple choice

Which element creates a multi-line text field?

✓ Correct! Not quite. Try again.
Code challenge

Add a <textarea> named "message" with 4 rows.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services