Getting started

Add the Canva Button to a website with the JavaScript API.

Canva provides a JavaScript API for adding the Canva Button to websites. You can use this API to launch the Canva editor from your website.

Here's how it works:

Your website opens the Canva editor in a modal. The user then creates or edits a design. When the user clicks the Publish button, your website downloads the user's design as an image file.

Broadly speaking, the main benefit of the JavaScript API is that it's more flexible than the HTML API. This means it's easier to tightly integrate the Canva Button with your website.

This tutorial series explains how to add the Canva Button to a website with the JavaScript API.

This tutorial assumes you have an API key to use the Canva Button. If you don't have one, sign up for an API key.

Canva distributes an SDK for embedding the SDK in websites. The same SDK is used for the JavaScript and HTML APIs. To embed the SDK, use the HTML or JavaScript syntax. The syntax is different, but the end result is the same.

<script src="https://sdk.canva.com/designbutton/v2/api.js"></script>
markup
((document, url) => {
const script = document.createElement("script");
script.src = url;
script.onload = () => {
// API initialization
};
document.body.appendChild(script);
})(document, "https://sdk.canva.com/designbutton/v2/api.js");
javascript

To initialize the JavaScript API, call the initialize method:

(async () => {
if (!window.Canva || !window.Canva.DesignButton) {
return;
}
const api = await window.Canva.DesignButton.initialize({
apiKey: "API KEY GOES HERE",
});
})();
javascript

Replace API KEY GOES HERE with your Canva Button API key. This API key is not a sensitive value.

The initialize method returns an object with two methods:

You can use these methods to create or open an existing design in the Canva editor.

Unlike the HTML API, Canva doesn't provide pre-made buttons for the JavaScript API. You have complete control over how the button looks and how it integrates with your website.

For advice on how to style the button, refer to Customization.

This example demonstrates how to set up a Canva Button that allows users to create a new design in the Canva editor. To learn more about creating designs, refer to Creating designs.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Canva Button</title>
<script src="https://sdk.canva.com/designbutton/v2/api.js"></script>
</head>
<body>
<button>Create a new design</button>
<script type="text/javascript">
(async () => {
if (!window.Canva || !window.Canva.DesignButton) {
return;
}
const api = await window.Canva.DesignButton.initialize({
apiKey: "API KEY GOES HERE",
});
const button = document.querySelector("button");
button.onclick = () => {
api.createDesign({
design: {
type: "Poster",
},
});
};
})();
</script>
</body>
</html>
markup