Easy auto-suggest with datalist

Easy autocomplete/suggestions for inputs with the HTML5 datalist tag

Niall Maher
Published in
3 min readJan 12, 2021

--

Sometimes you would like to suggest some options to a user as they type something into an input. Maybe there are popular search categories or tags that people are looking for. You could, of course, implement an API driven feature, or if you want to get a quick way for it to be up and running why not just use the datalist tag?

In case you want to watch me mess around with the datalist tag you can watch it here or else keep scrolling to read.

The HTML <datalist> element contains a set of <option> elements that represent the permissible or recommended options available to choose from within other controls. — MDN

Datalist acts as a hybrid between a normal input and a select field where it allows users to either choose a suggested option, see suggestions as you type, or add in your own option.

So how does it work?

Let’s show you how to add the datalist tag to a regular old <input type="text"> as a simple example (and probably the most common one you will use).

--

--

Writing about my thoughts on running a tech startup, personal growth and building stuff that people love!