HTML Form text input suggestions box

Ross Larson picture Ross Larson · Jun 23, 2011 · Viewed 17.8k times · Source

I am attempting to modify one of my text input boxes in a form that I have. I would like suggestions to pop up as the user types. Basically, I would like to emulate the "Tags" box that is on the ask question pages here on Stack Overflow, but with different data as the suggestions obviously. How would I go about doing this?

For context, this is for a club at a college, and I am trying to allow members to type in their majors and as they type have a suggestions come up.

Answer

Nathan Arthur picture Nathan Arthur · Apr 12, 2019

This snippet from Cena Mayo did just what I was looking for:

<input id="color" list="suggestions">
<datalist id="suggestions">
    <option value="Black">
    <option value="Red">
    <option value="Green">
    <option value="Blue">
    <option value="White">
</datalist>

Documentation