# Button

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

## Contained Button

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MAgA8lkflyE8DVzEwHy%2F-MAgAK7U48o9cPcKc-GG%2Fimage.png?alt=media\&token=71e3725b-7593-4417-942a-84f4dbd69a54)

Contained buttons are high-emphasis, distinguished by their use of elevation and fill. They contain actions that are primary to your app.

```powershell
 New-UDButton -Variant 'contained' -Text 'Default'
```

## Outlined Button

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MAgA8lkflyE8DVzEwHy%2F-MAgAMoLq98PKn296aEA%2Fimage.png?alt=media\&token=43ff3641-34ce-439a-a732-f2dce78f0d28)

Outlined buttons are medium-emphasis buttons. They contain actions that are important, but aren’t the primary action in an app.

```powershell
New-UDButton -Variant 'outlined' -Text 'Default'
```

## Control Button Size

You can control the pixel size of a button based on pixel size by using the Style parameter

```powershell
New-UDButton -Id "Submit" -Text "Submit" -Style @{ Width = "150px"; Height = "100px" }
```

## Buttons with icons and label

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6jY7sXTmhiAIMGYw_m%2F-MAgA8lkflyE8DVzEwHy%2F-MAgAP-Ld7Vk5lws1K2h%2Fimage.png?alt=media\&token=21230d6c-63af-4241-a34e-abb7a0ab3087)

Sometimes you might want to have icons for certain button to enhance the UX of the application as we recognize logos more easily than plain text. For example, if you have a delete button you can label it with a dustbin icon.

```powershell
New-UDButton -Icon (New-UDIcon -Icon trash) -Text 'Delete'
```

## Buttons with event handlers

You can specify a script block to execute when the button is clicked

```powershell
New-UDButton -Text 'Message Box' -OnClick {
    Show-UDToast -Message 'Hello, world!'
}
```

## Loading Button

![](https://620394196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1JcgdTkn7CUOMdfsVjOO%2Fuploads%2Fn5X0DGJjofcRlHqjW4Bj%2Fimage.png?alt=media\&token=8fe5104e-f3d9-4c2e-9b50-c7484c8593ef)

Loading buttons will display a loading icon while an event handler is running. This is useful for longer running events.&#x20;

```powershell
New-UDButton -Text 'Message Box' -OnClick {
    Show-UDToast -Message 'Hello, world!'
    Start-Sleep 10
} -ShowLoading
```

## API

* [New-UDButton](https://github.com/ironmansoftware/universal-docs/blob/master/cmdlets/New-UDButton.txt)
