Disable autocomplete on Chrome / Firefox / Safari

Peter Toth
Aug 31, 2018 · 1 min read

How frustrating that the browsers forcing their internal autocomplete solution aggressively… We sometimes would need to use our unique autocomplete solutions, for example to get an element’s id based on its name.

After hours of searching, digging, trying I came up a viable hack to get rid of the autocomplete function.

The magic with the autocomplete grouping function that would help the developers to tell the browsers how to split data to separated fields. For example, if you would like to autocomplete an address but you would like to split the address to ZIP code, Country, Town, Address, you can tell to the browser what part belongs to which fields of the form.

We can use this to switch the autocomplete function off:

<input type="text" name="your_input" autocomplete="prevent-autocomplete"><!-- Add a fake hidden input with the same autocomplete group and random naming -->
<input type="text" name="{{str_random(5)}}" hidden autocomplete="prevent-autocomplete">

Just add a hidden input with the same autocomplete value, since it has random name the browsers can’t remember its older values ;)

Official documentation and more info:

Peter Toth

Written by

Hello, my name is Peter, I am a professional Website / SaaS Developer. I started coding when I was 7 years old, this is my life and my passion.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade