Signup/Sign In
PUBLISHED ON: AUGUST 18, 2021

How to disable autocomplete of an input field?

The autocomplete helps the user to suggest possible text to complete the text field. When the user starts typing the suggestion appears on the screen. It is the default feature supported by the browser.

In this tutorial, we will learn to disable the autocomplete of the input field.

Disabling autocompletion

The input field is created using the <input> tag. To disable the autocomplete use autocomplete="off" attribute within the <input> tag. If you want to disable the autocomplete of input field for the entire form use the autocomplete attribute within the <form> tag.

Example: Disabling the autocomplete of the input field

Here, we have created an input field that will give no suggestion to the user.

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML</title>
</head>  
<body>
    <h3> No more suggestion </h3>       
   <label for="cd">Search Here </label>
   <input type="text" id="cd" name="cd" autocomplete="off"> 
</body>
</html>

Output

Here is the output of the above example.

Disabling autocomplete

Example: Disabling input field of the entire form

Here, we have used the autocomplete="off" to the form to disable the suggestion of the entire form.

Conclusion

In this tutorial, we have learned to disable autocomplete of the input field. To do so use autocomplete="off". You can use it on <input> or <form> element.



About the author: