HTML global attributeGlobal attributes

autocapitalize

Tells the on-screen keyboard when to capitalize: never, at the start of a sentence, at the start of a word, or always.

Applies to
Text <input> fields, <textarea>, elements with contenteditable, and <form> as the default for its fields
On this page

Example

#
HTML
<style>
  form { display: grid; gap: 10px; max-width: 320px; }
  label { display: grid; gap: 4px; }
</style>

<form>
  <label>Login <input type="text" name="login" autocapitalize="none" spellcheck="false"></label>
  <label>Full name <input type="text" name="name" autocapitalize="words"></label>
  <label>Discount code <input type="text" name="coupon" autocapitalize="characters"></label>
  <label>Message to your mentor
    <textarea name="message" rows="2" autocapitalize="sentences"></textarea>
  </label>
</form>
Preview

You will only see the difference on a phone or tablet when you start typing on the on-screen keyboard. On a computer all the fields behave the same way.

Definition and usage

#

The autocapitalize attribute hints to the on-screen keyboard on a phone or tablet when to turn on capital letters. By default the keyboard usually capitalizes the start of every sentence. In a message that is handy, but in a field for a login, a discount code or a web address it gets in the way, because the user has to keep fixing the first letter.

On a computer with a physical keyboard the attribute changes nothing. It also does not work in type="email", type="url" and type="password" fields, where the keyboard does not capitalize on its own anyway. You use it on ordinary text fields, on <textarea> and on elements with contenteditable, and set on a <form> it becomes the default for all the fields inside.

The words value is useful for first names, last names and city names, and characters for codes written in capitals, for example a license plate number. It is only a convenience: the user can still change the case by hand, so validate the data in code anyway.

Syntax

#
Syntax
<element autocapitalize="none | sentences | words | characters">…</element>

Values

#
  • none

    or off

    No automatic capital letters. For logins, codes, addresses and code snippets.
  • sentences

    or on

    A capital letter at the start of every sentence. This is usually how the keyboard behaves when the attribute is absent.
  • words

    A capital letter at the start of every word, for example in a first name, last name or city name.
  • characters

    All letters capitalized, for example in discount codes and license plate numbers.

Browser support

#

Limited support

Not every browser supports it. Check support before you use it in production.

Good practices

#
  • You can add the attribute without worry. Browsers that do not support it simply ignore it, and on phones it works in Safari, Chrome and Firefox.
  • In login and code fields, combine autocapitalize="none" with spellcheck="false". The keyboard will not change the first letter, and the browser will not underline the typed text as an error.

Related entries

#

Spotted a mistake or missing an example? Write to us.