HTML autocomplete attribute is available on <input> elements that take a text or numeric value as input, <textarea> elements, <select> elements, and <form> 元素。 autocomplete lets web developers specify what if any permission the 用户代理 has to provide automated assistance in filling out form field values, as well as guidance to the browser as to the type of information expected in the field.

The source of the suggested values is generally up to the browser; typically values come from past values entered by the user, but they may also come from pre-configured values. For instance, a browser might let the user save their name, address, phone number, and email addresses for autocomplete purposes. Perhaps the browser offers the ability to save encrypted credit card information, for autocompletion following an authentication procedure.

<input> , <select> or <textarea> element has no autocomplete attribute, then browsers use the autocomplete attribute of the element's form owner, which is either the <form> element that the element is a descendant of, or the <form> whose id is specified by the form attribute of the element.

更多信息,见 autocomplete 属性在 <form> .

In order to provide autocompletion, user-agents might require <input> / <select> / <textarea> elements to:

  1. Have a 名称 and/or id 属性
  2. Be descendants of a <form> element
  3. The form to have a submit button

" off "
The browser is not permitted to automatically enter or select a value for this field. It is possible that the document or application provides its own autocomplete feature, or that security concerns require that the field's value not be automatically entered. 注意: In most modern browsers, setting autocomplete to " off " will not prevent a password manager from asking the user if they would like to save username and password information, or from automatically filling in those values in a site's login form. See the autocomplete attribute and login fields .
" on "

The browser is allowed to automatically complete the input. No guidance is provided as to the type of data expected in the field, so the browser may use its own judgement.

" 名称 "
The field expects the value to be a person's full name. Using " 名称 " rather than breaking the name down into its components is generally preferred because it avoids dealing with the wide diversity of human names and how they are structured; however, you can use the following autocomplete values if you do need to break the name down into its components:
" honorific-prefix "

The prefix or title, such as "Mrs.", "Mr.", "Miss", "Ms.", "Dr.", or "Mlle.".

" given-name "

The given (or "first") name.

" additional-name "

The middle name.

" family-name "

The family (or "last") name.

" honorific-suffix "

The suffix, such as "Jr.", "B.Sc.", "PhD.", "MBASW", or "IV".

" nickname "

A nickname or handle.

" email "

An email address.

" username "

A username or account name.

" new-password "
A new password. When creating a new account or changing passwords, this should be used for an "Enter your new password" or "Confirm new password" field, as opposed to a general "Enter your current password" field that might be present. This may be used by the browser both to avoid accidentally filling in an existing password and to offer assistance in creating a secure password (see also Preventing autofilling with autocomplete="new-password" ).
" current-password "

The user's current password.

" one-time-code "

A one-time code used for verifying user identity.

" organization-title "

A job title, or the title a person has within an organization, such as "Senior Technical Writer", "President", or "Assistant Troop Leader".

" organization "

A company or organization name, such as "Acme Widget Company" or "Girl Scouts of America".

" street-address "

A street address. This can be multiple lines of text, and should fully identify the location of the address within its second administrative level (typically a city or town), but should not include the city name, ZIP or postal code, or country name.

" address-line1 ", " address-line2 ", " address-line3 "
Each individual line of the street address. These should only be present if the " street-address " is not present.
" address-level4 "
The finest-grained administrative level , in addresses which have four levels.
" address-level3 "
第 3 administrative level , in addresses with at least three administrative levels.
" address-level2 "
The second administrative level , in addresses with at least two of them. In countries with two administrative levels, this would typically be the city, town, village, or other locality in which the address is located.
" address-level1 "
The first administrative level in the address. This is typically the province in which the address is located. In the United States, this would be the state. In Switzerland, the canton. In the United Kingdom, the post town.
" country "

A country or territory code.

" country-name "

A country or territory name.

" postal-code "

A postal code (in the United States, this is the ZIP code).

" cc-name "

The full name as printed on or associated with a payment instrument such as a credit card. Using a full name field is preferred, typically, over breaking the name into pieces.

" cc-given-name "

A given (first) name as given on a payment instrument like a credit card.

" cc-additional-name "

