How to autocomplete the values for First Name or Given Name fields in an input HTML element using HTML?

Published December 15, 2022

To autocomplete the value for the First Name or Given Name fields in an input HTML element, you can add the attribute called autocomplete with the value of given-name to the input HTML element using HTML.

TL;DR

<!-- 
  A simple webpage with an `input` HTML
  element with autocomplete for the First Name 
-->
<html>
  <body>
    <label for="firstName">First Name</label>
    <input type="text" id="firstName" autocomplete="given-name" />
  </body>
</html>

For example, let's say we have an input HTML element to accept the First Name of the user.

The HTML for that would look something like this,

<!-- A simple webpage with an `input` HTML element -->
<html>
  <body>
    <label for="firstName">First Name</label>
    <input type="text" id="firstName" />
  </body>
</html>

A visual representation of the webpage is shown below,

no autocomplete for the first name input box when clicking on the input html element

As you can see from the above GIF that when clicking on the input HTML element, the autocomplete is not working for the First Name field.

To activate the autocomplete feature, we have to add the autocomplete attribute with the value of given-name. The given-name value refers that we need to autocomplete the First Name of the user.

It can be done like this,

<!-- 
  A simple webpage with an `input` HTML
  element with autocomplete for the First Name 
-->
<html>
  <body>
    <label for="firstName">First Name</label>
    <input type="text" id="firstName" autocomplete="given-name" />
  </body>
</html>

Now the webpage looks like this,

autocomplete activated for the first name input box when clicking on the input html element

As you can see from the above GIF now when clicking on the input HTML element, a autocomplete dropdown is shown to the user where they can select their first name.

We have successfully added the autocomplete feature and added the value for the First Name input HTML element using HTML. Yay 🥳!

See the above code live in the codesandbox.

That's all 😃.

Share on: Facebook Twitter