Web NFC: NDEF Tags, Scan, Write, and Permissions
How Web NFC and NDEFReader read and write NFC tags in the browser, including permissions, record types, and Android limits.
This page summarizes Google Chrome’s documentation on Web NFC for sites that need to read or program NFC tags from a web page on a phone—museum taps, inventory badges, provisioning URLs, and similar flows. The API is Web NFC; the JavaScript entry point is NDEFReader. In Chrome it shipped for Android in Chrome 89 as part of the capabilities work on the web platform.
Web NFC and NDEF: what the API can and cannot do
Section titled “Web NFC and NDEF: what the API can and cannot do”Web NFC lets a site read and write NFC tags when the user holds a device within roughly 5–10 cm (about 2–4 inches) of the tag.
NFC stands for Near Field Communications, a short-range wireless technology operating at 13.56 MHz that enables communication between devices at a distance less than 10 cm and a transmission rate of up to 424 kbit/s.
Web NFC provides sites the ability to read and write to NFC tags when they are in close proximity to the user’s device (usually 5-10 cm, 2-4 inches). The current scope is limited to NFC Data Exchange Format (NDEF), a lightweight binary message format that works across different tag formats.
— Google Chrome, Interact with NFC devices on Chrome for Android
NDEF (NFC Data Exchange Format) is the only tag format Web NFC handles today. That limit exists because NDEF read/write security is easier to reason about than raw tag protocols.
Web NFC is limited to NDEF because the security properties of reading and writing NDEF data are more easily quantifiable. Low-level I/O operations (e.g. ISO-DEP, NFC-A/B, NFC-F), Peer-to-Peer communication mode and Host-based Card Emulation (HCE) are not supported.
— Google Chrome, Interact with NFC devices on Chrome for Android
Typical use cases described in the docs include exhibit info cards, container inventory tags, conference badges (sometimes locked read-only), and sharing provisioning secrets or configuration in the field.
| Capability | Supported in Web NFC (per docs) |
|---|---|
| NDEF read/write on passive tags | Yes |
| NDEF record types (text, URL, MIME, smart poster, etc.) | Yes |
| ISO-DEP, NFC-A/B/F low-level I/O | No |
| Peer-to-peer NFC mode | No |
| Host-based Card Emulation (HCE) | No |
NDEFReader: tags, messages, and records
Section titled “NDEFReader: tags, messages, and records”An NFC tag is a passive device powered by the phone’s field when they are close. Tags that support NDEF hold one NDEF message, which wraps one or more NDEF records (payload plus type metadata).
The NDEFReader object is the entry point in Web NFC that exposes functionality for preparing reading and/or writing actions that are fulfilled when an NDEF tag comes in proximity.
— Google Chrome, Interact with NFC devices on Chrome for Android
An NFC tag that supports NDEF is like a post-it note. Anyone can read it, and unless it is read-only, anyone can write to it.
— Google Chrome, Interact with NFC devices on Chrome for Android
Web NFC supports NFC Forum record types including empty, text, url, smart poster, mime, absolute-url, external type, unknown, and local type (local names in Web NFC start with :—for example :t, :act, :s inside a smart poster).
Feature detection: API vs hardware
Section titled “Feature detection: API vs hardware”NDEFReader in window means the browser implements Web NFC—not that the device has an NFC radio.
The presence of NDEFReader tells you that the browser supports Web NFC, but not whether the required hardware is present. In particular, if the hardware is missing, the promise returned by certain calls will reject.
— Google Chrome, Interact with NFC devices on Chrome for Android
if ('NDEFReader' in window) { /* Scan and write NFC tags */}For permanent read-only tags, makeReadOnly() exists on Android in Chrome 100+:
if ('NDEFReader' in window && 'makeReadOnly' in NDEFReader.prototype) { // makeReadOnly() is supported.}Scan NFC tags: user gesture, permission, and events
Section titled “Scan NFC tags: user gesture, permission, and events”scan() starts listening for tags. It returns a promise and may show a permission prompt.
Calling scan() returns a promise. The user may be prompted if access was not previously granted. The promise will resolve if the following conditions are all met:
It was only called in response to a user gesture such as a touch gesture or mouse click. The user has allowed the website to interact with NFC devices. The user’s phone supports NFC. The user has enabled NFC on their phone.
— Google Chrome, Interact with NFC devices on Chrome for Android
After scan() resolves, subscribe to reading and readingerror (for incompatible tags).
const ndef = new NDEFReader();ndef.scan().then(() => { ndef.onreadingerror = () => { console.log("Cannot read data from the NFC tag. Try another one?"); }; ndef.onreading = (event) => { console.log("NDEF message read."); };}).catch((error) => { console.log(`Error! Scan failed to start: ${error}.`);});Each NDEFReadingEvent provides serialNumber (or "") and message. Loop message.records and branch on recordType; data is a DataView (UTF-16 cases included). For text records, decode with TextDecoder(record.encoding) and read language via record.lang.
Pass an AbortSignal in options to stop scanning—for example after a timeout.
Write NFC tags: strings, records, and overwrite
Section titled “Write NFC tags: strings, records, and overwrite”write() also requires a user gesture, granted nfc permission, NFC hardware enabled, and (for the write promise to fulfill) the user tapping a tag so the message is written.
A plain string writes a text record:
const ndef = new NDEFReader();await ndef.write("Hello World");Structured messages use { records: [...] }—for example a URL record:
await ndef.write({ records: [{ recordType: "url", data: "https://w3c.github.io/web-nfc/" }]});Multiple records can be written in one operation. MIME records need recordType: "mime", mediaType, and binary data. Smart poster, external type (example.com:foo), and android.com:pkg (Android Application Record) patterns are documented with examples on Interact with NFC devices on Chrome for Android.
To refuse overwriting existing NDEF data, pass { overwrite: false }—the promise rejects if the tag already holds a message:
await ndef.write("Writing data on an empty NFC tag is fun!", { overwrite: false });A common pattern is write then scan (optionally with AbortController) to confirm what was stored on the tag.
makeReadOnly: one-way lock on tag content
Section titled “makeReadOnly: one-way lock on tag content”makeReadOnly() permanently prevents further writes; it cannot be undone.
To prevent malicious users from overwriting an NFC tag’s content, it is possible to make NFC tags permanently read-only. This operation is a one-way process and cannot be reversed.
— Google Chrome, Interact with NFC devices on Chrome for Android
The same user-gesture, permission, hardware, and tap requirements apply as for write(). Typical flow: write payload, then makeReadOnly()—for example locking conference badge data.
Security, permissions, and page visibility
Section titled “Security, permissions, and page visibility”Web NFC follows powerful-feature principles: user control, transparency, and ergonomics.
Web NFC is only available to top-level frames and secure browsing contexts (HTTPS only). Origins must first request the “nfc” permission while handling a user gesture (e.g a button click). The NDEFReader scan(), write(), and makeReadOnly() methods trigger a user prompt, if access was not previously granted.
— Google Chrome, Interact with NFC devices on Chrome for Android
Practical rules from the same page:
- Tie
scan(),write(), andmakeReadOnly()to explicit UI (button click/tap)—not autoplay on load. - The page must be visible when the user taps the tag; NFC is blocked if the display is off or the device is locked.
- While the document is hidden, NFC operations are suspended and resume when visible again (you can observe this with the Page Visibility API).
Check nfc permission before prompting again
Section titled “Check nfc permission before prompting again”The Permissions API can show a scan button only when access is not already granted:
const nfcPermissionStatus = await navigator.permissions.query({ name: "nfc" });if (nfcPermissionStatus.state === "granted") { await startScanning();} else { document.querySelector("#scanButton").onclick = () => startScanning();}The same nfc permission covers scanning and writing.
Browser support and common mistakes
Section titled “Browser support and common mistakes”Web NFC is available on Android in Chrome 89.
— Google Chrome, Interact with NFC devices on Chrome for Android
The capabilities hub also notes that reading and writing NFC tags is possible in Chrome for Android—treat desktop and non-Chromium browsers as unsupported unless you verify otherwise.
| Mistake | What happens |
|---|---|
Calling scan() / write() without a user gesture |
Promise does not fulfill under documented rules |
| Serving the page over HTTP | API unavailable (secure context required) |
Assuming 'NDEFReader' in window means NFC hardware exists |
Calls may reject at runtime |
| Expecting HCE, P2P, or raw tag protocols | Out of scope for Web NFC today |
Writing without handling overwrite: false failures |
Tag already contains NDEF; write rejects |
| Running flows while the tab is hidden or phone locked | NFC access blocked or suspended |
Official samples and demos are linked from Interact with NFC devices on Chrome for Android (cards demo, grocery demo, and others).
How to check this on your site
Section titled “How to check this on your site”-
Confirm the page is HTTPS, in a top-level browsing context, and you test on Android Chrome 89+ with NFC enabled in system settings—see Interact with NFC devices on Chrome for Android.
-
In the page console or your code, verify
'NDEFReader' in windowand, if you use locking,'makeReadOnly' in NDEFReader.prototypewhere needed. -
Use a visible control (button) to call
scan()orwrite(), accept thenfcprompt, and confirmnavigator.permissions.query({ name: "nfc" })reports the state you expect after the user decides. -
With a known NDEF tag, exercise read (
onreading/ record parsing) and, on a spare tag, write plus optionalmakeReadOnly()—match behavior to the conditions listed in Interact with NFC devices on Chrome for Android. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence or code you are asking about.