> This page is for Designer API.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.webflow.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.webflow.com/_mcp/server.

# Set attribute (Beta)

> Set a single attribute on an element by name or index.

## `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()`](/designer/reference/attributes/setAttributes).

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

### Syntax

```typescript
element.setAttribute(name: string, value: string): Promise<AttributeEntry>
element.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:

```typescript
type AttributeEntry = {
  name: string | BindingValue
  value: string | BindingValue
}
```

### Returns

**Promise\<*AttributeEntry*>**

A Promise that resolves to the updated attribute entry.

### Example

```typescript
const element = await webflow.getSelectedElement()

if (element && element.attributes) {
  // Set by name (string values only)
  await element.setAttribute('data-label', 'primary')

  // Set by index (supports bindings)
  await element.setAttribute(0, { name: 'data-label', value: 'primary' })
}
```

[Try this example](https://webflow.com/oauth/authorize?response_type=code\&client_id=19511de1ec410f9228d8dcbc9420e67916dea80d86d18f0c9a533eb475ea0f62)

### Designer Ability

| Designer Ability | Locale  | Branch | Workflow | Sitemode |
| :--------------- | :------ | :----- | :------- | :------- |
| **canDesign**    | Primary | Main   | Canvas   | Design   |