How Safari Auto-Fills One-Time Verification Codes
This article provides a complete overview of how Apple’s Safari web browser automatically detects, extracts, and fills one-time verification codes from the Apple Mail and Messages apps. It covers the underlying HTML triggers used by websites, the on-device machine learning that scans incoming communications, the security measures that prevent phishing, and how Apple’s ecosystem syncs these codes across different devices.
Website Input Detection
The autofill process begins before a message or email even arrives.
Safari identifies where to place a verification code by reading the
webpage's underlying HTML. Web developers add a specific
attribute—autocomplete="one-time-code"—to the input field
designed for the security code.
When you click or tap on this specific field, Safari recognizes the attribute and alerts the operating system to listen for an incoming authentication code. If a website developer fails to include this specific HTML tag, Safari falls back on heuristics, scanning the webpage text near the input box for keywords like "verification," "passcode," or "two-factor" to guess the field's purpose.
On-Device Message and Email Scanning
When an SMS arrives in Messages or an email arrives in the Apple Mail app, the operating system (iOS, iPadOS, or macOS) immediately scans the incoming text in the background.
To maintain user privacy, this scanning process happens entirely on the device using Apple's local Natural Language Processing (NLP) frameworks. The system does not send your messages or emails to external servers to be read. Instead, the on-device intelligence looks for standard conversational patterns, such as "Your verification code is" or "Use this code to log in," paired with a numerical or alphanumeric string. Once identified, the system temporarily extracts just the code segment.
Domain Binding and Security
To protect users from phishing attacks, Safari utilizes a security
feature known as domain-bound codes. Apple encourages developers to
format their verification messages with a specific syntax at the bottom
of the text or email: an @ symbol followed by the website's
domain, and a # symbol followed by the code (for example,
@example.com #123456).
When the operating system detects this syntax, it pairs the code exclusively with that specific URL. Safari will then verify the URL of the website you are currently visiting. If you are on a legitimate site, Safari offers the code. If you are on a deceptive phishing site with a different URL, Safari will refuse to display the autofill suggestion, protecting your account from being compromised.
Cross-Device Syncing via Continuity
Often, a user is browsing Safari on a Mac, but the SMS verification code is sent to their iPhone. Safari handles this seamlessly using Apple’s Continuity architecture.
For this to work, both devices must be signed into the same Apple ID, have Bluetooth and Wi-Fi enabled, and have "Text Message Forwarding" turned on in the iPhone's settings. When the iPhone receives the SMS, it performs the detection process and securely relays the extracted code over the local network to the Mac, displaying it in the desktop Safari browser within seconds. For emails, the Mac’s native Mail app simply needs to be open or fetching mail in the background to detect the code locally.
Code Insertion and Automatic Deletion
Once the code is extracted and matched to the active Safari input field, the system presents it to the user. On an iPhone or iPad, the code appears directly above the on-screen keyboard. On a Mac, it appears as a small dropdown prompt right below the text box on the webpage.
With a single tap or click, Safari populates the field and often automatically submits the form. To keep your inboxes clutter-free, iOS 17, iPadOS 17, and macOS Sonoma (and later versions) include a "Clean Up Automatically" toggle in the system password settings. When enabled, the operating system will automatically move the verification text or email to the trash immediately after Safari successfully uses the code.