Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

CSS Animations and Transitions

Lesson 12 of 34 in the free Web Technologies notes on Siksha Sarovar, written by Rohit Jangra.

CSS Animations and Transitions

CSS Transitions

Transitions animate a property change from one value to another over a duration.

.button {
    background-color: blue;
    color: white;
    padding: 10px 20px;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.button:hover {
    background-color: darkblue;
    transform: scale(1.05);
}

Transition Properties

PropertyPurpose
transition-propertyWhich property to animate
transition-durationHow long (e.g., 0.5s)
transition-timing-functionSpeed curve
transition-delayWait before starting

Timing Functions

ValueBehavior
easeSlow start and end (default)
linearConstant speed
ease-inSlow start
ease-outSlow end
ease-in-outSlow start and end
cubic-bezier(n,n,n,n)Custom curve

CSS Animations

Animations use @keyframes to define multiple steps.

/* Define the animation */
@keyframes slideIn {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

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

/* Apply the animation */
.hero {
    animation: slideIn 0.8s ease-out forwards;
}

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

Animation Properties

PropertyPurpose
animation-name@keyframes name
animation-durationLength of one cycle
animation-iteration-countNumber of repeats (infinite)
animation-directionnormal / reverse / alternate
animation-fill-modeforwards / backwards / both
animation-play-staterunning / paused

Transform Property

.element {
    transform: translateX(50px) translateY(20px);
    transform: rotate(45deg);
    transform: scale(1.5);
    transform: skew(10deg, 5deg);
    transform: matrix(1, 0, 0, 1, 50, 20);
}

CSS Variables with Animations

:root {
    --primary: #3498db;
    --duration: 0.4s;
}

.card {
    transition: box-shadow var(--duration) ease;
}

.card:hover {
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
Key Takeaway: CSS transitions handle simple state changes (hover effects), while CSS animations with @keyframes handle complex multi-step sequences. Both use the transform property for GPU-accelerated smooth effects.