7

To turn off autocompletion in HTML I use:

    <input type="text" name="foo" autocomplete="off" />

But this forces me to specify autocomplete="off" in every input field of my application. Is it possible to define autocomplete="off" in a CSS style?

2
  • 7
    no, it's not a style - its behaviour. Commented Jun 1, 2016 at 11:35
  • It's as simple as @sevenseacat comment. It's a behaviour. You need to write it in the HTML. Commented Jun 1, 2016 at 11:39

6 Answers 6

12

You can just apply it to the form tag.

Sign up to request clarification or add additional context in comments.

Comments

5

Using CSS you cannot achieve it. You can use client side script for example using Jquery

$('input').attr('autocomplete','off');

If you are not using Jquery or scripting language then you have to stick to HTML only.

As TeT Psy said you can apply it in form tag like

<form id="Form" runat="server" autocomplete="off">

4 Comments

I don't use Jquery, sorry
@ps0604:- Then in that case you have to stick to HTML way. CSS does not provide any such way.
In my opinion, its not good idea to use JavaScript or jQuery if you can do it in html or css.
@MuhammadUsman:- Yes that is true. I just gave an option. Since OP neglected the idea of using HTML.
3

you can disable all the autocompletes using form

<form id="Form1" runat="server" autocomplete="off">

Comments

3

You can use autocomplete="off" attribute on form tag. Like this:

<form id='test' autocomplete="off">
  <input ...
  <input .. 
   ...
 </form>

Comments

2

No you can't do this using css, but there are 2 other ways to do it:

1- you can apply it for the form

<form autocomplete="off" >
  <input type="text" name="name">
  <input type="text" name="mail">
</form>

2- you can handle it using js

var eles = document.getElementsByTagName('input');
for(i=0; i<eles.length; i++){
    eles[i].setAttribute("autocomplete", "off");

}

https://jsfiddle.net/ng1mb77m/1/

Comments

1

You can set it on form element if you wants to set autocomplete: off for all input elements of form. And if wants to make it on for some selected input you can apply autocomplete: on on that input.

.form {
  padding: 30px 0;
  width: 300px;
  margin: 0 auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<form action="#" class="form" autocomplete="on">
  <div class="form-group">
    First name:<input type="text" class="form-control" name="fname">
  </div>
  <div class="form-group">
    Last name:<input type="text" class="form-control" name="lname" autocomplete="off">
  </div>
  <div class="form-group">
    E-mail: <input type="email" class="form-control" name="email">
  </div>
  <input type="submit">
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.