Website guides

How to Add a Buy Button to a Website: 4 Methods, With the Code

By the Chargedeck team 8 min read

The short answer

To add a buy button to a website you need two things: a checkout page that takes the payment, and a way to open it from your site. There are four ways to do the second part: a plain link, an overlay button snippet, an inline embedded checkout, or a web component. The right one depends on what your site lets you paste in.

Below is the actual code for each method, what each one asks of your site, and a table of which website builders support which.

Pick a method by what your site lets you paste

MethodWhat the buyer seesWhat your site must allow
1. Plain linkYour checkout opens as a full pageA button or text link with a URL field. Nothing else
2. Overlay buttonThe checkout opens on top of your pageHTML and a script tag that run in the page itself
3. Inline checkoutThe checkout sits inside your pageAn HTML or embed block, even one that shows code in a frame
4. Web componentA button that opens the overlayA script tag and support for custom elements

The quick rule: if you can only set a URL, use the link. If you can paste HTML that runs in the page, use the overlay. If your builder puts custom code inside a frame, use the inline checkout. If you build with components, use the web component.

The examples use Chargedeck, a checkout page builder that runs on your own Stripe, PayPal or Square account. In each one, swap your-page-slug for the last part of your checkout link, or copy finished code from the embed code generator.

Every hosted checkout page has a web address. Put that address on a button and you have a buy button. In HTML it is an ordinary link:

<a href="https://chargedeck.app/p/your-page-slug">Buy now</a>

In a website builder you never type that tag. You select a button, open its link setting and paste the address. The buyer taps it, lands on your branded checkout and pays. A hosted checkout link from any other provider works the same way.

This works on every builder and every plan, and the same address works in an email, a bio or a direct message, which is why it is also called a payment link. Choose it when you cannot add code, or when you want the simplest thing that works. Our guide to payment links, checkout pages and invoices explains how the three differ.

Method 2: an HTML buy now button that opens an overlay

An overlay keeps the buyer on your site: the checkout opens on top of the page they were reading. You need two lines. The first is the button. The second loads the script that makes it work.

<a data-chargedeck="your-page-slug">Buy now</a>

<script src="https://chargedeck.app/embed.js" defer></script>

  1. Paste both lines where the button should appear.
  2. Replace your-page-slug with your own.
  3. For more buttons on the same page, repeat only the first line, each with its own slug. The script is needed once per page, so many sites put it in the footer.
  4. Publish, then click the button on the live page to test it.

Two details worth knowing. The defer attribute tells the browser to run the script after the page has been read, so it does not hold up your content. And if you have already styled your own button, add data-cdk-raw="1" to the link to keep your styling as it is.

Worked example: one product on a small site

Say you sell a $38 sewing pattern as a PDF from a three-page site. You build one checkout page, add the delivery link buyers get after paying, and paste those two lines under the product photo. Now the cost, for a month with 20 sales:

  • Sales: 20 x $38 = $760.
  • Card fees, using Stripe's standard US online rate of 2.9% + 30 cents as of November 2026: 2.9% of $760 is $22.04, plus 20 x $0.30 = $6.00, so $28.04. This goes to your processor, not to Chargedeck.
  • Chargedeck Starter: $9.99 for the month. It is a flat fee and takes 0% of your sales.
  • Total cost: $38.03, which leaves you $721.97.

This is arithmetic on made-up sales, not a forecast. The useful part is the shape: the card fee grows with sales, and the checkout fee stays at $9.99 whether you sell 20 patterns or 200.

A whole shelf, not one button

The same script can show a mini shop: your products as a grid, with a basket so buyers can add several items and pay once. Replace the button line with this one and use your storefront handle:

<div data-chargedeck-shop="your-handle"></div>

Method 3: embed the checkout inside the page

The inline method places the checkout itself in your page, inside a frame. It needs no script:

<iframe src="https://chargedeck.app/p/your-page-slug?embed=1" title="Secure checkout" allow="payment *" style="width:100%;max-width:460px;height:760px;border:0"></iframe>

There are two reasons to pick it. The first is design: on a sales page you may want the form visible without a click. The second is technical. Some builders, such as Google Sites and GoDaddy, show any custom code inside a frame of their own. An overlay button cannot open from inside that frame, so the inline checkout is the one to use there. Give it a space about 460 pixels wide and 760 pixels tall.

