On September 25th, 2024, we released v2 of the Apps SDK. To learn what’s new and how to upgrade, see Migration FAQ and Migration guide.

addElementAtCursor

API reference for the addElementAtCursor method.

Add element to responsive documents, which slot things into a text stream

Parameters

elementElementAtCursor
REQUIRED

Elements targeting a cursor are a subset of the base Element

An element that renders image content.

typestring
REQUIRED

The type of element.

This must be "image".

altTextAltText | undefined
REQUIRED

A description of the image content.

Properties of altText
textstring
REQUIRED

The text content.

decorativeboolean | undefined
REQUIRED

Indicates where the alternative text should be displayed.

  • If true, the alternative text will only be displayed in the editor.
  • If false, the alternative text will be displayed in the editor and in view-only mode.
dataUrlstring
OPTIONAL

A data URL that contains the image data.

refImageRef
OPTIONAL

A unique identifier that points to an image asset in Canva's backend.

An element that renders video content.

typestring
REQUIRED

The type of element.

This must be "video".

refVideoRef
REQUIRED

A unique identifier that points to a video asset in Canva's backend.

altTextAltText | undefined
REQUIRED

A description of the video content.

Properties of altText
textstring
REQUIRED

The text content.

decorativeboolean | undefined
REQUIRED

Indicates where the alternative text should be displayed.

  • If true, the alternative text will only be displayed in the editor.
  • If false, the alternative text will be displayed in the editor and in view-only mode.

An element that renders rich media, such as a YouTube video.

typestring
REQUIRED

The type of element.

This must be "embed".

urlstring
REQUIRED

The URL of the rich media.

This URL must be supported by the Iframely API.

An element that renders text content.

typestring
REQUIRED

The type of element.

This must be "text".

childrenstring[]
REQUIRED

The text content.

Only the first element in this array is used.

fontSizenumber
OPTIONAL

The size of the text.

  • Minimum: 1
  • Maximum: 100

Default Value: 16

textAlignstring
OPTIONAL

The alignment of the text.

Default Value: "start"

The available options include:

  • "start"
  • "center"
  • "end"
  • "justify"
colorstring
OPTIONAL

The color of the text as a hex code.

The hex code must include all six characters and be prefixed with a # symbol.

Example

"#ff0099"
TS
fontRefFontRef
OPTIONAL

A unique identifier that points to a font asset in Canva's backend.

fontWeightFontWeight
OPTIONAL

The weight (thickness) of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "thin"
  • "extralight"
  • "light"
  • "medium"
  • "semibold"
  • "bold"
  • "ultrabold"
  • "heavy"
fontStylestring
OPTIONAL

The style of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "italic"
decorationstring
OPTIONAL

The decoration of the font.

Default Value: "none"

The available options include:

  • "none"
  • "underline"

An element that renders richtext content.

typestring
REQUIRED

The type of element.

This must be "richtext".

rangeRichtextRange
REQUIRED

The richtext content.

Properties of range
formatParagraphfunction
REQUIRED

Formats all of the paragraphs that overlap the given bounds.

  • The \n character indicates the end of a paragraph.
  • All paragraphs that overlap the provided bounds will be formatted in their entirety.

Parameters

boundsBounds
REQUIRED

The segment of the range on which to apply the formatting.

Properties of bounds
indexnumber
REQUIRED

The starting position of the segment.

This is zero-based, meaning the first character of the range is at index 0.

lengthnumber
REQUIRED

The number of characters in the segment, starting from the index.

formattingRichtextFormatting
REQUIRED

The formatting to apply to the paragraph(s).

Properties of formatting
colorstring
OPTIONAL

The color of the text as a hex code.

The hex code must include all six characters and be prefixed with a # symbol.

Example

"#ff0099"
TS
fontWeightFontWeight
OPTIONAL

The weight (thickness) of the font.

The available font weights depend on the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "thin"
  • "extralight"
  • "light"
  • "medium"
  • "semibold"
  • "bold"
  • "ultrabold"
  • "heavy"
fontStylestring
OPTIONAL

The style of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "italic"
decorationstring
OPTIONAL

The decoration of the text.

Default Value: "none"

The available options include:

  • "none"
  • "underline"
strikethroughstring
OPTIONAL

The strikethrough of the text.

Default Value: "none"

The available options include:

  • "none"
  • "strikethrough"
fontRefFontRef
OPTIONAL

A unique identifier that points to a font asset in Canva's backend.

fontSizenumber
OPTIONAL

The size of the text, in pixels.

  • In the Canva editor, this number is shown as points (pts), not pixels.
  • Minimum: 1
  • Maximum: 100
textAlignstring
OPTIONAL

The alignment of the text.

Default Value: "start"

The available options include:

  • "start"
  • "center"
  • "end"
  • "justify"
listLevelnumber
OPTIONAL

The list indentation level of the paragraph.

listMarkerstring
OPTIONAL

The appearance of list item markers.

This property only has an effect if listLevel is greater than 0.

Default Value: "none"

The available options include:

  • "none"
  • "disc"
  • "circle"
  • "square"
  • "decimal"
  • "lower-alpha"
  • "lower-roman"
  • "checked"
  • "unchecked"

Returns

void

formatTextfunction
REQUIRED

Formats a region of text with inline formatting properties.

Parameters

boundsBounds
REQUIRED

The segment of the range on which to apply the formatting.

Properties of bounds
indexnumber
REQUIRED

The starting position of the segment.

This is zero-based, meaning the first character of the range is at index 0.

lengthnumber
REQUIRED

The number of characters in the segment, starting from the index.

formattingInlineFormatting
REQUIRED

The formatting to apply to the text.

Properties of formatting
colorstring
OPTIONAL

The color of the text as a hex code.

