Skip to content

Animation ​

SweetAlert2 supports custom animations for the show and hide transitions of popup dialogs. The HasAnimation trait integrates with Animate.css to provide smooth, professional animations.

Basic Animation ​

Use the animation() method to specify both the show (entrance) and hide (exit) animation classes:

php
Alert::title('Welcome!')
    ->success()
    ->animation('animate__bounceIn', 'animate__bounceOut')
    ->flash();

The animate__ prefix is automatically added — the method wraps your class names with animate__animated to create the full Animate.css class string.

Enable Animate.css ​

For animations to work, you need to load the Animate.css stylesheet. Set the configuration option:

env
SWEET_ALERT_ANIMATION_ENABLE=true

This automatically includes the Animate.css CSS file when rendering alerts. You can also provide a custom CDN URL:

env
SWEET_ALERT_ANIMATECSS=https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css

Available Animate.css Classes ​

Here are some popular animation classes that work well with SweetAlert2:

Entrance Animations (Show) ​

ClassEffect
animate__bounceInBouncy entrance
animate__fadeInSimple fade in
animate__fadeInDownFade in from top
animate__fadeInUpFade in from bottom
animate__slideInDownSlide in from top
animate__slideInUpSlide in from bottom
animate__zoomInZoom in from center
animate__flipInX3D flip on X axis
animate__rotateInRotating entrance
animate__rollInRolling entrance

Exit Animations (Hide) ​

ClassEffect
animate__bounceOutBouncy exit
animate__fadeOutSimple fade out
animate__fadeOutDownFade out to bottom
animate__fadeOutUpFade out to top
animate__slideOutDownSlide out to bottom
animate__slideOutUpSlide out to top
animate__zoomOutZoom out to center
animate__flipOutX3D flip exit on X axis
animate__rotateOutRotating exit
animate__rollOutRolling exit

Disable Animation ​

To disable all animations on a specific alert:

php
Alert::title('Instant')
    ->info()
    ->disableAnimation()
    ->flash();

Advanced: Custom Show/Hide Classes ​

For full control over the animation classes (not using Animate.css), use showClass() and hideClass():

php
Alert::title('Custom Animation')
    ->showClass([
        'popup' => 'my-custom-enter-animation',
    ])
    ->hideClass([
        'popup' => 'my-custom-exit-animation',
    ])
    ->flash();

The showClass and hideClass options support multiple targets:

php
Alert::title('Multi-part Animation')
    ->showClass([
        'popup' => 'animate__animated animate__fadeInDown',
        'backdrop' => 'animate__animated animate__fadeIn',
        'icon' => 'animate__animated animate__heartBeat',
    ])
    ->hideClass([
        'popup' => 'animate__animated animate__fadeOutUp',
        'backdrop' => 'animate__animated animate__fadeOut',
        'icon' => 'animate__animated animate__rotateOut',
    ])
    ->flash();

Example: Slide-in Toast ​

php
Alert::toast('New message received', 'info')
    ->animation('animate__slideInRight', 'animate__slideOutRight')
    ->flash();

Example: Bouncy Success Modal ​

php
Alert::title('Order Confirmed!')
    ->success()
    ->text('Your order has been placed successfully.')
    ->animation('animate__bounceIn', 'animate__bounceOut')
    ->confirmButton('Great!', '#28a745')
    ->flash();

Made with ❤️ from Pakistan Released under the MIT License.