---
title: WidgetStack
description: Stack element shown in widget.
---

Stack element shown in widget.

Shows a stack in the widget.

## Properties

### backgroundColor

Background color of the widget.

```typescript
backgroundColor: Color
```

### backgroundGradient

Background gradient.

```typescript
backgroundGradient: LinearGradient
```

### backgroundImage

Background image.

```typescript
backgroundImage: Image
```

### borderColor

Border color.

```typescript
borderColor: Color
```

Color of the border around the stack. Defaults to black.

### borderWidth

Border width.

```typescript
borderWidth: number
```

Width of the border around the stack. Defaults to 0.

### cornerRadius

Radius of the corners.

```typescript
cornerRadius: number
```

Radius of the rounded corners. Defaults to 0.

### size

Size of the stack.

```typescript
size: Size
```

Specifies the size of the stack when shown in a widget. When a dimension is set to zero or less, the widget will automatically decide a length for that dimension. Both dimensions default to 0.

### spacing

Spacing between elements.

```typescript
spacing: number
```

Specifies the spacing between elements in the stack. You can also use the `addSpacer()` function on the widget to add spacing between elements. Defaults to 0.

### url

URL to open.

```typescript
url: string
```

The URL will be opened when the text is tapped. This is only supported in medium and large widgets. Small widgets can only have a single tap target, which is specified by the `url` on the widget.

## Methods

<span id="-adddate" class="api-anchor"></span>

### addDate(date)

Add date to the widget.

```typescript
addDate(date: Date): WidgetDate
```

Adds a date element to the widget. Use the properties on the returned element to style the date.

#### Parameters

**`date` `Date`**



#### Return value

**`WidgetDate`**

Date element.

<span id="-addimage" class="api-anchor"></span>

### addImage(image)

Add image to the stack.

```typescript
addImage(image: Image): WidgetImage
```

Adds an image element to the stack. Use the properties on the returned element to style the image.

#### Parameters

**`image` `Image`**



#### Return value

**`WidgetImage`**

Image element.

<span id="-addspacer" class="api-anchor"></span>

### addSpacer(length)

Add spacer.

```typescript
addSpacer(length: number): WidgetSpacer
```

Adds a spacer to the stack. This can be used to offset the content horizontally in the stack.

#### Parameters

**`length` `number`**

Length of the spacer. Pass null to create a spacer with a flexible length.

#### Return value

**`WidgetSpacer`**

Spacer element.

<span id="-addstack" class="api-anchor"></span>

### addStack()

Add stack.

```typescript
addStack(): WidgetStack
```

Adds a stack to the widget. Stacks layout elements horizontally by default.

#### Return value

**`WidgetStack`**

Stack element.

<span id="-addprogress" class="api-anchor"></span>

### addProgress(value, options)

Add a progress indicator to the widget.

```typescript
addProgress(value: number, options: dictionary?): WidgetStack
```

Adds a progress indicator with a value from 0 to 100. Values outside that range are clamped. Use the returned stack to size the indicator or add content centered on top of it.

#### Parameters

**`value` `number`**

Progress from 0 to 100.

**`options` `dictionary?`**

Optional dictionary with `style` ("circular" or "linear"), `progressColor`, `trackColor`, and `thickness` in points. The default style is circular. Thickness sets the ring stroke or the initial height of a linear bar.

#### Return value

**`WidgetStack`**

A stack sized to 40 by 40 points for a ring or 120 points wide for a bar.

<span id="-addbutton" class="api-anchor"></span>

### addButton(title, options)

Add a button that runs a widget action.

```typescript
addButton(title: string, options: {[key: string]: string})
```

Tapping the button runs the configured script in the widget and reloads the widget. Read `args.widgetAction.id` to handle the action. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.

#### Parameters

**`title` `string`**

The label shown on the control.

**`options` `{[key: string]: string}`**

A dictionary with a non-empty string `id`.

<span id="-addrefreshbutton" class="api-anchor"></span>

### addRefreshButton(title)

Add a button that refreshes the widget.

```typescript
addRefreshButton(title: string)
```

Tapping the button reloads the widget and runs its normal render. The render receives no widget action. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.

#### Parameters

**`title` `string`**

The label shown on the control.

<span id="-addtoggle" class="api-anchor"></span>

### addToggle(title, isOn, options)

Add a toggle that runs a widget action.

```typescript
addToggle(title: string, isOn: boolean, options: {[key: string]: string})
```

Read `args.widgetAction.isOn` to get the requested state. Save the state before the script finishes and read it when rendering the widget again. Interactive controls require iOS or iPadOS 17 or later and a widget family that supports them. Interactive controls take precedence over a URL on the containing stack.

#### Parameters

**`title` `string`**

The label shown on the control.

**`isOn` `boolean`**

The current saved state of the toggle.

**`options` `{[key: string]: string}`**

A dictionary with a non-empty string `id`.

<span id="-setaction" class="api-anchor"></span>

### setAction(title, options)

Run a widget action when the stack is tapped.

```typescript
setAction(title: string?, options: dictionary?)
```

Uses the stack contents as the action’s appearance on iOS or iPadOS 17 or later. Controls inside the stack take precedence over a stack action.

#### Parameters

**`title` `string?`**

Accessibility label, or null to clear the action.

**`options` `dictionary?`**

A dictionary with a non-empty string `id`.

<span id="-addtext" class="api-anchor"></span>

### addText(text)

Add text to the stack.

```typescript
addText(text: string): WidgetText
```

Adds a text element to the stack. Use the properties on the returned element to style the text.

#### Parameters

**`text` `string`**



#### Return value

**`WidgetText`**

Text element.

<span id="-bottomaligncontent" class="api-anchor"></span>

### bottomAlignContent()

Bottom aligns the content.

```typescript
bottomAlignContent()
```

Specifies that content should be bottom aligned.

<span id="-centeraligncontent" class="api-anchor"></span>

### centerAlignContent()

Center aligns the content.

```typescript
centerAlignContent()
```

Specifies that content should be center aligned.

<span id="-layouthorizontally" class="api-anchor"></span>

### layoutHorizontally()

Layout elements horizontally.

```typescript
layoutHorizontally()
```

Specifies that the stack should layout elements horizontally. This is the default.

<span id="-layoutvertically" class="api-anchor"></span>

### layoutVertically()

Layout elements vertically.

```typescript
layoutVertically()
```

Specifies that the stack should layout elements vertically.

<span id="-setpadding" class="api-anchor"></span>

### setPadding(top, leading, bottom, trailing)

Set padding.

```typescript
setPadding(top: number, leading: number, bottom: number, trailing: number)
```

Sets the padding on each side of the stack.

#### Parameters

**`top` `number`**

Padding on the top edge.

**`leading` `number`**

Padding on the leading edge.

**`bottom` `number`**

Padding on the bottom edge.

**`trailing` `number`**

Padding on the trailing edge.

<span id="-topaligncontent" class="api-anchor"></span>

### topAlignContent()

Top aligns the content.

```typescript
topAlignContent()
```

Specifies that content should be top aligned. This is the default.

<span id="-usedefaultpadding" class="api-anchor"></span>

### useDefaultPadding()

Use the default padding.

```typescript
useDefaultPadding()
```

Configure the stack to use the default padding. Any padding previously defined with `setPadding()` will be discarded.