+++
title = "loading-states"
+++
This extension allows you to easily manage loading states while a request is in flight, including disabling elements, and adding and removing CSS classes.
## Install
```html
```
## Usage
Add the `hx-ext="loading-states"` attribute to the body tag or to any parent element containing your htmx attributes.
Add the following class to your stylesheet to make sure elements are hidden by default:
```css
[data-loading] {
display: none;
}
```
## Supported attributes
- `data-loading`
Shows the element. The default style is `inline-block`, but it's possible to use any display style by specifying it in the attribute value.
```html
loading
loading
loading
```
- `data-loading-class`
Adds, then removes, CSS classes to the element:
```html
...
```
- `data-loading-class-remove`
Removes, then adds back, CSS classes from the element.
```html
...
```
- `data-loading-disable`
Disables an element for the duration of the request.
```html
```
- `data-loading-aria-busy`
Add [`aria-busy="true"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-busy) attribute to the element for the duration of the request
```html
```
- `data-loading-delay`
Some actions may update quickly and showing a loading state in these cases may be more of a distraction. This attribute ensures that the loading state changes are applied only after 200ms if the request is not finished. The default delay can be modified through the attribute value and expressed in milliseconds:
```html
```
You can place the `data-loading-delay` attribute directly on the element you want to disable, or in any parent element.
- `data-loading-target`
Allows setting a different target to apply the loading states. The attribute value can be any valid CSS selector. The example below disables the submit button and shows the loading state when the form is submitted.
```html
Loading ...
```
- `data-loading-path`
Allows filtering the processing of loading states only for specific requests based on the request path.
```html
```
You can place the `data-loading-path` attribute directly on the loading state element, or in any parent element.
```html
```
- `data-loading-states`
This attribute is optional and it allows defining a scope for the loading states so only elements within that scope are processed.
```html