> For the complete documentation index, see [llms.txt](https://cbwire.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cbwire.ortusbooks.com/3.x/template-features/loading-states.md).

# Loading States

Show your users loading spinners, modals, and more as they wait for requests to complete.

Actions may involve a long-running process (such as completing a cart checkout) and HTML may not re-render instantly. You can help your users during the wait using Loading States. Loading States allow you to show/hide elements, add/remove classes, or toggle HTML attributes until the server responds.

{% hint style="success" %}
Loading States can make your apps feel much more responsive and user-friendly.
{% endhint %}

## Toggling Elements

Let's look at an action that takes too long.

```javascript
<cfscript>
    function addTask(){
        sleep( 5000 ); // Optimize this code yo!
    }
</cfscript>
```

We can annotate our \<div> with *wire:loading* to display *Adding Task* while the checkout action is running.

```xml
<cfoutput>
    <div>
        <button wire:click="addTask">Add Task</button>
    
        <div wire:loading>
            Adding Task...
        </div>
    </div>
</cfoutput>

<cfscript>
    function addTask(){
        sleep( 5000 ); // Optimize this code yo!
    }
</cfscript>
```

After the action completes, the *Adding Task...* output will disappear. :wave:&#x20;

## Toggling Attributes

```xml
<cfoutput>
    <div>
        <button wire:click="addTask" wire:loading.attr="disabled">
            Add Task
        </button>
    </div>
</cfoutput>
```

## Targeting Specific Actions

You can target a specific action so that the element is only visible if a specific action is loading using *wire:target*.

```html
<cfoutput>
   <div>
       <button wire:click="addTask">Add Task</button>
    
       <div wire:loading wire:target="addTask">
          Adding task...
       </div>
   </div>
</cfoutput>
```

## Delaying

If you want to avoid flickering because loading is very fast, you can add a *.delay* modifier, and it will only show up if loading takes longer than 200ms.

```html
<div wire:loading.delay>...</div>
```

If you wish, you can customize the delay duration with the following modifiers:

```xml
<div wire:loading.delay.shortest>...</div> <!-- 50ms -->
<div wire:loading.delay.shorter>...</div>  <!-- 100ms -->
<div wire:loading.delay.short>...</div>    <!-- 150ms -->
<div wire:loading.delay>...</div>          <!-- 200ms -->
<div wire:loading.delay.long>...</div>     <!-- 300ms -->
<div wire:loading.delay.longer>...</div>   <!-- 500ms -->
<div wire:loading.delay.longest>...</div>  <!-- 1000ms -->
```

## Display Property

Loading State elements are set with a CSS property of *display: inline-block;* by default. You can override this behavior by using various directive modifiers.

```xml
<div wire:loading.flex>...</div>
<div wire:loading.grid>...</div>
<div wire:loading.inline>...</div>
<div wire:loading.table>...</div>
```

## Hiding

If you want to display an element except during a loading state, you can apply the *wire:loading.remove* directive.

<pre class="language-xml"><code class="lang-xml">&#x3C;cfoutput>
<strong>    &#x3C;div>
</strong>        &#x3C;button wire:click="addTask">Add Task&#x3C;/button>
    
        &#x3C;div wire:loading.remove>
            Click 'Add Task'
        &#x3C;/div>
    &#x3C;/div>
&#x3C;/cfoutput>
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cbwire.ortusbooks.com/3.x/template-features/loading-states.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
