---
title: "How do I add autocomplete suggestions to an input without JavaScript?"
description: "The datalist element gives any text input a list of suggestions with no JavaScript. Here is how to use it, which input types it works with, and where its limits are."
url: https://www.danny.engineering/answer/html/how-do-i-add-autocomplete-suggestions-to-an-input-without-javascript
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["HTML"]
---

# How do I add autocomplete suggestions to an input without JavaScript?

## The short answer


Create a `datalist` with an `id`, fill it with `option` elements, and point the input's `list` attribute at that `id`. The browser shows matching suggestions as the user types, but they can still type anything.


```html
<label for="browser">Favourite browser</label>
<input id="browser" name="browser" list="browsers">

<datalist id="browsers">
  <option value="Chrome"></option>
  <option value="Edge"></option>
  <option value="Firefox"></option>
  <option value="Safari"></option>
</datalist>
```


## Why it happens


Developers often reach for a JavaScript autocomplete library when they only need a short list of suggestions. HTML has had a built-in option for years: `datalist`. It works like a combo box, a text input with a dropdown of suggestions, and the browser handles filtering, keyboard navigation and the popup for you.


The key thing to understand is that `datalist` suggests, it does not restrict. It is not a replacement for `select`. Whatever the user types is what gets submitted.


## How to fix it


### Basic suggestions


The example in the short answer is all you need for a simple list. The browser filters options as the user types. The `datalist` itself is not rendered on the page, so you can put it anywhere in the document, though keeping it next to the input makes the code easier to follow.


Always keep a visible `label`. The `datalist` does not label the input.


### Use it with other input types


`datalist` works with many input types, not just text. The browser shows the suggestions in a way that fits the control.


```html
<label for="email">Email</label>
<input id="email" type="email" list="domains">
<datalist id="domains">
  <option value="name@company.example"></option>
</datalist>

<label for="volume">Volume</label>
<input id="volume" type="range" min="0" max="100" list="marks">
<datalist id="marks">
  <option value="0"></option>
  <option value="50"></option>
  <option value="100"></option>
</datalist>
```


On a range input, some browsers draw tick marks at the listed values. On colour and date inputs, support and appearance vary a lot between browsers, so treat it as a bonus there.


### Restrict the value when you need to


If only listed values are valid, use a `select` instead. If you want the typing experience of `datalist` but must limit the value, add a `pattern` built from the allowed values, and validate on the server as well.


```html
<input id="size" name="size" list="sizes" pattern="Small|Medium|Large" required>
<datalist id="sizes">
  <option value="Small"></option>
  <option value="Medium"></option>
  <option value="Large"></option>
</datalist>
```


### Add suggestions from the server


Because it is plain HTML, you can render the options on the server, for example a list of existing tags or recent searches. If the list must change as the user types, you will need a little JavaScript to fetch new options and replace the `option` elements.


## Common pitfalls

- **You cannot style the dropdown.** The popup is drawn by the browser and ignores your CSS. If the design needs custom styling, rich option content or icons, you need a custom component.
- **Labels on options behave differently.** Some browsers show an option's text label next to its value, others show only the value. Do not rely on the label to explain the value.
- **Filtering is the browser's choice.** Some match from the start of the word, others match anywhere. You cannot change it.
- **Mobile support is uneven.** Some mobile browsers show suggestions above the keyboard, and some have had patchy support. Make sure the input works fine with no suggestions at all.
- **Browser autofill can compete.** Saved form entries may appear alongside or instead of your suggestions. Set a suitable `autocomplete` value, or `autocomplete="off"` if autofill is not useful for that field.
- **Very long lists.** Thousands of options make the page heavy and the popup hard to use. For large data sets, filter on the server.
- **Expecting a select.** Users can submit any text, so always validate the value.

## Related reading

- [MDN: The datalist element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/datalist)
- [MDN: The list attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#list)
