Skip to content

Instantly share code, notes, and snippets.

@mauricioulloa
Last active August 29, 2015 14:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauricioulloa/a894e58149c4ed21cf82 to your computer and use it in GitHub Desktop.
Save mauricioulloa/a894e58149c4ed21cf82 to your computer and use it in GitHub Desktop.
How to block autocomplete in modern browsers?

Since Chrome 34, Firefox 30 and Internet Explorer 11 the autocomplete attribute for input[type="password"] is being ignored (:angry:). Many people have been complaining and asking for workarounds because in some cases it's an important requirement to block autocomplete.

Here is a workaround for a classic implementation of login (currently working in mainstream browsers):

##OLD WAY The old way was using autocomplete="off" attribute in passwords' input:

<form>

    <label>Username</label>
    <input id="username" name="username">

    <label>Password</label>
    <input id="password" name="password" type="password" autocomplete="off">

    <input id="rememberme" name="rememberme" type="checkbox" value="false">
    <label class="checkbox">Remember me</label>

    <button type="submit">Log in</button>
    
</form>

##NEW WAY The new way is adding fake username and password fields before the real ones and hiding them. Those fields are autocompleted by the browser (but users don't realize it 😎).

<form>

    <input type="text" style="display:none">
    <input type="password" style="display:none">
    
    <label>Username</label>
    <input id="username" name="username">

    <label>Password</label>
    <input id="password" name="password" type="password">

    <input id="rememberme" name="rememberme" type="checkbox" value="false">
    <label class="checkbox">Remember me</label>

    <button type="submit">Log in</button>
    
</form>

Thanks @felipefunes and @beckyq for editing.

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