Skip to content
CSS

Animation

CSS keyframe animations.

By EZ4Code Team
cssanimation

Code

/* Define keyframes */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-30px); }
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

/* Apply animation */
.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

.bounce {
    animation: bounce 1s ease-in-out infinite;
}

.spinner {
    animation: rotate 1s linear infinite;
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}

/* Multiple animations */
.multi {
    animation: fadeIn 0.5s, rotate 2s 0.5s infinite;
}

/* Animation pause */
.paused {
    animation-play-state: paused;
}

Explanation

@keyframes defines keyframes; the animation property controls duration, easing, iteration count, delay, etc.

More CSS Snippets