# States
> Show or hide parts of a Widget based on its data, with states and conditions.
## What are States?
States show or hide parts of a Widget based on its current data. Each state has a **name** and a **visibility** setting, and wraps a section of the Widget's code. While the state is visible, its content shows. Otherwise the content is hidden.
Manage states in the builder's **States** tab.

## Using States in the Code
In the code, a state is a `Stack` element: an invisible wrapper whose `widgetStateName` is the state's name and whose `visible` holds its condition. For example, a state named "Loading" that shows while `fetchStatus` is `loading`:
```jsx
```
While `fetchStatus` is `loading`, the "Please wait..." text shows. The rest of the Widget shows as usual whatever the state.
You don't need to write `visible` by hand. Wrap the content in a `Stack` with a `key`, click **Add state** in the **States** tab and set the condition there; the builder writes `visible` for you. **Add state** uses the first `Stack` that isn't a state yet, and names it `NewState`.
> [!NOTE]
>
> If **Add state** says "No reachable Stack can host another state.", wrap the content in a new `` in the code first.
To show a loading state while a function runs, set the variable its condition checks in the function's [On start](/docs/developer-guides/widgets/functions#after-a-function-runs) follow-up.
## Multiple Visible States
Several states can be visible at once. Each state controls only its own content.
```jsx
```
Here, when both "SignedIn" and "HasItems" are visible, the visitor sees the welcome, the item count and the button. When only "SignedIn" is visible, the item count is hidden, but the welcome and the button still show.
## Visibility Modes
Each state's **Visibility** decides when its content shows.
| Mode | Behavior |
| - | - |
| **Always visible** | The content always shows. |
| **Always hidden** | The content never shows. |
| **Conditional** | The content shows only when the conditions are met. |
> [!TIP]
>
> Switch a state to **Always visible** or **Always hidden** to check a section while you build.
## Operators
With **Conditional** visibility, each condition compares a Widget variable with a value using an operator.
| Operator | Description |
| - | - |
| **equal to** | Exactly matches the value. |
| **not equal to** | Doesn't match the value. |
| **contains** | The variable contains the value as text. |
| **not contains** | The variable doesn't contain the value as text. |
| **greater than** | The variable is greater than a number. |
| **greater than or equal** | The variable is greater than or equal to a number. |
| **less than** | The variable is less than a number. |
| **less than or equal** | The variable is less than or equal to a number. |
| **is empty** | The variable has no value. No comparison value is needed. |
| **is not empty** | The variable has a value. No comparison value is needed. |
## Combining Conditions
Click **Add condition** to add more conditions, and join them with **And** or **Or**.
* **And**: every condition must be true for the content to show.
* **Or**: at least one condition must be true.
Each condition after the first has a connector to the one before it. This lets you build rules like:
`status` equal to "Shipped" **And** `trackingUrl` is not empty
> [!NOTE]
>
> The conditions in one list must all use the same connector. To mix **And** and **Or**, use groups.
## Condition Groups
For more complex rules, click **Add group** to put conditions in groups. Each group is checked as a unit, and groups are joined to each other with **And** or **Or**.
This lets you write rules like:
(`status` equal to "Shipped" **And** `carrier` equal to "DHL") **Or** (`status` equal to "Shipped" **And** `carrier` equal to "UPS")
Here, the content shows when the order has shipped with either DHL or UPS. Use **Delete group** to remove a group, and **Remove all** to clear the conditions.
## States Tab in the Builder
Manage states in the **States** tab. Click a state to open it. Each state has:
* **Name**: the state's name, for example `Loading`, `Error` or `Success`. It's saved in the code as `widgetStateName`.
* **Visibility**: **Always visible**, **Always hidden** or **Conditional**.
* **Conditions**: with **Conditional**, one or more conditions with a variable, an operator, a value and connectors.
Changes apply as you make them, and the preview updates straight away. To remove a state, use **Delete state**. Its content stays in the Widget and shows as usual.
When a Widget has no states, the tab shows **No states defined yet** with **Add your first state**, as in the screenshot above.
> [!NOTE]
>
> States aren't the same as **named examples**. Named examples are sets of data for previewing in the builder. States decide what shows in the Widget, in the builder and in conversations, based on its actual data.
## Next steps
> [card] Functions | /docs/developer-guides/widgets/functions | Set the variables your states check.
> [card] Code Editor | /docs/developer-guides/widgets/code-editor | Preview each state with named examples.
> [card] Media & Visual | /docs/developer-guides/widgets/components/media#transition | Fade between states with Transition.