A middle name as given on a payment instrument or credit card.

" cc-family-name "

A family name, as given on a credit card.

" cc-number "

A credit card number or other number identifying a payment method, such as an account number.

" cc-exp "

A payment method expiration date, typically in the form "MM/YY" or "MM/YYYY".

" cc-exp-month "

The month in which the payment method expires.

" cc-exp-year "

The year in which the payment method expires.

" cc-csc "

The security code for the payment instrument; on credit cards, this is the 3-digit verification number on the back of the card.

" cc-type "

The type of payment instrument (such as "Visa" or "Master Card").

" transaction-currency "

The currency in which the transaction is to take place.

" transaction-amount "
The amount, given in the currency specified by " transaction-currency ", of the transaction, for a payment form.
" 语言 "
A preferred language, given as a valid BCP 47 language tag .
" bday "

A birth date, as a full date.

" bday-day "

The day of the month of a birth date.

" bday-month "

The month of the year of a birth date.

" bday-year "

The year of a birth date.

" sex "

A gender identity (such as "Female", "Fa'afafine", "Male"), as freeform text without newlines.

" tel "
A full telephone number, including the country code. If you need to break the phone number up into its components, you can use these values for those fields:
" tel-country-code "

The country code, such as "1" for the United States, Canada, and other areas in North America and parts of the Caribbean.

" tel-national "

The entire phone number without the country code component, including a country-internal prefix. For the phone number "1-855-555-6502", this field's value would be "855-555-6502".

" tel-area-code "

The area code, with any country-internal prefix applied if appropriate.

" tel-local "
The phone number without the country or area code. This can be split further into two parts, for phone numbers which have an exchange number and then a number within the exchange. For the phone number "555-6502", use " tel-local-prefix " for "555" and " tel-local-suffix " for "6502".
" tel-extension "

A telephone extension code within the phone number, such as a room or suite number in a hotel or an office extension in a company.

" impp "

A URL for an instant messaging protocol endpoint, such as "xmpp:username@example.net".

" url "

A URL, such as a home page or company web site address as appropriate given the context of the other fields in the form.

" photo "

The URL of an image representing the person, company, or contact information given in the other fields in the form.

WHATWG Standard for more detailed information.

注意: autocomplete attribute also controls whether Firefox will — unlike other browsers — persist the dynamic disabled state and (if applicable) dynamic checkedness of an <input> element, <textarea> element, or entire <form> across page loads. The persistence feature is enabled by default. Setting the value of the autocomplete 属性到 off disables this feature. This works even when the autocomplete attribute would normally not apply by virtue of its type 。见 bug 654072 .

范例

<div>
  <label for="cc-number">Enter your credit card number</label>
  <input name="cc-number" id="cc-number" autocomplete="off">
</div>
		

Administrative levels in addresses

The four administrative level fields ( address-level1 透过 address-level4 ) describe the address in terms of increasing levels of precision within the country in which the address is located. Each country has its own system of administrative levels, and may arrange the levels in different orders when addresses are written.

address-level1 always represents the broadest administrative division; it is the least-specific portion of the address short of the country name.

Form layout flexibility

Given that different countries write their address in different ways, with each field in different places within the address, and even different sets and numbers of fields entirely, it can be helpful if, when possible, your site is able to switch to the layout expected by your users when presenting an address entry form, given the country the address is located within.

Variations

The way each administrative level is used will vary from country to country. Below are some examples; this is not meant to be an exhaustive list.

United States

A typical home address within the United States looks like this:

432 Anywhere St
Exampleville CA 95555

In the United States, the least-specific portion of the address is the state, in this case "CA" (the official US Postal Service shorthand for "California"). Thus address-level1 is the state, or "CA" in this case.

The second-least specific portion of the address is the city or town name, so address-level2 is "Exampleville" in this example address.

United States addresses do not use levels 3 and up.

United Kingdom

Address input forms in the UK should contain one address level and one, two or three address lines, depending on the address. A complete address would look like so:

103 Frogmarch Street
Upper-Wapping
Winchelsea
TN99 8ZZ

