For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Resources
Get started
ReferenceGuidesExamplesChangelog
ReferenceGuidesExamplesChangelog
  • Designer API
    • Introduction
    • Getting Started
    • Webflow CLI
    • Error Handling
    • App Modes
  • Elements
    • Creating & Retrieving Elements
    • Element Properties & Methods
      • Attributes
        • Get Attributes
        • Get Resolved Attributes
        • Set Attributes
        • Set Attribute
        • Get Attribute Value
        • Get Resolved Attribute Value
        • Remove Attribute
      • Custom Attributes
      • Styles
      • Text Content
      • Display Name
    • Element Types & Methods
  • Styles
    • Managing Style Properties
    • Managing Variable Modes
  • Components
  • Variables & Collections
    • Variable Collections
    • Variables
    • Variable Modes
  • Assets
  • Pages & Folders
  • Utilities
    • User Events & Notifications
    • App Intents & Connections
  • Additional Resources
    • API Playground
    • FAQs
LogoLogo
Resources
Get started
On this page
  • element.setAttribute(name, value) / element.setAttribute(index, entry)
  • Syntax
  • Parameters
  • Returns
  • Example
  • Designer Ability
ElementsElement Properties & MethodsAttributes

Set attribute (Beta)

Was this page helpful?
Previous

Get attribute value (Beta)

Next
Built with

element.setAttribute(name, value) / element.setAttribute(index, entry)

Set a single attribute on an element.

This method supports two calling signatures:

  • Pass a name string and a value string to set an attribute by name. In this case you can bind the value by passing a BindingValue object, but you cannot bind the name.

  • Pass an index and an AttributeEntry object to update the attribute at that position in the attributes array, with full binding support on both name and value.

To replace the entire set of attributes at once, use element.setAttributes().

Beta

These methods are in public beta and may change with future releases.

Syntax

1element.setAttribute(name: string, value: string): Promise<AttributeEntry>
2element.setAttribute(index: number, entry: AttributeEntry): Promise<AttributeEntry>

Parameters

Signature 1 — set by name:

  • name : string — The name of the attribute to set.
  • value : string — The string value to assign to the attribute.

Signature 2 — set by index:

  • index : number — The zero-based position of the attribute in the element’s attributes array.
  • entry : AttributeEntry — An object specifying the name and value, each of which can be a string or a BindingValue.

Related types:

1type AttributeEntry = {
2 name: string | BindingValue
3 value: string | BindingValue
4}

Returns

Promise<AttributeEntry>

A Promise that resolves to the updated attribute entry.

Example

1const element = await webflow.getSelectedElement()
2
3if (element && element.attributes) {
4 // Set by name (string values only)
5 await element.setAttribute('data-label', 'primary')
6
7 // Set by index (supports bindings)
8 await element.setAttribute(0, { name: 'data-label', value: 'primary' })
9}

Try this example

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canDesignPrimaryMainCanvasDesign