The Image element represents an image in the Webflow Designer.

Properties

PropertyDescriptionTypeExample
idUnique identifier for the element composed of two identifiers, the component and the element.object{component: "64c813...", element: "5edf8e59-71f9..."}
typeSpecifies the type of the element.string”Image”
childrenIndicates whether the element can contain child elements.booleanfalse
customAttributesIndicates whether the element can have custom attributes.booleantrue
stylesIndicates whether the element can contain styles.booleantrue
textContentIndicates whether the element can contain text contentbooleanfalse
appConnectionsIndcates whether the element supports App Connectionsbooleantrue

Methods

element.getAsset()

Retrieve an asset from an Image element.

Syntax

1element.getAsset(): Promise<Asset | null>

Returns

Promise<Asset> | null

A Promise that resolves to an Asset. If an element does not have an aseet, the method will return null

Example

1// Get Selected Element
2const el = await webflow.getSelectedElement()
3
4// Check if element can have children
5if (el?.children) {
6 // Create a new Image Element using Element Presets
7 const imgEl = await el.append(webflow.elementPresets.Image)
8
9 // Check element type
10 if (imgEl.type === 'Image') {
11 // Get asset from Image element
12 const myAsset = await imgEl.getAsset()
13 console.log(myAsset)
14 }
15}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessAssetsanyanyanyany


element.setAsset()

Add an asset to an Image element.

Syntax

1element.setAsset(asset: Asset | null): Promise<null>

Parameters

  • Asset: Asset - The asset to be inserted into the Image Element. Can be retrieved with the method webflow.getAssetById

Returns

Promisenull

A Promise that resolves to null

Example

1// Get Selected Element
2const el = await webflow.getSelectedElement()
3
4// Check if element can have children
5if (el?.children) {
6 // Create a new Image Element using Element Presets
7 const imgEl = await el.append(webflow.elementPresets.Image)
8
9 // Get asset by ID
10 const asset = await webflow.getAssetById(assetId)
11
12 // Check element type
13 if (imgEl.type === 'Image') {
14 // Set asset as the "src" of the Image Element
15 await imgEl.setAsset(asset)
16 }
17}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canModifyImageElementanymaincanvasany

element.getAltText()

Retrieve the Alt Text for an Image element on the canvas. If the Image element does not have alt text, the API will retrieve the alt text from the associated Asset.

Syntax

1element.getAltText(): Promise<string>

Returns

Promise<String>

A Promise that resolves to an the string of Alt Text.

Example

1// Get Selected Element
2const el = await webflow.getSelectedElement()
3if (el?.type === 'Image') {
4 // Get alt text
5 const alt = await el.getAltText()
6 console.log(alt)
7} else {
8 console.error('Please select an image element')
9 await webflow.notify({
10 type: 'Error',
11 message: 'Please select an Image Element',
12 })
13}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessAssetsanyanyanyany

element.setAltText()

Set the Alt Text for an Image element on the canvas.

Syntax

1element.setAltText(altText: string | null): Promise<null>

Parameters

altText: string - The Alternate Text for an image

Returns

Promisenull

A Promise that resolves to null

Example

1// Get Selected Element
2const el = await webflow.getSelectedElement()
3
4// Check element type
5if (el?.type === 'Image') {
6 // Set alt text. If a null is passed, the API will set the alt text as "decorative"
7 await el.setAltText(altText)
8 // Get alt text
9 const alt = await el.getAltText()
10 console.log(alt) // true
11} else {
12 console.error('Please select an Image Element')
13 await webflow.notify({
14 type: 'Error',
15 message: 'Please select an Image Element',
16 })
17}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canModifyImageElementanymaincanvasany