Learning about the autocomplete and list attribute | Forms

HTML5 introduces two attributes, autocomplete and list, that enhance form functionality and user experience, especially in responsive web design.

autocomplete Attribute

The autocomplete attribute helps browsers to predict the user’s input based on previous form submissions or browsing history. This can save users time and effort, especially on mobile devices.

Example:

HTML

<form>

    <label for=”name”>Name:</label>

    <input type=”text” id=”name” name=”name” autocomplete=”name”>

    <br>

    <label for=”email”>Email:</label>

    <input type=”email” id=”email” name=”email” autocomplete=”email”>

    <br>

    <button type=”submit”>Submit</button>

</form>

In this example, the name and email fields are set to autocomplete. When a user starts typing in these fields, the browser may suggest previously entered values, making it easier for them to fill out the form.

Values for autocomplete:

  • on: Enables autocomplete.
  • off: Disables autocomplete.
  • name: Suggests names.
  • honorific-prefix: Suggests honorific prefixes (e.g., Mr., Ms.).
  • given-name: Suggests given names.
  • family-name: Suggests family names.
  • organization: Suggests organizations.
  • street-address: Suggests street addresses.
  • city: Suggests cities.
  • state: Suggests states or provinces.
  • country: Suggests countries.
  • postal-code: Suggests postal codes.
  • phone-number: Suggests phone numbers.
  • email: Suggests email addresses.
  • url: Suggests URLs.

list Attribute

The list attribute creates a dropdown list of suggestions for an input field. It’s often used in combination with the datalist element.

Example:

HTML

<datalist id=”countryList”>

    <option value=”United States”>

    <option value=”Canada”>

    <option value=”Australia”>

</datalist>

<form>

    <label for=”country”>Country:</label>

    <input type=”text” id=”country” name=”country” list=”countryList”>

    <br>

    <button type=”submit”>Submit</button>

</form>

In this example, the datalist element countryList contains a list of countries. When the user starts typing in the country field, the browser will display a dropdown list of matching countries from the datalist.

Responsive Design Considerations:

  • Mobile-Friendly: Ensure that the autocomplete and list features work well on mobile devices and don’t interfere with the user experience.
  • Privacy: Be mindful of privacy concerns when using autocomplete, especially for sensitive information.
  • Accessibility: Make sure that autocomplete and list features are accessible to users with disabilities.

By effectively using the autocomplete and list attributes, you can create more efficient and user-friendly forms in your responsive web designs.

Exploring attributes like ‘required’ and ‘autofocus’ | Forms
HTML5 Input Types | Forms

Get industry recognized certification – Contact us

keyboard_arrow_up
Open chat
Need help?
Hello 👋
Can we help you?