Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save niksumeiko/360164708c3b326bd1c8 to your computer and use it in GitHub Desktop.

Select an option

Save niksumeiko/360164708c3b326bd1c8 to your computer and use it in GitHub Desktop.
Disable HTML form input autocomplete and autofill

Disable HTML Form Input Autocomplete and Autofill

  1. Add autocomplete="off" onto <form> element;
  2. Add hidden <input> with autocomplete="false" as a first children element of the form.
<form autocomplete="off" method="post" action="">
    <input autocomplete="false" name="hidden" type="text" style="display:none;">
    ...

This formation is going to prevent Chrome and Firefox to offer autofill and autocomplete for all input fields inside the form.

@Jonathanvictor-dev

Jonathanvictor-dev commented Mar 13, 2025

Copy link
Copy Markdown

readonly

The problem was solved with the solution in the following comment above.

I'm using react, I included readOnly in the inputs, combined it with useEffect, addEventListener, removeEventListener and the 'focus' event. This way, the field is not filled automatically.

@dmbritos

dmbritos commented Mar 20, 2025

Copy link
Copy Markdown

It also works if you remove the readOnly attribute in the window's load event:

<input type="password" readonly id="MyPasswordInput" name="MyPasswordInput"/>

$(window).load(function () {
    $("#MyPasswordInput").removeAttr('readonly');
});

Just to clarify, NO need to change or add anything to the username/login input...

@sgtrusty

Copy link
Copy Markdown

@valentimmx worked, thanks.

@darkaouihasni4-sketch

Copy link
Copy Markdown

ما يعمل في متصفح كروم هو التالي:

<input type="text" autocomplete="new-text" />
<input type="number" autocomplete="new-number" />
<input type="password" autocomplete="new-password" />

لقد نجحت هذه الطريقة! كما أنني قمت بتعطيل خاصية الإكمال التلقائي في حقل النموذج.

input type="text" autocomplete="new-text" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment