Skip to content
Create account
or
Sign in
The Stripe Docs logo
/
Ask AI
Create account
Sign in
Get started
Payments
Finance automation
Platforms and marketplaces
Money management
Developer tools
Get started
Payments
Finance automation
Get started
Payments
Finance automation
Platforms and marketplaces
Money management
Overview
Versioning
Changelog
Upgrade your API version
Upgrade your SDK version
Developer tools
SDKs
    Overview
    Server-side SDKs
    Mobile SDKs
    iOS SDK
    Android SDK
    React Native SDK
    Web SDKs
    ES Module Stripe.js
    React Stripe.js
    Terminal SDKs
    iOS SDK
    Android SDK
    React Native SDK
    Community
    Community SDKs
    Mobile migrations
    Migrate to iOS SDK 24
    Migrate to Android SDK 21
API
Testing
Workbench
Event Destinations
Workflows
Stripe CLI
Stripe Shell
Developers Dashboard
Agent toolkit
Stripe health alertsBuild with LLMsStripe for Visual Studio CodeFile uploads
Security
Security
Extend Stripe
Stripe Apps
Stripe Connectors
Partners
Partner ecosystem
Partner certification
HomeDeveloper toolsSDKs

ES Module Stripe.js SDK

Set up the ES Module Stripe.js client-side SDK in your web application.

Copy page

See the code

To see how ES Module Stripe.js works or to help develop it, check out the project on GitHub.

This introductory guide shows you how to install the ES Module Stripe.js client-side SDK with a script tag or package manager. The SDK wraps the global Stripe function provided by the Stripe.js script as an ES module. It allows you to use Elements, our pre-built UI components, to create a payment form that lets you securely collect a customer’s card details without handling the sensitive data.

Before you begin

Enable the payment methods you want to support on the payment methods settings page.

Manually load the Stripe.js script

Installation

To install by script, add the Stripe.js ES Module as a script to the <head> element of your HTML. This allows any newly created Stripe objects to be globally accessible in your code.

<head> <title>Checkout</title> <script src="https://js.stripe.com/v3/" async></script> </head>

Stripe.js constructor

Next, set the API publishable key to allow Stripe to tokenise customer information and collect sensitive payment details. For example:

var stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
);

Load Stripe.js as an ES Module

Installation

To install by package manager, install the Stripe.js ES Module from the npm public registry.

npm install @stripe/stripe-js

Stripe.js constructor

Next, import the module into a JavaScript file. The following function returns a Promise that resolves with a newly created Stripe object after Stripe.js loads.

import {loadStripe} from '@stripe/stripe-js'; const stripe = await loadStripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
);

See also

This wraps up the introductory guide to setting up the ES Module Stripe.js SDK. See the links below to get started with your integration.

  • Accept a payment with a payment element on GitHub
  • Accept a payment with a payment element in Docs
  • Custom payment flow builder
  • Stripe.js reference
Was this page helpful?
YesNo
Need help? Contact Support.
Join our early access programme.
Check out our changelog.
Questions? Contact Sales.
LLM? Read llms.txt.
Powered by Markdoc