References

Beginner-friendly references for web development, with live, editable examples.

The HTML autocapitalize attribute

Global attribute Works on every element All modern browsers
In short

The HTML autocapitalize attribute controls how on-screen keyboards automatically capitalize the text a user types in form fields and contenteditable elements. Values include none, sentences, words and characters. It is a global attribute, most relevant on touch devices.

Overview

The autocapitalize attribute hints to virtual keyboards how to auto-capitalize text as the user types. It has no effect on physical keyboards, and it does not change the value that is submitted, only what the on-screen keyboard suggests.

Use none (or off) for case-sensitive data like usernames and codes, characters for things like country or coupon codes, words for names, and sentences for ordinary prose.

Values

Value
none (off) | sentences (on) | words | characters

Example

Live example
<input type="text" autocapitalize="characters" placeholder="Type a code (ABC123)" style="padding:8px; width:100%;">

Best practices

  • Setting autocapitalize on the <form> gives its fields a default, even fields linked to it with the form attribute. A field's own non-empty value overrides it, and a <fieldset> or <div> passes nothing down.
  • To stop capitalization, write none or off. An unknown value such as no or false is read as sentences, the opposite of what you meant.
  • Choose the value with dictation in mind. A virtual keyboard lets the user switch a suggested capital back to lowercase, but voice input may apply the hint without giving them that chance.
  • Set a value wherever capitalization matters, since the unset default varies. Chrome and Safari capitalize sentences by default, while Firefox starts with none.
  • Normalize letter case in your own code before you compare or store values such as coupon codes. Users can sometimes override the hint or edit the text afterward, so it must not be relied on for validation.

Frequently asked questions

What does the autocapitalize attribute do?
Controls how on-screen keyboards automatically capitalize text the user enters.
Is autocapitalize guaranteed to work?
No. It is a hint to the on-screen keyboard, so software keyboards may honor or ignore it, and a physical keyboard ignores it entirely.
Which elements does autocapitalize affect?
It is a global attribute, but it only matters where text is entered: <input> and <textarea> fields and elements with contenteditable.
Which input types ignore autocapitalize?
Inputs of type url, email and password ignore autocapitalize. There the browser and keyboard make their own choice, whatever value you set.