> For the complete documentation index, see [llms.txt](https://manual.bubble.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manual.bubble.io/help-guides/logic/conditions.md). Agents can also search and read this documentation through its [MCP server](https://manual.bubble.io/~gitbook/mcp).

# Conditions

Conditions are yes/no checks that change how elements look and decide whether workflows and actions run. Learn how to set them up, keep them fast, and use them securely.

Conditions are questions your app asks itself, where the answer is *yes* or *no*, such as whether the user is logged in, whether an input is empty, or whether the current user is an admin. Based on the answer, Bubble can change how an element[^1] looks, stop a workflow[^2] from running, or start one.

For example, if a user leaves a required field empty in a form, a condition can check whether the field is empty and stop the form from being submitted until the missing information is filled in.

{% hint style="info" %}
Conditions are built with dynamic expressions[^3], so it helps to know how those work before you start.

**Article:** [Dynamic expressions](https://manual.bubble.io/help-guides/logic/dynamic-expressions.md)\
**Reference:** [Data sources](https://manual.bubble.io/core-resources/data/data-sources.md)\
**Reference:** [Operators and comparisons](https://manual.bubble.io/core-resources/data/operations-and-comparisons.md)
{% endhint %}

You'll use conditions in three places:

| Where                                                                 | What the condition does                                       | Example                                     |
| --------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------- |
| [On elements](#element-conditions)                                    | Changes the element's properties while the condition is true  | Make a button clickable only for admins     |
| [On workflows and actions](#only-when-conditions-workflow-conditions) | Decides whether a workflow or action runs once it's triggered | Only create a thing if an input isn't empty |
| [As an event](#running-a-workflow-when-a-condition-is-true)           | Starts a workflow as soon as the condition becomes true       | Run a workflow when the user logs in        |

Conditions also work in [Bubble for native mobile apps](https://manual.bubble.io/help-guides/getting-started/building-for.../native-ios-and-android.md), for example to [show one group or another in a view](https://manual.bubble.io/help-guides/design/elements/ios-and-android-app/containers/group-element-mobile.md#conditions).

***

## Element conditions

Element conditions change an element's properties while an expression returns *yes*. You'll find them in the **Conditional** tab of the element property editor, where each condition has two parts:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2Fr5ZZLiq5qh6W1L3YgdDW%2Felement-property-editor.png?alt=media&amp;token=ad9744f0-b429-4428-853d-f63c38677429" alt="The Conditional tab of a button called post-card-delete-btn, with a condition that turns on Make clickable when Current User&#x27;s admin is yes."><figcaption><p>This condition makes the delete button clickable for admins only. Note that this is only a UI change – it is not a secure way to stop a workflow from running.</p></figcaption></figure>

<table><thead><tr><th width="128.140625">Part</th><th>What it does</th></tr></thead><tbody><tr><td>When</td><td>The expression that decides when the condition applies. Here, it's <code>Current User's admin is yes</code>.</td></tr><tr><td>Then</td><td>The properties that change while the expression returns <em>yes</em>. Here, <em>Make clickable</em> is turned on, so admins can click the button.</td></tr></tbody></table>

If the element's style[^4] has conditions of its own, the **Conditional** tab lists them separately as inherited from the style, above the element's own conditions.

Element conditions are dynamic and instant. Whenever the data in the expression changes, Bubble checks the condition again and updates the element right away. When the expression goes back to returning *no*, the element goes back to its default properties.

### Adding a condition to an element

{% stepper %}
{% step %}

#### Open the Conditional tab

Select the element, and open the **Conditional** tab in the element property editor.
{% endstep %}

{% step %}

#### Add a condition

Click the *+* icon next to *All conditionals* at the top of the tab.
{% endstep %}

{% step %}

#### Write the expression

In the *When* field, build an expression that returns *yes* or *no*, such as `Current User's admin is yes`.
{% endstep %}

{% step %}

#### Pick the properties to change

Under *Then*, choose a property to change while the expression returns *yes*, and set its value. Depending on the property, a value can be static or a dynamic expression. To change more properties, click **Change another property**.
{% endstep %}
{% endstepper %}

**Reference:** [Conditional element properties](https://manual.bubble.io/core-resources/bubble-elements/conditional-element-properties.md)

### Using more than one condition

You can add as many conditions as you need to an element, and more than one can be true at the same time. For example, one condition could make a button unclickable while another changes its color.

Bubble reads an element's conditions from top to bottom. If two conditions are true and change the same property, the one lowest in the list wins, since it's applied last. You can drag conditions up and down to change their order.

### Applying styles with conditions

Instead of changing properties one at a time, a condition can apply a different style to the element. For example, you could set up one style for light mode and one for dark mode. If you save a yes/no field called *Dark mode* on the user, a condition like `Current User's Dark mode is yes` can switch the element to the dark style. You can still adjust individual properties on top of the style.

You can also place a condition on the style itself, so every element that uses it changes at once.

**Article section:** [Using styles in conditionals](https://manual.bubble.io/help-guides/design/variables-and-styles/styles.md#using-styles-in-conditionals)\
**Article section:** [Can I use color variables for dark mode?](https://manual.bubble.io/help-guides/design/variables-and-styles/color-variables.md#can-i-use-color-variables-for-dark-mode)

### Previewing conditions

To see what an element looks like when a condition is true, hover the condition and click the play icon in its top bar. Click it again to turn the preview off. The preview only changes what you see in the editor, not how your app behaves.

{% embed url="<https://youtu.be/uF1gU9VXrg8>" %}
A Bubble Academy quick tip on previewing element conditions
{% endembed %}

### Debugging element conditions

Since several conditions can be true at the same time, it's not always obvious why an element looks or behaves the way it does. The debugger[^5] can help. When you preview your app, select the element with the debugger to see its conditions: true conditions are shown in green, and false ones in red.

**Article section:** [Understanding expression evaluations](https://manual.bubble.io/help-guides/getting-started/navigating-the-bubble-editor/tools/using-the-debugger.md#understanding-expressions-evaluations)

***

## Only when conditions (workflow conditions)

*Only when* conditions decide whether a workflow or action runs once it's been triggered. Each time, Bubble checks the condition first and only goes ahead if it returns *yes*. For example, if a button starts a workflow, Bubble can check every time the button is clicked whether the user is allowed to run it.

You can place the condition on the event[^6] or on a single action[^7], and the two work a little differently:

<table><thead><tr><th width="138.08984375">Condition on</th><th>What happens when it returns no</th></tr></thead><tbody><tr><td>The event</td><td>None of the workflow's actions run.</td></tr><tr><td>An action</td><td>Bubble skips that action and moves on to the next one. Later actions can't use any data the skipped action would have produced.</td></tr></tbody></table>

To add a condition, select the event or action, and write the expression in the *Condition* field in the **Only when** section of the workflow property editor. In this example, the condition is on the event, so the whole workflow only runs when the current user is an admin:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FOTfgQNEP2dvnXZAvB9w0%2Fevent-condition.png?alt=media&amp;token=1f9fe9a7-c73d-45e3-a966-51d606f13615" alt="The workflow property editor for a Button post-card-delete-btn is clicked event, with the condition Current User&#x27;s admin is yes in the Only when section."><figcaption><p>A condition on the event decides whether any of the workflow's actions run.</p></figcaption></figure>

In the next example, the condition is on the [**Create a new thing**](#user-content-fn-8)[^8] action instead, so only that step depends on it. The post is only created if the title input isn't empty:

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2F83qjkMMUf2JUUP8Sfqt6%2Faction-condition.png?alt=media&amp;token=2fb407b3-e189-42b6-ba62-8e29c23ab3c5" alt="The workflow property editor for a Create a new Post action, with the condition Input editor-title-input&#x27;s value is not empty in the Only when section."><figcaption><p>A condition on an action only decides whether that action runs.</p></figcaption></figure>

Bubble checks the condition each time the event or action is about to run, so it uses the latest data.

*Only when* conditions are also an important part of your app's security. See [Using conditions for security](#using-conditions-for-security).

**Reference:** [Conditional workflow properties](https://manual.bubble.io/core-resources/bubble-workflows/conditional-workflow-properties.md)

### Choosing between workflows with conditions

You can also use conditions to decide which of several workflows runs. For example, two workflows can share the same event, such as a button click, with opposite conditions. One creates a thing when the current user is an admin, and the other shows an error message when they're not.

You can get the same result with conditions on individual actions in a single workflow. If each alternative has several steps, though, separate workflows are often easier to manage, since you only need one condition per workflow instead of one per action.

***

## Running a workflow when a condition is true

The *Do when condition is true* event starts a workflow as soon as its condition returns *yes*. For example, a workflow can run when the current user is logged in.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FcR3jTy2PEfxvfhud0bTr%2Fevent-on-condition.png?alt=media&amp;token=f3897193-09f2-402e-a08b-77774c9afc18" alt="A condition event in the When user is logged in workflow, with Run this set to Just once and Current User is logged in as its Only when condition."><figcaption><p>This workflow runs when the current user is logged in. Its <em>Run this</em> property is set to run once, so it triggers once per page load.</p></figcaption></figure>

Its *Run this* property decides how often it runs:

<table><thead><tr><th width="168.07421875">Option</th><th>What it does</th></tr></thead><tbody><tr><td><em>Only once</em></td><td>Triggers once per page load.</td></tr><tr><td><em>Every time</em></td><td>Triggers every time the condition is true.</td></tr></tbody></table>

Bubble keeps checking the condition while the page is open, so this event can affect performance and workload if it triggers often or checks something in the database.

**Article section:** [When a condition is true](https://manual.bubble.io/help-guides/logic/workflows/events/frontend-events.md#when-a-condition-is-true)\
**Article section:** [Do when condition is true and conditions](https://manual.bubble.io/help-guides/workload/optimizing-workload/optimization-checklist/workflows-and-actions.md#do-when-condition-is-true-and-conditions)

{% hint style="info" %}
Database trigger events work in a similar way on the server. They watch for changes in the database and run a backend workflow when a change matches their conditions, whether or not anyone has your app open.

**Article:** [Database trigger events](https://manual.bubble.io/help-guides/logic/workflows/events/backend-events/database-trigger-events.md)
{% endhint %}

***

## Creating efficient expressions

Bubble reads an expression from left to right, and it doesn't do more work than it has to. When the steps in a condition are joined with the *and* operator and one of them returns *no*, Bubble already knows the answer, so it doesn't check the rest.

You can use this to your advantage. Put the quickest checks first, and Bubble can often find the answer before it reaches the slow ones.

There's no hard rule for what makes a check slow, but these guidelines can help:

<table><thead><tr><th width="218.06640625">Type of check</th><th>Speed</th><th>Example</th></tr></thead><tbody><tr><td>Something already on the page</td><td>Usually fast</td><td><code>Group Menu is visible</code>, <code>Input Email's value is not empty</code></td></tr><tr><td>A database search</td><td>Slower, since the request has to go to the server and back. The more complex the search, the slower it gets.</td><td><code>Search for Posts:count ≤ 100</code></td></tr><tr><td>Heavy processing on the device</td><td>Usually fast, but it can slow down with large amounts of data</td><td>Using the <em>intersect with</em> operator on two lists with thousands of things</td></tr></tbody></table>

Searches also use workload[^9], so skipping one when it isn't needed can save workload too.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2Fnj9vnqzInZcGv1uy28EM%2Fefficient-condition-check-example.png?alt=media&amp;token=720090dc-dbb8-4353-8501-3ff098d9ede1" alt="The Save post is clicked event, with the condition Current User is logged in and Search for Posts:count ≤ 100 in the Only when section of the workflow property editor."><figcaption><p>The simple check comes first, so Bubble can skip the search if the current user isn't logged in.</p></figcaption></figure>

In the example above, the workflow checks two things before it runs. The first, `Current User is logged in`, is a simple check. The second is a search that runs on the server, which takes longer. Since the search comes last, Bubble can skip it whenever the user is logged out.

**Article section:** [The order in a conditional expression](https://manual.bubble.io/help-guides/workload/optimizing-workload/optimization-checklist/workflows-and-actions.md#the-order-in-a-conditional-expression)

<details>

<summary>Why does Bubble stop checking early?</summary>

Stopping as soon as the answer is known is called *short-circuit evaluation*, and many programming languages work the same way.

Think of the question "Is it raining, and did I bring an umbrella?" If it isn't raining, it doesn't matter whether you brought an umbrella. The answer to the whole question is already *no*, so there's no reason to check the second part.

That's why the order of your checks matters. Bubble can only skip the parts that come after the one that settles the answer.

</details>

***

## Using conditions for security

Conditions are an important part of your app's security, but they don't all protect your app the same way. Some provide real security, while others only make things harder to find, which is called obfuscation.

### Obfuscation versus security

"Obfuscation isn't security" is a common saying when people discuss security, and it holds true for Bubble too. Obfuscation can make it harder for an attacker to find and exploit a weakness, but it can't stop them.

That doesn't mean you should avoid obfuscation. Making things harder for attackers is still worthwhile, and it's often an important part of the user experience. What matters is knowing which is which.

### Element conditions and security

Hiding or showing elements, making them unclickable or uneditable, and changing their style with conditions is a common way to guide users and show them what they can and can't do.

<figure><img src="https://34394582-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M5sbzwG7CljeZdkntrL%2Fuploads%2FQyAtThnOadMy6owmXlc0%2Funsafe-condition-example.png?alt=media&amp;token=c6e8129e-a0b9-490a-bfd6-ba757899c2f5" alt="The Conditional tab of a button called Save post, with a condition that turns off Make clickable when Current User&#x27;s admin is no."><figcaption><p>Element conditions are good for the user experience, but they aren't a secure way to stop a workflow from running. Users who aren't admins can't click this button, but a technical user can get around that.</p></figcaption></figure>

This makes good sense for the user experience, but it isn't secure. The elements on your page are part of the code that the user's browser downloads, so a technical user can change them on their own device. For example, they could show an element that's supposed to be hidden, or click a button that's supposed to be unclickable.

Treat element conditions as *obfuscation*. To stop a user from running a workflow they're not allowed to run, place a condition on the workflow too.

### Workflow conditions and security

Conditions on workflows and actions are a more secure way to stop unauthorized use. Together with privacy rules[^10], they're a central part of your app's security. How secure a condition is depends on where Bubble checks it:

| The condition checks                                  | Where it's checked   | Example                        | How secure                                                            |
| ----------------------------------------------------- | -------------------- | ------------------------------ | --------------------------------------------------------------------- |
| Something in the database, or the user's login status | On the server        | `Current User's Admin is yes`  | The user can't change the result.                                     |
| Something on the page                                 | On the user's device | `Group Admin panel is visible` | A technical user can change the result, so it's easier to get around. |

A server-side condition doesn't make a client-side action secure, though. For example, a server-side condition on a **Show an element** action still isn't secure, since the element can be shown by changing the code on the device.

**Article section:** [Page security: Conditions](https://manual.bubble.io/help-guides/security/page-security.md#conditions)

<details>

<summary>What do client-side and server-side mean?</summary>

*Client-side* describes anything that happens on the user's device, such as in their browser. Since it happens on the user's own device, a technical user can look at it and change it.

*Server-side* describes anything that happens on Bubble's server, out of the user's reach. The user only sees the result.

**Article:** [Client-side and server-side](https://manual.bubble.io/help-guides/security/client-side-and-server-side.md)

</details>

These tips can help you keep your conditions secure:

| Tip                                                         | Why it helps                                                                                                                                                                                          |
| ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Base sensitive conditions on something the server can check | The user can't change the result on their device.                                                                                                                                                     |
| Put alternative courses of action in separate workflows     | You have fewer conditions to keep track of and update if something changes, compared to one workflow with a condition on each action.                                                                 |
| Keep sensitive information out of condition names           | Condition names don't affect how your app runs, but they're visible in your app's source code.                                                                                                        |
| Test your app as different users                            | [Previewing your app as different users](https://manual.bubble.io/help-guides/previewing-your-app/previewing-a-web-app.md#switch-between-users) lets you check that each condition works as expected. |

The [security dashboard](https://manual.bubble.io/help-guides/security/security-dashboard.md) can also help you find weak spots, such as sensitive data exposed in workflows.

***

## Set up conditions with Bubble AI

You can ask the [Bubble AI Agent](https://manual.bubble.io/help-guides/ai/bubble-ai-agent.md) to help you with conditions. It can create workflows that use the [*Do when condition is true* event](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/edit-apps-with-ai.md#generate-and-modify-frontend-workflows), and in [backend workflows](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/edit-apps-with-ai.md#generate-and-modify-backend-workflows), it can add *Only when* conditions to the workflow or to individual actions and help you find a misconfigured one.

The Agent can also [explain how your app is set up](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/edit-apps-with-ai.md#app-specific-explanations), such as which conditions are on an element and what they do. Select the element or workflow before you send your prompt, so the Agent knows which one you mean.

Here are a few prompts to try:

{% code overflow="wrap" %}

```
Create a workflow that shows the Results group every time the Search input isn't empty.
```

{% endcode %}

{% code overflow="wrap" %}

```
Add a condition to the archive-project API workflow so it only runs if the current user's Admin field is yes.
```

{% endcode %}

{% code overflow="wrap" %}

```
Explain the conditions on this button, and which one applies if more than one is true.
```

{% endcode %}

{% code overflow="wrap" %}

```
Why isn't the Save action in this workflow running?
```

{% endcode %}

{% code overflow="wrap" %}

```
How do I make sure only admins can run the Delete project workflow?
```

{% endcode %}

**Article:** [Edit apps with AI](https://manual.bubble.io/help-guides/ai/bubble-ai-agent/edit-apps-with-ai.md)

***

## FAQ: Conditions

<details>

<summary>What's the difference between a condition and a dynamic expression?</summary>

A condition is a dynamic expression that returns *yes* or *no*. Bubble uses that answer to decide whether to change an element, run a workflow or action, or start a workflow.

**Article:** [Dynamic expressions](https://manual.bubble.io/help-guides/logic/dynamic-expressions.md)

</details>

<details>

<summary>What happens if two element conditions change the same property?</summary>

Bubble reads conditions from top to bottom, so the true condition lowest in the list wins. See [Using more than one condition](#using-more-than-one-condition).

</details>

<details>

<summary>Does the rest of the workflow run if an action's condition returns no?</summary>

Yes. Bubble skips that action and moves on to the next one, but later actions can't use any data the skipped action would have produced. To stop the whole workflow, place the condition on the event instead.

</details>

<details>

<summary>What's the difference between Only when and Do when condition is true?</summary>

An *Only when* condition checks whether a workflow or action should run after something else has triggered it, like a button click. The *Do when condition is true* event is the trigger itself: it starts the workflow as soon as the condition becomes true.

</details>

<details>

<summary>Can I check more than one thing in a condition?</summary>

Yes. Use the *and* operator when every part has to be true, and the *or* operator when one is enough. With *and*, Bubble stops checking as soon as one part returns *no*, so put the quickest checks first. See [Creating efficient expressions](#creating-efficient-expressions).

</details>

<details>

<summary>Are element conditions secure?</summary>

No. They're useful for the user experience, but a technical user can change how an element looks and behaves on their own device. To protect a workflow, place a condition on the workflow itself, and protect your data with privacy rules. See [Using conditions for security](#using-conditions-for-security).

</details>

<details>

<summary>Do conditions use workload?</summary>

It depends on what they check. A condition that checks something on the page, like whether an element is visible, is checked on the user's device and doesn't use workload. A condition that searches the database does.

**Article section:** [Do when condition is true and conditions](https://manual.bubble.io/help-guides/workload/optimizing-workload/optimization-checklist/workflows-and-actions.md#do-when-condition-is-true-and-conditions)

</details>

<details>

<summary>Can I name my conditions?</summary>

Yes. You can give each condition a name to make it easier to find, and the name doesn't affect how it runs. Names are visible in your app's source code, though, so don't include sensitive information in them.

**Reference:** [Conditional element properties](https://manual.bubble.io/core-resources/bubble-elements/conditional-element-properties.md)

</details>

[^1]: *Elements* are the objects that you place on the page as you design your app. There are many different types of elements, like texts, buttons, input fields, and calendars.\
    **Article series:** [Elements](https://manual.bubble.io/help-guides/design/elements.md)

[^2]: A *workflow* is the combination of an event and one or more actions.\
    **Article:** [Workflows](https://manual.bubble.io/help-guides/logic/workflows.md)

[^3]: Dynamic expressions are like live formulas that update based on user input, database changes, and other things happening in your app.\
    **Article:** [Dynamic expressions](https://manual.bubble.io/help-guides/logic/dynamic-expressions.md)

[^4]: *Styles* are reusable sets of visual properties tied to an element type. Changing a style updates every element that uses it.\
    **Article:** [Styles](https://manual.bubble.io/help-guides/design/variables-and-styles/styles.md)

[^5]: The debugger lets you check your workflows and element properties in real time when you preview your app.\
    **Article:** [The debugger](https://manual.bubble.io/help-guides/getting-started/navigating-the-bubble-editor/tools/using-the-debugger.md)

[^6]: An event is what starts a workflow, such as a button being clicked.\
    **Article:** [Events](https://manual.bubble.io/help-guides/logic/workflows/events.md)

[^7]: *Actions* are the steps in a workflow that do the work, such as changing something in the database or showing an element.\
    **Article:** [Actions](https://manual.bubble.io/help-guides/logic/workflows/actions.md)

[^8]: *Create a new thing* creates a new thing in the database, and can save data to its fields at the same time.\
    **Article:** [Creating, saving and deleting data](https://manual.bubble.io/help-guides/data/the-database/creating-saving-and-deleting-data.md)\
    **Reference:** [Create a new thing](https://manual.bubble.io/core-resources/bubble-workflows/bubble-actions/database-actions.md#create-a-new-thing)

[^9]: *Workload* is the overall metric that measures how much work the server has to do to power your app.\
    **Article series:** [Workload](https://manual.bubble.io/help-guides/workload.md)

[^10]: Privacy rules decide which data each user is allowed to see, before anything is sent to their device.\
    **Article:** [Protecting data with privacy rules](https://manual.bubble.io/help-guides/data/the-database/protecting-data-with-privacy-rules.md)
