Skip to main content
Elements renders card input as one combined field, or as separate number/expiry/CVV fields you lay out yourself.

Element types

  • Create with elements.create(type, options?).
  • You can’t mix card with the split types in one Elements instance — creating a duplicate type throws element:duplicate. To switch layouts, create a separate Elements instance and destroy the other. See Fix card fields that don’t render for this and other mount-time failures.
  • Tab order across the split fields (number → expiry → CVV) is handled for you.
  • Elements doesn’t collect cardholder name, postal code, email, or phone — collect those with your own inputs.
Split fields require BroadcastChannel, available in Safari 15.4+. Older Safari versions surface expiry_missing / cvv_missing field errors — use the combined card type if you need to support them.

Create options

Pass these to elements.create(type, options):
supportedBrands is an allowlist, not just a display hint: a card number whose detected brand isn’t in the list stays incomplete and reports unsupported_brand, even if the brand is one you recognize. A number whose brand can’t be detected at all (unknown) isn’t rejected by this list. Omit the option (or pass []) to accept every brand.

Events

Subscribe with element.on(event, handler); unsubscribe with element.off(event, handler). Gate your pay button on valid, not complete. error is set by blur-time validation only, so it can still be null while valid is false — the shopper may simply still be typing. Use error for inline messaging, not for enabling submit:
If the iframe doesn’t finish loading within 5 seconds, change fires once with error.code: "required" and a “failed to load” message; a later successful ready clears it with a recovery change (error: null). There’s no separate loaderror event — treat a required error as the load-failure signal.

Field error codes

change.error is a { code, message, field } object. field names the Element the error belongs to (for example cardExpiry) — except on the combined card Element, where field is always "card"; use code to tell which cell (number, expiry, or CVV) actually failed. code (FieldErrorCode): required (empty, or failed to load), incomplete_number, invalid_number (fails the Luhn checksum), unsupported_brand (see the supportedBrands allowlist above), incomplete_expiry, invalid_month, invalid_year, expired_card, invalid_expiry (generic fallback), incomplete_cvv, invalid_cvv. See Show card validation errors for how to display each of these. message follows the Elements locale for field-validation errors. The required messages from Elements.getState()/Elements.submit(), and the load-timeout message above, are English only regardless of locale — see Customize appearance: locales for what’s translated.

Methods

SPA cleanup

If the container element is removed from the DOM (for example, on a route change), the element destroys itself automatically — you don’t need to call destroy() yourself in that case. Still call destroy() explicitly when you conditionally unmount a form without removing its container, to avoid leaking the iframe and its listeners.

Safari notes

  • iOS Safari suppresses the native autofill popup on the CVV field and scrolls the focused field into view when the keyboard opens.
  • The combined card element supports the browser’s saved-card autofill; split CVV fields don’t autofill across iframes.

Next steps

Customize appearance

Themes, variables, and CSS rule overrides.

Elements SDK errors

Full ElementsError reference.
Last modified on September 15, 2026