addNativeElement
Adds a native element to a user's design.
To learn more, see:
- Creating images
- Creating shapes
- Creating tables
- Creating text
- Creating videos
- Embedding rich media
- Grouping elements
Usage
import { addNativeElement } from "@canva/design";await addNativeElement({type: "TEXT",children: ["Hello world"],});
Permissions
Before an app that uses this method can be submitted for review, the canva:design:content:write
permission must be enabled via the Developer Portal. To learn more, see Configuring permissions.
Rate limit
This method has a rate limit of 20 requests every 10 seconds.
Parameters
The expected parameters depend on the type of element being added to the design:
To add an embed element to the user's design, set the following parameters:
type
string
The type of element. For embed elements, this must be "EMBED"
.
url
string
The URL of the embeddable media.
This URL must be supported by Iframely. To learn more, see What URLs to send to Iframely(opens in a new tab or window).
width
number
The width of the element, in pixels.
If height
is a number, this can be set to "auto"
.
height
number
The height of the element, in pixels.
If width
is a number, this can be set to "auto"
.
top
number
The distance from the top edge of the container, in pixels.
The container could be a page, a group, or an app element.
left
number
The distance from the left edge of the container, in pixels.
The container could be a page, a group, or an app element.
rotation
number
The rotation of the element, in degrees. This must be a number between -180
and 180
.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the width
, height
, top
, and left
properties.
To add a group element to the user's design, set the following parameters:
type
string
The type of element. For group elements, this must be "GROUP"
.
children
array
The elements to include in the group.
Each element must have the following properties:
width
height
top
left
Group elements can't contain group elements.
width
number
The width of the element, in pixels.
If height
is a number, this can be set to "auto"
.
height
number
The height of the element, in pixels.
If width
is a number, this can be set to "auto"
.
top
number
The distance from the top edge of the page, in pixels.
left
number
The distance from the left edge of the page, in pixels.
rotation
number
The rotation of the element, in degrees. This must be a number between -180
and 180
.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the width
, height
, top
, and left
properties.
To add an image element to the user's design, set the following parameters:
type
string
The type of element. For image elements, this must be "IMAGE"
.
ref
string
A unique identifier that points to an image in Canva's backend.
width
number
The width of the element, in pixels.
If height
is a number, this can be set to "auto"
.
height
number
The height of the element, in pixels.
If width
is a number, this can be set to "auto"
.
top
number
The distance from the top edge of the container, in pixels.
The container could be a page, a group, or an app element.
left
number
The distance from the left edge of the container, in pixels.
The container could be a page, a group, or an app element.
rotation
number
The rotation of the element, in degrees. This must be a number between -180
and 180
.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the width
, height
, top
, and left
properties.
To add a plaintext element to the user's design, set the following parameters:
type
string
The type of element. For plaintext elements, this must be "TEXT"
.
children
array
The text to add to the user's design, provided as an array of strings.
For the time being, the array is only allowed to have one item. In the future, each element in the array will be rendered as a separate line of text.
fontSize
string
The size of the text, in pixels. This must be an integer between 1 and 1000 (inclusive). The default value is 16
.
In the user interface, the font size is displayed as points (pts), not pixels. This means the font size defined here will be different from what's shown to the user.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the top
, left
, and width
properties.
textAlign
string
The alignment of the text.
The available options include:
"start"
"center"
"end"
The default value is "start"
.
color
string
The color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol — for example, "#ff0099"
.
The default value is "#000000"
.
fontRef
string
A unique identifier that references a font in Canva's backend. To learn more, see Creating text.
fontWeight
string
The weight of the font.
The available options include:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
The default value is "normal"
.
fontStyle
string
The style of the font.
The available options include:
"normal"
"italic"
The default value is "normal"
.
decoration
string
The decoration of the font.
The available options include:
"none"
"underline"
The default value is "none"
.
width
number
The width of the element, in pixels.
top
number
The distance from the top edge of the container, in pixels.
The container could be a page, a group, or an app element.
left
number
The distance from the left edge of the container, in pixels.
The container could be a page, a group, or an app element.
rotation
number
The rotation of the element, in degrees. This must be a number between -180
and 180
.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the top
, left
, and width
properties.
To add a richtext element to the user's design, set the following parameters:
type
string
The type of element. For richtext elements, this must be "RICHTEXT"
.
range
object
A range of formatted text created with the createRichtextRange
method.
width
number
The width of the element, in pixels.
top
number
The distance from the top edge of the container, in pixels.
The container could be a page, a group, or an app element.
left
number
The distance from the left edge of the container, in pixels.
The container could be a page, a group, or an app element.
rotation
number
The rotation of the element, in degrees. This must be a number between -180
and 180
.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the top
, left
, and width
properties.
To add a shape element to the user's design, set the following parameters:
type
string
The type of element. For shape elements, this must be "SHAPE"
.
paths
array
The paths that define the shape of the element.
There must be between 1 and 30 paths. The maximum combined size of all paths must not exceed 2kb. The maximum number of unique fill colors across all paths is 6.
paths[0].d
string
The shape of the path.
This accepts the same value as the d
attribute of the SVG <path>
element, with some limitations:
- The path must start with an
M
command - The path must not have more than one
M
command - The path must not use the
Q
command - The path must be closed, either with a
Z
command at the end or by having the last coordinate match the first coordinate
paths[0].fill
object
The appearance of the path's interior.
Only one type of fill — color, image, or video — can be set.
paths[0].fill.dropTarget
boolean
If true
, users can drop images or videos onto the path to use them as a fill.
Although the dropTarget
property is optional, we encourage you to set it to prevent breaking in potential future API changes. For image fills dropTarget
can be false
, but for video fills it must be true
.
paths[0].fill.color
string
The color of the fill as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol — for example, "#ff0099"
.
paths[0].fill.asset
object
If set, a user can fill a shape with an asset.
paths[0].fill.asset.type
string
The type of asset to fill the shape.
Valid values include:
IMAGE
VIDEO
paths[0].fill.asset.ref
string
The unique identifier of the paths[0].fill.asset.type
asset to fill the shape.
paths[0].stroke
object
The outline of the path.
paths[0].stroke.weight
number
The weight of the stroke. This must be an integer between 0 and 100.
paths[0].stroke.color
string
The color of the stroke as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol — for example, "#ff0099"
.
paths[0].stroke.strokeAlign
string
The alignment of the stroke. The only supported value is "inset"
.
viewBox
object
The scale and cropping of a shape. This is similar to the viewBox
attribute of a HTMLSVGElement
.
viewBox.width
number
The width of the view box, in pixels.
viewBox.height
number
The height of the view box, in pixels.
viewBox.top
number
The distance of the shape from the top edge of the element, in pixels.
viewBox.left
number
The distance of the shape from the left edge of the element, in pixels.
width
number
The width of the element, in pixels.
If height
is a number, this can be set to "auto"
.
height
number
The height of the element, in pixels.
If width
is a number, this can be set to "auto"
.
top
number
The distance from the top edge of the container, in pixels.
The container could be a page, a group, or an app element.
left
number
The distance from the left edge of the container, in pixels.
The container could be a page, a group, or an app element.
rotation
number
The rotation of the element, in degrees. This must be a number between -180
and 180
.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the width
, height
, top
, and left
properties.
This API is in preview mode and may experience breaking changes. Apps that use this API will not pass the review process and can't be made available on the Apps Marketplace.
To add a table element to the user's design, set the following parameters:
type
string
The type of element. For table elements, this must be "TABLE"
.
rows
array
The rows that make up a table. A table must have at least one row, one column, and no more than 225 cells.
rows[0]
object
An individual row within a table.
rows[0].cells
array
The cells that make up a row.
rows[0].cells[0]
object
An individual cell within a row.
rows[0].cells[0].text
object
A text element to set as the contents of the cell.
rows[0].cells[0].text.type
string
The type of element. For text elements, this must be "TEXT"
.
rows[0].cells[0].text.children
array
The text to add to the user's design, provided as an array of strings.
For the time being, the array is only allowed to have one item. In the future, each element in the array will be rendered as a separate line of text.
rows[0].cells[0].fill
object
The background of the cell.
rows[0].cells[0].fill.color
string
The background color of the cell as a hex code. The hex code must include all six characters and be prefixed with a #
symbol — for example, "#ff0099"
.
rows[0].cells[0].colSpan
number
The number of columns that the cell occupies.
rows[0].cells[0].rowSpan
number
The number of rows that the cell occupies.
To add a video element to the user's design, set the following parameters:
type
string
The type of element. For video elements, this must be "VIDEO"
.
ref
string
A unique identifier that points to a video in Canva's backend.
width
number
The width of the element, in pixels.
If height
is a number, this can be set to "auto"
.
height
number
The height of the element, in pixels.
If width
is a number, this can be set to "auto"
.
top
number
The distance from the top edge of the page, in pixels.
The container could be a page or a group.
left
number
The distance from the left edge of the container, in pixels.
The container could be a page or a group.
rotation
number
The rotation of the element, in degrees. This must be a number between -180
and 180
.
This property doesn't have an effect unless you also set position properties for the element. To set a position, you must provide the width
, height
, top
, and left
properties.
Returns
Promise<void>