🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
Guides / Building Search UI / Widgets

Change browser defaults for React InstantSearch

This is the React InstantSearch v7 documentation. React InstantSearch v7 is the latest version of React InstantSearch and the stable version of React InstantSearch Hooks.

If you were using React InstantSearch v6, you can upgrade to v7.

If you were using React InstantSearch Hooks, you can still use the React InstantSearch v7 documentation, but you should check the upgrade guide for necessary changes.

If you want to keep using React InstantSearch v6, you can find the archived documentation.

If you don’t use the built-in InstantSearch or Autocomplete components to render a search box, you need to change the default properties of the HTML input element to turn off the default autocomplete behavior of the browser.

A classic search HTML input looks like:

1
<input type="text" id="search" />

When a user starts typing into this input, the browser may use its default search-as-you-type behavior, which interferes with the custom search box. This guide describes how to avoid this behavior.

Updating input attributes

Set these attributes on the HTML input element to turn off the browser’s default behavior:

1
2
3
4
5
6
<input type="text"
       id="search"
       autocomplete="off"
       autocorrect="off"
       autocapitalize="none"
       spellcheck="false" />

In Chrome, autocomplete="off" doesn’t work. In Chrome, you can turn off autocomplete by setting the attribute to an invalid value like autocomplete="nope". The same solution doesn’t work in Firefox (it disregards the invalid value and reverts to the default autocompletion behavior).

More information about input attributes

For more information, see these MDN references:

Did you find this page helpful?