--- layout: demo_layout.njk --- ## Animations Htmx is designed to allow you to use [CSS transitions](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions) to add smooth animations and transitions to your web page using only CSS and HTML. Below are a few examples of various animation techniques. ### Swap Fade Out If you want to fade out an element that is going to be removed when the request ends, you want to take advantage of the `htmx-swapping` class with some CSS and extend the swap phase to be long enough for your animation to complete. This can be done like so: ```html ``` #### Demo ### Settle Fade In Building on the last example, we can fade in the new content by using the `htmx-settling` class during the settle phase. ```html ``` #### Demo ### Request In Flight Animation You can also take advantage of the `htmx-request` class, which is applied to the element that triggers a request. Below is a form that on submit will change its look to indicate that a request is being processed: ```html
``` #### Demo ### Using the HTMX `class-tools` Extension Many interesting animations can be created by using the [`class-tools`](/extensions/class-tools) extension. Here is an example that toggles the opacity of a div. Note that we set the toggle time to be a bit longer than the transition time. This avoids flickering that can happen if the transition is interrupted by a class change. ```html