Element types
- Create with
elements.create(type, options?). - You can’t mix
cardwith the split types in oneElementsinstance — creating a duplicate type throwselement:duplicate. To switch layouts, create a separateElementsinstance 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.
Create options
Pass these toelements.create(type, options):
Events
Subscribe withelement.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:
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 calldestroy() 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
cardelement 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.