Transitions in Alexa with AnimateItem
Tags: alexa, apl, animation, transitions
Published: 2019-07-17 22:40:06

---
title: Transitions in Alexa with AnimateItem
published: true
description: How to add transition to components in Alexa with AnimateItem
tags: alexa, apl, animation, transitions
---

Transitions are simple animations that provides visual feedback and enhances the pleasantness of the UI. By simply combining opacity, movement, scale and rotation we can create various types of transitions.

If you are new to transitions you can get some inspiration from [uimovement.com](https://uimovement.com). Since the animations featured in the website is for web or mobile, not all can translate to a alexa animation but you can get some idea out of it.

_Note: Always make sure the transitions are short and subtle._

{% youtube DOrp9iRWxLU %}

This article will go through in detail on how to create some transitions with [AnimateItem](https://developer.amazon.com/docs/alexa-presentation-language/apl-standard-commands.html#animate_item_command). If you are familiar with CSS Animations then AnimateItem works exactly the same with some limitations.


## FadeIn

To create a fade in effect all we have to do is increase the opacity of the component from 0 to 1 gradually for a specific duration.

```json
{
    "type": "AnimateItem",
    "duration": 1000,
    "value": [
        {
            "property": "opacity",
            "from": 0,
            "to": 1
        }
    ]
}
```

![](https://thepracticaldev.s3.amazonaws.com/i/4yq7ir55l2lcgua4dk8g.gif)

## FadeOut

FadeOut is similar to fade in but in reverse. Here we gradually reduce the opacity from 1 to 0.

```json
{
    "type": "AnimateItem",
    "duration": 1000,
    "value": [
        {
            "property": "opacity",
            "from": 1,
            "to": 0
        }
    ]
}
```

![](https://thepracticaldev.s3.amazonaws.com/i/vkcatenqbo3gy1hnilij.gif)

## FadeInUp

Here the opacity needs to change from 0 to 1 and the component needs to move from bottom to top. So we manipulate both opacity and translate in Y axis

```json
{
    "type": "AnimateItem",
    "duration": 1000,
    "value": [
        {
            "property": "opacity",
            "from": 0,
            "to": 1
        },
        {
            "property": "transform",
            "from": [
                {
                    "translateY": "100%"
                }
            ],
            "to": [
                {
                    "translateY": "0"
                }
            ]
        }
    ]
}
```

![](https://thepracticaldev.s3.amazonaws.com/i/vh9sakncuhn9p1rifc4o.gif)

## ZoomInDown

For this transition we manipulate opacity, scale on X & Y axis, translate on Y axis. This involves multiple AnimateItem executed in sequence. You will see an additional easing function here, rather than explaining what it does I will show a side by side comparison of the effect with and without the easing.

```json
{
    "type": "Sequential",
    "commands": [
        {
            "type": "AnimateItem",
            "duration": 600,
            "easing": "cubic-bezier(0.55, 0.055, 0.675, 0.19)",
            "value": [
                {
                    "property": "opacity",
                    "from": 0,
                    "to": 1
                },
                {
                    "property": "transform",
                    "from": [
                        {
                            "scaleX": 0.1,
                            "scaleY": 0.1
                        },
                        {
                            "translateY": "-100vh"
                        }
                    ],
                    "to": [
                        {
                            "scaleX": 0.475,
                            "scaleY": 0.475
                        },
                        {
                            "translateY": "60px"
                        }
                    ]
                }
            ]
        },
        {
            "type": "AnimateItem",
            "duration": 400,
            "easing": "cubic-bezier(0.175, 0.885, 0.32, 1)",
            "value": [
                {
                    "property": "transform",
                    "from": [
                        {
                            "scaleX": 0.475,
                            "scaleY": 0.475
                        },
                        {
                            "translateY": "60px"
                        }
                    ],
                    "to": [
                        {
                            "scaleX": 1,
                            "scaleY": 1
                        },
                        {
                            "translateY": "0"
                        }
                    ]
                }
            ]
        }
    ]
}
```

![](https://thepracticaldev.s3.amazonaws.com/i/f5ainikgz90mf4kia0ng.gif)

Adding a easing function enhances the transitions. AnimateItem supports both linear and cubic-beizier functions. Check [easings.net](https://easings.net) to know the types of easing that can be generated with cubic-bezier and how it actually affects the transition.

## Conclusion

Similar to the above examples you can create different variation of transitions. I have created a repo of few transitions which you can use in your skills [https://github.com/arjun-g/apl-transitions](https://github.com/arjun-g/apl-transitions). Instructions on how to use it can be found in the repo. Fade On!!!!!