Method 4: the web component and the JavaScript call

If your site is built from components, or your builder accepts custom elements, there is a ready-made button element. Load its script, then use the tag wherever you want a button:

<script src="https://chargedeck.app/chargedeck-button.js" defer></script>

<chargedeck-button slug="your-page-slug" label="Buy now"></chargedeck-button>

Developers who want to open the checkout from their own code, for example at the end of a quiz or after a form, can call it from JavaScript once the Chargedeck script has loaded:

Chargedeck.buy('your-page-slug')

To run something after the buyer has paid, such as showing a thank-you message, set a function:

Chargedeck.onSuccess = function (order) { }

If your site has its own cart and you need to charge an exact total, the REST API creates a hosted checkout for that amount and confirms the order with a signed webhook.

Which method your website builder supports

Every builder below has a button you can link (Method 1). The table shows where that button lives and what the code route looks like.

BuilderNo-code routeCode routeFull steps
WordPressButtons block with the linkCustom HTML block for the overlay button, or the free plugin's block and shortcodeWordPress guide
WixButton with a web address linkThe Chargedeck app for an overlay button, or Embed HTML for the inline checkoutWix guide
SquarespaceButton blockCode Block for the overlay button. Squarespace limits JavaScript in Code Blocks to some plansSquarespace guide
WebflowAny button or link blockA data-chargedeck custom attribute plus the script in Footer code. Custom code needs a paid site plan or workspaceWebflow guide
GoDaddyButton linked to a website URLHTML section holding the inline checkoutGoDaddy guide
FramerButton or text linkEmbed set to HTML, holding the inline checkoutFramer guide
CarrdButtons elementEmbed element set to Code for the overlay button, on Carrd's paid plansCarrd guide
GhostButton cardHTML card with the overlay buttonGhost guide
Google SitesInsert, ButtonEmbed code holding the inline checkoutGoogle Sites guide

Writing your own HTML, or using a builder that is not listed? All four methods are open to you, and the HTML checkout guide keeps every snippet on one page.

Why card details never touch your page

In all four methods, the form where the buyer types their card number is not part of your website. With a link it is a separate page. With the overlay, the inline embed and the web component, the checkout runs in a frame served by Chargedeck, and the card details go from that frame to your payment processor. Your page holds a button or a frame and nothing more. It does not see, handle or store card numbers.

That is why a buy button suits even a simple static site: there is no payment code of your own to write or keep up to date. The money takes a direct path too. It goes straight into your own Stripe, PayPal or Square account, and that processor pays you out on its normal schedule. Chargedeck never holds it.

When a buy button is the wrong tool

A button and a checkout page cover one product, a service or a small range. Look elsewhere in these cases:

  • A large catalog. If you need shipping rules, stock across many products and a full cart, use a store platform such as WooCommerce or your builder's own commerce plan.
  • Subscriptions. Chargedeck does not do subscriptions or recurring billing.
  • Tax handled for you. Chargedeck does not calculate sales tax or VAT, so set tax-inclusive prices or handle it in your accounting. If you want a platform to be the legal seller and deal with sales tax, a merchant of record such as Gumroad or Lemon Squeezy does that job.
  • Discount codes. Chargedeck does not have them.
FAQ

Common questions

Can I add a buy button without knowing how to code?

Yes. Copy the link to your checkout page and paste it into the URL field of any button in your website builder. That is Method 1, and it needs no code at all.

Do I need my website builder's online store plan to use a buy button?

No. The sale happens on the checkout page, so your site only needs a button with a link or a place to paste a snippet. Some builders limit custom code to certain plans, and in that case the plain link still works.

Can I put several buy buttons on one page?

Yes. Repeat the button line once per product, each with its own page slug, and include the script once.

What is the difference between an overlay and an inline checkout?

An overlay opens on top of your page when the buyer clicks a button. An inline checkout is always visible inside the page, in a frame, and is the one to use in builders that show custom code in a frame of their own.

Keep reading

Related guides

Get the code for your buy button

Build a checkout page, open the embed generator and paste the snippet into your site. Free for 7 days, no card.

See pricing