The Wayback Machine - https://web.archive.org/web/20250320154602/https://www.geeksforgeeks.org/html-autocapitalize-attribute/
Open In App

HTML autocapitalize Attribute

Last Updated : 30 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The HTML autocapitalize attribute is used to define whether the text present inside the HTML element should be automatically capitalized or not. It is a global attribute which means it is applied to all HTML elements.

Features:

  • It specifies how the text will be automatically capitalized.
  • It indicates that the first letter of the word or sentence would be in Capital.
  • It does not support <input> tag with type URL, Email, and Password.
  • It is a Global Attribute.

Syntax:

<tag_name autocapitalize="off | none | on 
| sentences | words | characters" />

Attribute Values:

  • off/none: It defines that the text will not be capitalized.
  • on/sentences: It defines that the first letter of each sentence would be capital.
  • words: It defines that the first letter of each word would be capital.
  • characters: It specifies that the whole text will be capitalized.

Example: Below HTML code use the auto-capitalize attribute with the <input> Tag.  

HTML
<!DOCTYPE html>
<html>

<head>
    <title> HTML input autocapitalize Attribute
    </title>
</head>

<body style="text-align:center">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>

    <h2>
        HTML autocapitalize Attribute
        with &lt;input&gt; Tag
    </h2>

    Name:
    <input type="text" 
           autocapitalize="words" autofocus>
    <br><br>

    <!-- Assign id to the Button. -->
    <button id="GFG">
        Submit
    </button>
    <br>
</body>

</html>

Output:

Important Note: This code is working on virtual keyboards such as on mobile devices and voice inputs. It is not working on physical keyboards.

Supported Browsers:

HTML autocapitalize Attribute – FAQs

How do I use the autocapitalize attribute in an HTML element?

You can use it with input fields or textareas, like this: <input type=”text” autocapitalize=”words”>.

Can the autocapitalize attribute be dynamically changed using JavaScript?

Yes, you can change the autocapitalize attribute dynamically using JavaScript by accessing the element’s properties.

Does the autocapitalize attribute affect already entered text?

No, it only affects new text as it is typed. It does not retroactively change the capitalization of text already entered in the field.

Does autocapitalize affect all types of input fields?

It is most relevant for text-based input fields, such as type=”text”, type=”search”, type=”email”, type=”password”, and type=”url”. It does not affect non-text input types like type=”number”.

How does autocapitalize differ from CSS text-transform?

The autocapitalize attribute affects the behavior of input fields as the user types, instructing the input mechanism on capitalization rules. In contrast, CSS text-transform only changes the visual presentation of text without affecting the input data itself.



Next Article

Similar Reads

three90RightbarBannerImg