The address levels are:

  • address-level1 : The post town — "Winchelsea" in this case.
  • address-line2 : The locality — "Upper-Wapping" in this case.
  • address-line1 : The house/street particulars — "103 Frogmarch Street"

The postcode is separate. Note that you can actually use just the postcode and address-line1 to sucessfully deliver mail in the UK, so they should be the only mandatory items, but usually people tend to provide more details.

China

China can use as many as three administrative levels: the province, the city, and the district.

The 6 digit postal code is not always needed but when supplied it is placed separately with a label for clarity. For example:

北京市东城区建国门北大街8号华润大厦17层1708单元
邮编:100005

Japan

An address in Japan is typically written in one line , in an order from the least-specific to more-specific portions (in reverse order to the United States ). There are two or three administrative levels in an address. Additional line can be used to show building names and room numbers. The postal code is separate. For example:

〒381-0000
長野県長野市某町123

"〒" and following seven digits shows the postal code.

address-level1 is used for prefectures or the Tokyo Metropolis; "長野県" (Nagano Prefecture) is in this case. address-level2 is typically used for cities, counties, towns and villages; "長野市" (Nagano City) in this case. "某町123" is address-line1 which consists of an area name and a lot number.

规范

规范 状态 注释
HTML 实时标准 实时标准

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
autocomplete Chrome 完整支持 66 注意事项
完整支持 66 注意事项
注意事项 Support added for autocomplete <textarea> and <select> 元素。
注意事项 Chrome does not accept off as a value. See bug 587466 .
完整支持 Yes 注意事项
注意事项 Originally only supported on the <input> 元素。
注意事项 Chrome does not accept off as a value. See bug 587466 .
Edge 完整支持 ≤79 Firefox 完整支持 Yes IE 不支持 No Opera 完整支持 Yes Safari ? WebView Android 完整支持 66 注意事项
完整支持 66 注意事项
注意事项 Support added for autocomplete <textarea> and <select> 元素。
注意事项 WebView does not accept off as a value. See bug 587466 .
完整支持 Yes 注意事项
注意事项 Originally only supported on the <input> 元素。
注意事项 WebView does not accept off as a value. See bug 587466 .
Chrome Android 完整支持 66 注意事项
完整支持 66 注意事项
注意事项 Support added for autocomplete <textarea> and <select> 元素。
注意事项 Chrome does not accept off as a value. See bug 587466 .
完整支持 Yes 注意事项
注意事项 Originally only supported on the <input> 元素。
注意事项 Chrome does not accept off as a value. See bug 587466 .
Firefox Android 完整支持 Yes Opera Android 完整支持 Yes Safari iOS ? Samsung Internet Android 完整支持 9.0 注意事项
完整支持 9.0 注意事项
注意事项 Support added for autocomplete <textarea> and <select> 元素。
注意事项 Samsung Internet does not accept off as a value. See bug 587466 .
完整支持 Yes 注意事项
注意事项 Originally only supported on the <input> 元素。
注意事项 Samsung Internet does not accept off as a value. See bug 587466 .
new-password 值。 Chrome 完整支持 Yes Edge 完整支持 ≤79 Firefox 完整支持 67 IE 不支持 No Opera 完整支持 Yes Safari ? WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 67 Opera Android 完整支持 Yes Safari iOS ? Samsung Internet Android 完整支持 Yes

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. HTML
  2. 教程:
  3. HTML 基础
  4. HTML 介绍
    1. Introduction to HTML overview
    2. Getting started with HTML
    3. What's in the head? Metadata in HTML
    4. HTML text fundamentals
    5. Creating hyperlinks
    6. Advanced text formatting
    7. Document and website structure
    8. Debugging HTML
    9. Assessment: Marking up a letter
    10. Assessment: Structuring a page of content
  5. 多媒体和嵌入
    1. Multimedia and embedding overview
    2. Images in HTML
    3. Video and audio content
    4. From object to iframe — other embedding technologies
    5. Adding vector graphics to the Web
    6. Responsive images
    7. Assessment: Mozilla splash page
  6. 参考:
  7. HTML 元素
    1. <a>
    2. <abbr>
    3. <acronym>
    4. <address>
    5. <applet>
    6. <area>
    7. <article>
    8. <aside>
    9. <audio>
    10. <b>
    11. <base>
    12. <basefont>
    13. <bdi>
    14. <bdo>
    15. <bgsound>
    16. <big>
    17. <blink>
    18. <blockquote>
    19. <body>
    20. <br>
    21. <button>
    22. <canvas>
    23. <caption>
    24. <center>
    25. <cite>
    26. <code>
    27. <col>
    28. <colgroup>
    29. <command>
    30. <content>
    31. <data>
    32. <datalist>
    33. <dd>
    34. <del>
    35. <details>
    36. <dfn>
    37. <dialog>
    38. <dir>
    39. <div>
    40. <dl>
    41. <dt>
    42. <element>
    43. <em>
    44. <embed>
    45. <fieldset>
    46. <figcaption>
    47. <figure>
    48. <font>
    49. <footer>
    50. <form>
    51. <frame>
    52. <frameset>
    53. <h1>
    54. <head>
    55. <header>
    56. <hgroup>
    57. <hr>
    58. <html>
    59. <i>
    60. <iframe>
    61. <image>
    62. <img>
    63. <input>
    64. <ins>
    65. <isindex>
    66. <kbd>
    67. <keygen>
    68. <label>
    69. <legend>
    70. <li>
    71. <link>
    72. <listing>
    73. <main>
    74. <map>
    75. <mark>
    76. <marquee>
    77. <menu>
    78. <menuitem>
    79. <meta>
    80. <meter>
    81. <multicol>
    82. <nav>
    83. <nextid>
    84. <nobr>
    85. <noembed>
    86. <noframes>
    87. <noscript>
    88. <object>
    89. <ol>
    90. <optgroup>
    91. <option>
    92. <output>
    93. <p>
    94. <param>
    95. <picture>
    96. <plaintext>
    97. <pre>
    98. <progress>
    99. <q>
    100. <rb>
    101. <rp>
    102. <rt>
    103. <rtc>
    104. <ruby>
    105. <s>
    106. <samp>
    107. <script>
    108. <section>
    109. <select>
    110. <shadow>
    111. <slot>
    112. <small>
    113. <source>
    114. <spacer>
    115. <span>
    116. <strike>
    117. <strong>
    118. <style>
    119. <sub>
    120. <summary>
    121. <sup>
    122. <table>
    123. <tbody>
    124. <td>
    125. <template>
    126. <textarea>
    127. <tfoot>
    128. <th>
    129. <thead>
    130. <time>
    131. <title>
    132. <tr>
    133. <track>
    134. <tt>
    135. <u>
    136. <ul>
    137. <var>
    138. <video>
    139. <wbr>
    140. <xmp>
  8. 全局属性
    1. accesskey
    2. autocapitalize
    3. class
    4. contenteditable
    5. contextmenu
    6. data-*
    7. dir
    8. draggable
    9. dropzone
    10. hidden
    11. id
    12. inputmode
    13. is
    14. itemid
    15. itemprop
    16. itemref
    17. itemscope
    18. itemtype
    19. lang
    20. part
    21. slot
    22. spellcheck
    23. style
    24. tabindex
    25. title
    26. translate
    27. x-ms-acceleratorkey
    28. x-ms-format-detection
  9. <input> 类型
    1. <input type="button">
    2. <input type="checkbox">
    3. <input type="color">
    4. <input type="date">
    5. <input type="datetime">
    6. <input type="datetime-local">
    7. <input type="email">
    8. <input type="file">
    9. <input type="hidden">
    10. <input type="image">
    11. <input type="month">
    12. <input type="number">
    13. <input type="password">
    14. <input type="radio">
    15. <input type="range">
    16. <input type="reset">
    17. <input type="search">
    18. <input type="submit">
    19. <input type="tel">
    20. <input type="text">
    21. <input type="time">
    22. <input type="url">
    23. <input type="week">
  10. 文档编制:
  11. 有用清单
  12. All pages index
  13. Pages tagged "HTML"
  14. 贡献
    1. HTML 文档状态
    2. MDN 工程