CSS: Transitions & Animations

Learn how to create smooth transitions and animations using CSS.

CSS Transitions

CSS transitions allow you to change property values smoothly over a specified duration:

Example: CSS Transition

/* Example */
button {
    background-color: #007BFF;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}
button:hover {
    background-color: #0056b3;
}
        

This example creates a button with a smooth color transition on hover.

CSS Animations

CSS animations allow you to define keyframes for more complex animations:

Example: CSS Animation

/* Example */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
div {
    animation: fadeIn 2s ease-in-out;
}
        

This example creates a fade-in effect for a div element.

Practice

Try experimenting with transitions and animations:

Continue Learning

Quick Check

Which shorthand property configures all transition values at once?