Open In App

How to specify whether an input element should have autocomplete disabled or not ?

Last Updated : 17 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The autocomplete attribute specifies whether an autocomplete input field should be enabled. The browser can predict the value using autocomplete. The browsing options to fill in the field, based on earlier typed values, should be shown for the user while typing a field.

If the autocomplete feature is enabled, the browser will suggest values based on what users have previously entered the field. If the autocomplete feature is disabled, the browser will not show the values automatically, depending on the previous users.

Note: Text, search, URL, mobile, email, password, date pickers, range, and color, all work with the autocomplete attribute.

Syntax:

<input autocomplete="on|off">

Values:

  • on: This is the default setting. It states that autocomplete is enabled.
  • off: This states that the autocomplete is disabled.

Example 1: The following example demonstrates the disabled state of autocomplete feature. In this case, the browser will not show the values automatically, entered by the previous users.

HTML




<!DOCTYPE html>
<html>
   <head>
      <title>OFF</title>
   </head>
   <body>
      <form action = "/gfg" method = "post" 
            autocomplete="off">
         Full Name
         <br>
         <input type = "text" name = "full_name">
         <br>
         <input type = "submit" value = "submit" />
      </form>
   </body>
</html>


Output :

autocomplete is Off

Example 2: The following example demonstrates the enabled state of autocomplete feature. When autocomplete is turned on, then the browser will suggest values based on what users have previously entered the field.

HTML




<!DOCTYPE html>
<html>
   <head>
      <title>ON</title>
   </head>
   <body>
      <form action = "/gfg" method = "post" 
            autocomplete="on">
         Full Name
         <br>
         <input type = "text" name = "full_name">
         <br>
         <input type = "submit" value = "submit" />
      </form>
   </body>
</html>


Output :

 autocomplete is on



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads