> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/powershell-commands/new-udbutton.md).

# New-UDButton

New-UDButton creates a clickable button component in PowerShell Universal that triggers an action, script, or link navigation.

### Synopsis

Buttons allow users to take actions, and make choices, with a single tap..

### Syntax

```powershell
New-UDButton [[-Text] <String>] [[-Icon] <Object>] [[-Variant] <String>] [[-IconAlignment] <String>] [[-FullWidth]] [[-OnClick] <Endpoint>] [[-Size] <String>] [[-Style] <Hashtable>] [[-Href] <String>] [-Target <String>] [-Id <String>] [-Color <String>] [-Disabled] [-ClassName <String>] [-ShowLoading] [-LoadingIndicator <Object>] [-LoadingPosition <String>] [<CommonParameters>]
```

### Description

Creates a new button. Buttons allow users to take actions, and make choices, with a single tap.

### Parameters

#### -Text

The text to show within the button.

```
Required?                    false
Position?                    1
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Icon

An icon to show within the button. Use New-UDIcon to create an icon for this parameter.

```
Required?                    false
Position?                    2
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Variant

The variant type for this button. Valid values are: "text", "outlined", "contained"

```
Required?                    false
Position?                    3
Default value                contained
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -IconAlignment

How to align the icon within the button. Valid values are: "left", "right"

```
Required?                    false
Position?                    4
Default value                left
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -FullWidth

Whether the button takes the full width of the it's container.

```
Required?                    false
Position?                    7
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -OnClick

The action to take when the button is clicked.

```
Required?                    false
Position?                    8
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Size

The size of the button. Valid values are: "small", "medium", "large"

```
Required?                    false
Position?                    9
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Style

Styles to apply to the button.

```
Required?                    false
Position?                    10
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Href

A URL that the user should be redirected to when clicking the button.

```
Required?                    false
Position?                    11
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Target

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Id

The ID of the component. It defaults to a random GUID.

```
Required?                    false
Position?                    named
Default value                ([Guid]::NewGuid()).ToString()
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Color

The color of the component. Valid values are: 'default', 'inherit', 'primary', 'secondary', 'info', 'warning', 'error', 'success'

```
Required?                    false
Position?                    named
Default value                primary
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -Disabled

Whether the button is disabled.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ClassName

The CSS Class to apply to the button.

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -ShowLoading

Displays a loading spinner while the OnClick event handler is running.

```
Required?                    false
Position?                    named
Default value                False
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -LoadingIndicator

A custom element to display instead of the built in spinner for -ShowLoading

```
Required?                    false
Position?                    named
Default value
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### -LoadingPosition

The position of the loading indicator. Valid values are: 'start', 'end', 'center'

```
Required?                    false
Position?                    named
Default value                center
Accept pipeline input?       false
Aliases
Accept wildcard characters?  false
```

#### Common parameters

This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see [about\_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

### Outputs

### Examples

#### Example 1: Basic buttons

```powershell
New-UDButton -Variant 'text' -Text 'Text' -Id 'button1'
New-UDButton -Variant 'contained' -Text 'Contained'  -Id 'button2'
New-UDButton -Variant 'outlined' -Text 'Outlined' -Id 'button3'
```

UDButton comes with three variants: text, contained, and outlined.

#### Example 2: Handling clicks

```powershell
New-UDButton -Text 'Click me' -OnClick {
  Show-UDToast -Message 'Hello, world!'
} -Id 'button4'
```

PowerShell that is executed when the button is clicked.

#### Example 3: Color

```powershell
New-UDButton -Text 'Secondary' -Color secondary -Id 'button5'
New-UDButton -Text 'Success' -Color success -Id 'button6'
New-UDButton -Text 'Error' -Color error -Id 'button7'
```

Adjust the button color with -Color

#### Example 4: Sizes

```powershell
New-UDButton -Variant 'text' -Text 'small' -Id 'button8' -Size small
New-UDButton -Variant 'text' -Text 'medium'  -Id 'button9' -Size medium
New-UDButton -Variant 'text' -Text 'large' -Id 'button10' -Size large
New-UDButton -Variant 'contained' -Text 'small' -Id 'button11'  -Size small
New-UDButton -Variant 'contained' -Text 'medium'  -Id 'button12'  -Size medium
New-UDButton -Variant 'contained' -Text 'large' -Id 'button13'  -Size large
New-UDButton -Variant 'outlined' -Text 'small' -Id 'button14'  -Size small
New-UDButton -Variant 'outlined' -Text 'medium'  -Id 'button15'  -Size medium
New-UDButton -Variant 'outlined' -Text 'large' -Id 'button16'  -Size large
```

For larger or smaller buttons, use the -Size parameter.

#### Example 5: Icon

```powershell
New-UDButton -Icon (New-UDIcon -Icon 'User') -Text 'View User' -Id 'button17'
```

Display an icon within the button

#### Example 6: Loading

```powershell
New-UDButton -OnClick { Start-Sleep 3 } -ShowLoading -Text 'Load Data' -Id 'button18'
```

Show a loading indicator while the OnClick event handler is running.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/powershell-commands/new-udbutton.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
