Question:
Hi, what is the difference between using an input list
or select
?
Here is an example.
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Google Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<select name="Seleccion">
<option value="Rojo">rojo</option>
<option value="Verde">verde</option>
</select>
Answer:
Some differences:
- With a
list
/datalist
you can manually enter values that do not exactly match the values suggested in thedatalist
, while with aselect
you have to choose from theoption
values. -
select
is supported by all browsers, while the support forlist
/datalist
although extended, is not yet there at all and can cause problems (especially on mobile devices) … And curiously the way to solve it is to have aselect
inside thedatalist
. - You can have multiple
input list
pointing to the samedatalist
without affecting the page (creating one is basically automatic), while aselect
you must insert all theoption
to have values, which can negatively affect performance.
And here are some differences that will depend on the browser you use:
- In Chrome / Firefox, with a
list
/datalist
you can search for elements anywhere in the string, while withselect
you have to search starting with the first character of the string (for example, in thelist
you can write a "c" and it will automatically suggest "Google Chrome", while in theselect
to select Chrome you would have to start with a "g" because it is "Google Chrome"). In IE the behavior is the same betweeninput
/datalist
andselect
. - If there are many values, when displaying a
select
it will show all the values (datalist
with a scroll), while with alist
/datalist
it will only show some or none (eg Chrome will show a select list while Firefox will not show anything until do not start writing).
——-
The main difference is that they are not the same: one is a text field with autocomplete / suggestions and the other is a list of fixed values. Some browsers will represent them in a very similar way, but that similarity will depend on the browser used (eg IE and Chrome show input list
similar to a select
but Firefox represents it as a normal text field until you start typing) .