TechnologiesSwiftUI

TextInputAutocapitalization struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The kind of autocapitalization behavior applied during text input.

How it works

TextInputAutocapitalization describes how a text-entry view should automatically capitalize the characters a person types. Use it to align the keyboard's capitalization behavior with the kind of content a field expects, so names start with capital letters while email addresses and other case-sensitive input stay exactly as typed. Reach for it whenever the default sentence-capitalization would fight the data — proper names, addresses, identifiers, or anything that must be entered verbatim.

  1. Apply it with the textInputAutocapitalization(_:) modifier

    You rarely construct a TextInputAutocapitalization value directly; instead you pass one to the textInputAutocapitalization(_:) view modifier, which sets the capitalization style for the text input inside that view. In the example each TextField carries its own .textInputAutocapitalization(...), so the two fields can behave differently.

  2. Capitalize proper nouns with .words

    The .words style tells the keyboard to capitalize the first letter of every word, which suits names and titles. The "Full Name" TextField uses .textInputAutocapitalization(.words) so each part of a person's name is capitalized as they type.

  3. Turn capitalization off with .never

    The .never style suppresses automatic capitalization entirely, leaving the text exactly as entered. The "Email" TextField applies .textInputAutocapitalization(.never) because an email address is case-sensitive and an unwanted leading capital would corrupt it.

  4. Choose from the standard capitalization styles

    TextInputAutocapitalization exposes a fixed set of static styles — .never, .words, .sentences, and .characters — that map to the system's capitalization behaviors. You select the one that matches the field's content; the example draws on .words and .never, while .sentences and .characters cover prose and all-caps input.

  5. Pair it with keyboardType for the full input experience

    Capitalization is one half of configuring a field; the other is the keyboard layout. The email field combines .textInputAutocapitalization(.never) with .keyboardType(.emailAddress) so the entry surface is tuned for addresses both in capitalization and in the keys it offers.

Try it — Change the email field's .textInputAutocapitalization(.never) to .textInputAutocapitalization(.sentences) and watch the first letter you type get capitalized — exactly the behavior you want to avoid in an address.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

TextInputAutocapitalization.swift
struct TextInputAutocapitalizationDemo: View {
    @State private var name = ""
    @State private var email = ""

    var body: some View {
        Form {
            TextField("Full Name", text: $name)
                .textInputAutocapitalization(.words)
            TextField("Email", text: $email)
                .textInputAutocapitalization(.never)
                .keyboardType(.emailAddress)
        }
        .padding()
    }
}
Live preview
Full Name Email
Full Name Email
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →