---
schema_version: "1"
id: ac341f600776aeb50002e66de2959f1840f3a527213a8af1746d0ffcb2bbfce5
title: Conditional Expressions
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/expr/expr-conditional.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/expr-conditional.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: adc0375ec97be9fcbbd348c93d365126ea85719a49de91a2e4a8b3319e3e0ed8
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Conditional Expressions

Here are examples of conditional expressions using the ternary operator and the `<aura:if>` tag.

## Ternary Operator

This expression uses the ternary operator to conditionally output one of two values dependent on a condition.

<!-- otherprops: set_clipboard -->
```nolang
<a class="{!v.location == '/active' ? 'selected' : ''}" href="#/active">Active</a>
```

The `{!v.location == '/active' ? 'selected' : ''}` expression conditionally sets the `class` attribute of an HTML `<a>` tag, by checking whether the `location` attribute is set to `/active`. If true, the expression sets `class` to `selected`.

## Using `<aura:if>` for Conditional Markup

This snippet of markup uses the `<aura:if>` tag to conditionally display an edit button.

```nolang
<aura:attribute name="edit" type="Boolean" default="true"/>
<aura:if isTrue="{!v.edit}">
    <lightning:button label="Edit"/>
    <aura:set attribute="else">
        You can’t edit this.
    </aura:set>
</aura:if>
```

If the `edit` attribute is set to `true`, `lightning:button` displays. Otherwise, the text in the `else` attribute displays.

**See Also**  


-   [Best Practices for Conditional Markup](https://developer.salesforce.com/docs/platform/aura-platform/components/components-conditional-markup.md)