The hex code must include all six characters and be prefixed with a # symbol.

Example

"#ff0099"
TS
fontWeightFontWeight
OPTIONAL

The weight (thickness) of the font.

The available font weights depend on the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "thin"
  • "extralight"
  • "light"
  • "medium"
  • "semibold"
  • "bold"
  • "ultrabold"
  • "heavy"
fontStylestring
OPTIONAL

The style of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "italic"
decorationstring
OPTIONAL

The decoration of the text.

Default Value: "none"

The available options include:

  • "none"
  • "underline"
strikethroughstring
OPTIONAL

The strikethrough of the text.

Default Value: "none"

The available options include:

  • "none"
  • "strikethrough"

Returns

void

appendTextfunction
REQUIRED

Appends the specified characters to the end of the range.

Parameters

charactersstring
REQUIRED

The characters to append to the richtext range.

formattingInlineFormatting
OPTIONAL

Options for formatting inline richtext.

Properties of formatting
colorstring
OPTIONAL

The color of the text as a hex code.

The hex code must include all six characters and be prefixed with a # symbol.

Example

"#ff0099"
TS
fontWeightFontWeight
OPTIONAL

The weight (thickness) of the font.

The available font weights depend on the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "thin"
  • "extralight"
  • "light"
  • "medium"
  • "semibold"
  • "bold"
  • "ultrabold"
  • "heavy"
fontStylestring
OPTIONAL

The style of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "italic"
decorationstring
OPTIONAL

The decoration of the text.

Default Value: "none"

The available options include:

  • "none"
  • "underline"
strikethroughstring
OPTIONAL

The strikethrough of the text.

Default Value: "none"

The available options include:

  • "none"
  • "strikethrough"

Returns

boundsBounds

A segment of a richtext range.

Properties of bounds
indexnumber

The starting position of the segment.

This is zero-based, meaning the first character of the range is at index 0.

lengthnumber

The number of characters in the segment, starting from the index.

replaceTextfunction
REQUIRED

Replaces a region of text with the specified characters.

Parameters

boundsBounds
REQUIRED

The segment of the range to replace.

Properties of bounds
indexnumber
REQUIRED

The starting position of the segment.

This is zero-based, meaning the first character of the range is at index 0.

lengthnumber
REQUIRED

The number of characters in the segment, starting from the index.

charactersstring
REQUIRED

The replacement characters.

formattingInlineFormatting
OPTIONAL

The formatting to apply to the replaced text.

Properties of formatting
colorstring
OPTIONAL

The color of the text as a hex code.

The hex code must include all six characters and be prefixed with a # symbol.

Example

"#ff0099"
TS
fontWeightFontWeight
OPTIONAL

The weight (thickness) of the font.

The available font weights depend on the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "thin"
  • "extralight"
  • "light"
  • "medium"
  • "semibold"
  • "bold"
  • "ultrabold"
  • "heavy"
fontStylestring
OPTIONAL

The style of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "italic"
decorationstring
OPTIONAL

The decoration of the text.

Default Value: "none"

The available options include:

  • "none"
  • "underline"
strikethroughstring
OPTIONAL

The strikethrough of the text.

Default Value: "none"

The available options include:

  • "none"
  • "strikethrough"

Returns

boundsBounds

The bounds of the replacement characters within the updated range.

Properties of bounds
indexnumber

The starting position of the segment.

This is zero-based, meaning the first character of the range is at index 0.

lengthnumber

The number of characters in the segment, starting from the index.

readPlaintextfunction
REQUIRED

Returns the current state of the richtext as plaintext.

Returns

string

readTextRegionsfunction
REQUIRED

Returns the current state of the richtext as one or more text regions. Each region is an object that contains the text content and its formatting.

Returns

textstring

The plaintext content of the region.

formattingPartial<RichtextFormatting>
OPTIONAL

The formatting of the region.

An element that renders a table.

typestring
REQUIRED

The type of element.

This must be "table".

rowsobject[]
REQUIRED

The rows of the table.

Properties of rows
cellsArray<Cell | null | undefined>
REQUIRED

The cells (columns) of the row.

Each row must have the same number of cells.

This should be either the following object, null, or undefined.

attributesCellAttributes
OPTIONAL

The attributes of the cell.

Properties of attributes
backgroundColorstring
OPTIONAL

The background color of the cell, as a hex code.

fontSizenumber
OPTIONAL

The size of the text.

  • Minimum: 1
  • Maximum: 100

Default Value: 16

textAlignstring
OPTIONAL

The alignment of the text.

Default Value: "start"

The available options include:

  • "start"
  • "center"
  • "end"
  • "justify"
colorstring
OPTIONAL

The color of the text as a hex code.

The hex code must include all six characters and be prefixed with a # symbol.

Example

"#ff0099"
TS
fontRefFontRef
OPTIONAL

A unique identifier that points to a font asset in Canva's backend.

fontWeightFontWeight
OPTIONAL

The weight (thickness) of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "thin"
  • "extralight"
  • "light"
  • "medium"
  • "semibold"
  • "bold"
  • "ultrabold"
  • "heavy"
fontStylestring
OPTIONAL

The style of the font.

Default Value: "normal"

The available options include:

  • "normal"
  • "italic"
decorationstring
OPTIONAL

The decoration of the font.

Default Value: "none"

The available options include:

  • "none"
  • "underline"
colSpannumber
OPTIONAL

The number of columns that the cell occupies.

rowSpannumber
OPTIONAL

The number of rows that the cell occupies.

typestring
REQUIRED

The available options include:

  • "empty"
  • "string"
valuestring
SOMETIMES REQUIRED

The plaintext content of the cell.

If an empty string is provided, the type will change to "empty".

Returns

Promise<void>