--- title: Transitions --- Transitions allow elements to enter and leave the DOM gracefully, rather than suddenly appearing and disappearing. ```html visible {#if visible}
fades in and out
{/if} ``` Transitions can have parameters — typically `delay` and `duration`, but often others, depending on the transition in question. For example, here's the `fly` transition: ```html visible {#if visible}flies 200 pixels up, slowly
{/if} ``` ### In and out An element can have separate `in` and `out` transitions: ```html visible {#if visible}flies up, fades out
{/if} ``` ### Built-in transitions Svelte comes with a handful of ready-to-use transitions: ```html ``` ### Custom transitions You can also make your own. Transitions are simple functions that take a `node` and any provided `parameters` and return an object with the following properties: * `duration` — how long the transition takes in milliseconds * `delay` — milliseconds before the transition starts * `easing` — an [easing function](https://github.com/rollup/eases-jsnext) * `css` — a function that accepts an argument `t` between 0 and 1 and returns the styles that should be applied at that moment * `tick` — a function that will be called on every frame, with the same `t` argument, while the transition is in progress Of these, `duration` is required, as is *either* `css` or `tick`. The rest are optional. Here's how the `fade` transition is implemented, for example: ```html visible {#if visible}fades in and out
{/if} ``` > If the `css` option is used, Svelte will create a CSS animation that runs efficiently off the main thread. Therefore if you can achieve an effect using `css` rather than `tick`, you should.