Checkout Kit for Web
Agentic commerce is rolling out to Dev Dashboard. Sign up to be notified.
The <shopify-checkout> web component embeds Shopify Checkout in web apps. Buyers complete their purchase without leaving your site. By default, checkout opens in a new tab. Authenticated embedders can render checkout inline, customize branding, and configure features like tipping and analytics.
Anchor to What you'll learnWhat you'll learn
In this guide, you'll learn how to do the following tasks:
- Add the Checkout Kit script to your page
- Present checkout using a checkout URL
- Configure checkout behavior with attributes
- Listen for checkout events
Anchor to RequirementsRequirements
- A valid Shopify checkout URL (from the Storefront API
cart.checkoutUrlfield or a cart permalink) - For authenticated checkouts:
client_idandclient_secretprovided by Shopify
Anchor to Step 1: Add the Checkout Kit scriptStep 1: Add the Checkout Kit script
Include the script from the Shopify CDN in your HTML:
This CDN URL is a preview for development purposes only.
HTML
Alternatively, import the @shopify/checkout-kit npm package:
JavaScript
Anchor to Step 2: Add the checkout elementStep 2: Add the checkout element
Add a <shopify-checkout> element to your HTML. Use the checkout URL as the href for an anchor element to provide a fallback if JavaScript is disabled:
HTML
Anchor to Step 3: Present checkoutStep 3: Present checkout
Set the src attribute to a checkout URL and call open() to present checkout:
JavaScript
Anchor to Step 4: Listen for eventsStep 4: Listen for events
The <shopify-checkout> component dispatches DOM events at key points in the checkout lifecycle. The following example listens for the checkout:complete event:
JavaScript
Anchor to ConfigurationConfiguration
Configure the <shopify-checkout> element using attributes.
Required. The checkout URL from the Storefront API or a cart permalink.
HTML
Controls where checkout renders. Valid values:
auto(default): Opens checkout in a new tab.popup: Opens checkout in a popup window.inline: Renders checkout inline when the element connects to the DOM. You must provide a list of valid pages where you intend to embed checkout so that we can set theframe-ancestorsvalue in theContent-Security-Policyresponse header.
JavaScript
The JWT that authenticates checkout. Required for inline embedding and configuration overrides.
HTML
Anchor to MethodsMethods
The <shopify-checkout> element exposes the following methods:
- open(): Presents checkout in the configured target. Has no effect when
targetisinline. - close(): Closes checkout and its overlay. Has no effect when
targetisinline. - focus(): Brings checkout to the foreground. Has no effect when
targetisinline.
Anchor to EventsEvents
Anchor to [object Object]checkout:start
checkout:startEmitted when checkout starts and is visible:
JavaScript
Anchor to [object Object]checkout:close
checkout:closeEmitted when the buyer closes checkout without completing payment:
JavaScript
Anchor to [object Object]checkout:complete
checkout:completeEmitted when checkout completes successfully, immediately after payment processing. The orderConfirmation property contains order details:
JavaScript
Anchor to [object Object]checkout:error
checkout:errorEmitted when errors occur during checkout:
JavaScript
Anchor to AuthenticationAuthentication
By default, anyone can use <shopify-checkout> without authentication. However, to embed checkout inline or apply configuration overrides, you need to authenticate using a JWT.
Never expose your client_id or client_secret in client-side code. Token generation must occur server-side.
Anchor to Generate a tokenGenerate a token
Create a secure server endpoint that generates tokens:
curl
Tokens have a 60-minute time-to-live (TTL) and can be cached for that duration.
Anchor to Use the tokenUse the token
Fetch the token from your backend and pass it to the component's auth attribute:
JavaScript
For details on configuring checkout features like branding, tipping, and analytics, refer to Authenticate checkouts.