---
title: "Button element"
summary: "Allows users a direct path to performing basic actions."
url: "https://docs.slack.dev/reference/block-kit/block-elements/button-element"
type: "reference"
subtype: "block-kit"
available_in_surfaces:
  - "Modals"
  - "Messages"
  - "Home tabs"
works_with_blocks:
  - "Section"
  - "Actions"
  - "Data table"
---

Source: https://docs.slack.dev/reference/block-kit/block-elements/button-element

# Button element

Example:

![Three buttons showing default, primary, and danger color styles](https://docs.slack.dev/img/guides/messaging/block_element_button_style.png)

## Fields {#fields}

Field

Type

Description

Required?

`type`

String

The type of element. In this case `type` is always `button`.

Required

`text`

Object

A [text object](https://docs.slack.dev/reference/block-kit/composition-objects/text-object.md) that defines the button's text. Can only be of `type: plain_text`. `text` may truncate with ~30 characters. Maximum length for the `text` in this field is 75 characters.

Required

`action_id`

String

An identifier for this action. You can use this when you receive an interaction payload to [identify the source of the action](https://docs.slack.dev/interactivity/handling-user-interaction.md#payloads). Should be unique among all other `action_id`s in the containing block. Maximum length is 255 characters.

Optional

`url`

String

A URL to load in the user's browser when the button is clicked. Maximum length is 3000 characters. If you're using `url`, you'll still receive an [interaction payload](https://docs.slack.dev/interactivity/handling-user-interaction.md#payloads) and will need to [send an acknowledgement response](https://docs.slack.dev/interactivity/handling-user-interaction.md#acknowledgment_response).

Optional

`value`

String

The value to send along with the [interaction payload](https://docs.slack.dev/interactivity/handling-user-interaction.md#payloads). Maximum length is 2000 characters.

Optional

`style`

String

Decorates buttons with alternative visual color schemes. Use this option with restraint.`primary` gives buttons a green outline and text, ideal for affirmation or confirmation actions. `primary` should only be used for one button within a set.`danger` gives buttons a red outline and text, and should be used when the action is destructive. Use `danger` even more sparingly than `primary`.If you don't include this field, the default button style will be used.

Optional

`confirm`

Object

A [confirm object](https://docs.slack.dev/reference/block-kit/composition-objects/confirmation-dialog-object.md) that defines an optional confirmation dialog after the button is clicked.

Optional

`accessibility_label`

String

A label for longer descriptive text about a button element. This label will be read out by screen readers _instead of_ the button [`text`](https://docs.slack.dev/reference/block-kit/composition-objects/text-object.md) object. Maximum length is 75 characters.

Optional

`agent_prompt`

String

A prompt sent to [Slackbot](https://docs.slack.dev/ai.md) when the button is clicked, if Slackbot AI is available to the user. Any app can set this field to a prompt of up to 4000 characters. Your app also receives a standard [interaction payload](https://docs.slack.dev/interactivity/handling-user-interaction.md#payloads).

Optional

`agent_prompt_display`

String

Short text shown instead of the full `agent_prompt` in the user's Slackbot message. The user can expand the message to read the full prompt. Requires `agent_prompt` and defaults to the button's [`text`](https://docs.slack.dev/reference/block-kit/composition-objects/text-object.md).

Optional

`visible_to_user_ids`

Array

An array of user IDs for which the button appears. If not provided, the button is visible to all users.

Optional

## Examples {#examples}

A regular interactive button:

*   JSON
*   Python Slack SDK
*   Node Slack SDK
*   Java Slack SDK

```json
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Click Me"
  },
  "value": "click_me_123",
  "action_id": "button"
}
```

```python
def example01() -> ButtonElement:
    """
    Allows users a direct path to performing basic actions.
    https://docs.slack.dev/reference/block-kit/block-elements/button-element/

    A regular interactive button.
    """
    element = ButtonElement(
        text=PlainTextObject(text="Click Me"),
        value="click_me_123",
        action_id="button",
    )
    return element
```

```javascript
export function example01() {
  /**
   * @type {import('@slack/types').Button}
   */
  const element = {
    type: "button",
    text: {
      type: "plain_text",
      text: "Click Me",
    },
    value: "click_me_123",
    action_id: "button",
  };
  return element;
}
```

```java
public static ButtonElement example01() {
    ButtonElement element = BlockElements.button(b -> b.text(BlockCompositions.plainText("Click Me"))
            .value("click_me_123")
            .actionId("button"));
    return element;
}
```

A button with a `primary` `style` attribute:

*   JSON
*   Python Slack SDK
*   Node Slack SDK
*   Java Slack SDK

```json
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Save"
  },
  "style": "primary",
  "value": "click_me_123",
  "action_id": "button"
}
```

```python
def example02() -> ButtonElement:
    """
    A button with a primary style attribute.
    """
    element = ButtonElement(
        text=PlainTextObject(text="Save"),
        style="primary",
        value="click_me_123",
        action_id="button",
    )
    return element
```

```javascript
export function example02() {
  /**
   * @type {import('@slack/types').Button}
   */
  const element = {
    type: "button",
    text: {
      type: "plain_text",
      text: "Save",
    },
    style: "primary",
    value: "click_me_123",
    action_id: "button",
  };
  return element;
}
```

```java
public static ButtonElement example02() {
    ButtonElement element = BlockElements.button(b -> b.text(BlockCompositions.plainText("Save"))
            .style("primary")
            .value("click_me_123")
            .actionId("button"));
    return element;
}
```

A link button:

*   JSON
*   Python Slack SDK
*   Node Slack SDK
*   Java Slack SDK

```json
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Link Button"
  },
  "url": "https://docs.slack.dev/block-kit"
}
```

```python
def example03() -> ButtonElement:
    """
    A link button.
    """
    element = ButtonElement(
        text=PlainTextObject(text="Link Button"),
        url="https://docs.slack.dev/block-kit",
    )
    return element
```

```javascript
export function example03() {
  /**
   * @type {import('@slack/types').Button}
   */
  const element = {
    type: "button",
    text: {
      type: "plain_text",
      text: "Link Button",
    },
    url: "https://docs.slack.dev/block-kit",
  };
  return element;
}
```

```java
public static ButtonElement example03() {
    ButtonElement element = BlockElements.button(
            b -> b.text(BlockCompositions.plainText("Link Button")).url("https://docs.slack.dev/block-kit"));
    return element;
}
```

A button that sends a prompt to [Slackbot](https://docs.slack.dev/ai.md):

```json
{
  "type": "button",
  "text": {
    "type": "plain_text",
    "text": "Summarize with Slackbot"
  },
  "action_id": "summarize_incident",
  "agent_prompt": "Summarize this incident and suggest next steps.",
  "agent_prompt_display": "Summarize this incident"
}
```

Handling agent prompt clicks

Your app receives a standard [`block_actions` payload](https://docs.slack.dev/reference/interaction-payloads/block_actions-payload.md) whether or not Slackbot AI is available to the user. Include an `action_id` to identify the button, and [acknowledge the payload](https://docs.slack.dev/interactivity/handling-user-interaction.md#acknowledgment_response) within 3 seconds.

If Slackbot AI is unavailable, clicking the button only sends the interaction payload.

The button element must be used inside either the [section](https://docs.slack.dev/reference/block-kit/blocks/section-block.md) or [actions](https://docs.slack.dev/reference/block-kit/blocks/actions-block.md) block, like this:

*   JSON
*   Python Slack SDK
*   Node Slack SDK
*   Java Slack SDK

```json
{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "This is a section block with a button."
            },
            "accessory": {
                "type": "button",
                "text": {
                    "type": "plain_text",
                    "text": "Click Me"
                },
                "value": "click_me_123",
                "action_id": "button"
            }
        },
        {
            "type": "actions",
            "block_id": "actionblock789",
            "elements": [
                {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "Primary Button"
                    },
                    "style": "primary",
                    "value": "click_me_456"
                },
                {
                    "type": "button",
                    "text": {
                        "type": "plain_text",
                        "text": "Link Button"
                    },
                    "url": "https://api.slack.com/block-kit"
                }
            ]
        }
    ]
}
```

[View in Block Kit Builder ](https://api.slack.com/tools/block-kit-builder?blocks=%5B%0A%09%7B%0A%09%09%22type%22%3A%20%22section%22%2C%0A%09%09%22text%22%3A%20%7B%0A%09%09%09%22type%22%3A%20%22mrkdwn%22%2C%0A%09%09%09%22text%22%3A%20%22This%20is%20a%20section%20block%20with%20a%20button.%22%0A%09%09%7D%2C%0A%09%09%22accessory%22%3A%20%7B%0A%09%09%09%22type%22%3A%20%22button%22%2C%0A%09%09%09%22text%22%3A%20%7B%0A%09%09%09%09%22type%22%3A%20%22plain_text%22%2C%0A%09%09%09%09%22text%22%3A%20%22Click%20Me%22%0A%09%09%09%7D%2C%0A%09%09%09%22value%22%3A%20%22click_me_123%22%2C%0A%09%09%09%22action_id%22%3A%20%22button%22%0A%09%09%7D%0A%09%7D%2C%0A%09%7B%0A%09%09%22type%22%3A%20%22actions%22%2C%0A%09%09%22block_id%22%3A%20%22actionblock789%22%2C%0A%09%09%22elements%22%3A%20%5B%0A%09%09%09%7B%0A%09%09%09%09%22type%22%3A%20%22button%22%2C%0A%09%09%09%09%22text%22%3A%20%7B%0A%09%09%09%09%09%22type%22%3A%20%22plain_text%22%2C%0A%09%09%09%09%09%22text%22%3A%20%22Primary%20Button%22%0A%09%09%09%09%7D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22style%22%3A%20%22primary%22%2C%0A%09%09%09%09%22value%22%3A%20%22click_me_456%22%0A%09%09%09%7D%2C%0A%09%09%09%7B%0A%09%09%09%09%22type%22%3A%20%22button%22%2C%0A%09%09%09%09%22text%22%3A%20%7B%0A%09%09%09%09%09%22type%22%3A%20%22plain_text%22%2C%0A%09%09%09%09%09%22text%22%3A%20%22Link%20Button%22%0A%09%09%09%09%7D%2C%0A%09%09%09%09%22url%22%3A%20%22https%3A%2F%2Fapi.slack.com%2Fblock-kit%22%0A%09%09%09%7D%0A%09%09%5D%0A%09%7D%0A%5D)

```python
def example05() -> list[Block]:
    """
    The button element used inside either the section or actions block.
    """
    blocks: list[Block] = [
        SectionBlock(
            text=MarkdownTextObject(text="This is a section block with a button."),
            accessory=ButtonElement(
                text=PlainTextObject(text="Click Me"),
                value="click_me_123",
                action_id="button",
            ),
        ),
        ActionsBlock(
            block_id="actionblock789",
            elements=[
                ButtonElement(
                    text=PlainTextObject(text="Primary Button"),
                    style="primary",
                    value="click_me_456",
                ),
                ButtonElement(
                    text=PlainTextObject(text="Link Button"),
                    url="https://api.slack.com/block-kit",
                ),
            ],
        ),
    ]
    return blocks
```

```javascript
export function example05() {
  /**
   * @type {(import('@slack/types').SectionBlock | import('@slack/types').ActionsBlock)[]}
   */
  const blocks = [
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: "This is a section block with a button.",
      },
      accessory: {
        type: "button",
        text: {
          type: "plain_text",
          text: "Click Me",
        },
        value: "click_me_123",
        action_id: "button",
      },
    },
    {
      type: "actions",
      block_id: "actionblock789",
      elements: [
        {
          type: "button",
          text: {
            type: "plain_text",
            text: "Primary Button",
          },
          style: "primary",
          value: "click_me_456",
        },
        {
          type: "button",
          text: {
            type: "plain_text",
            text: "Link Button",
          },
          url: "https://api.slack.com/block-kit",
        },
      ],
    },
  ];
  return blocks;
}
```

```java
public static List<LayoutBlock> example05() {
    List<LayoutBlock> blocks = List.of(
            Blocks.section(s -> s.text(BlockCompositions.markdownText("This is a section block with a button."))
                    .accessory(BlockElements.button(b -> b.text(BlockCompositions.plainText("Click Me"))
                            .value("click_me_123")
                            .actionId("button")))),
            Blocks.actions(a -> a.blockId("actionblock789")
                    .elements(List.of(
                            BlockElements.button(b -> b.text(BlockCompositions.plainText("Primary Button"))
                                    .style("primary")
                                    .value("click_me_456")),
                            BlockElements.button(b -> b.text(BlockCompositions.plainText("Link Button"))
                                    .url("https://api.slack.com/block-kit"))))));
    return blocks;
}
```
