Search code examples
htmlautocompletew3cautosuggest

Should autosuggest input have type="text" or type="search"?


Are there any w3c recommendations regarding having type="text" vs type="search" on an <input> field of an autosuggest/autocomplete component?

Example of autosuggest component


Solution

  • Just because an input element offers autosuggest/autocomplete does not mean that it should have to use one of these two states, Text or Search. Autosuggest/autocomplete could, of course, also be offered for other states (like Number, URL etc.).

    Unfortunately, HTML5 does not really define what the Search state represents. However, it notes:

    The difference between the Text state and the Search state is primarily stylistic: […]

    So if you refer to it as "search field", if it would not be confusing for your users if user agents display it with a search icon or similar, and if, well, it lets users search something, then using the Search state makes sense.