How to Apply Animation in CSS – Question & Answer

How do you apply animation in CSS? Explain with an example.

Answer:

Animation in CSS is applied using the @keyframes rule along with the animation property.
The @keyframes rule defines how an element changes its style at different stages of the animation, and the animation property applies it to the HTML element.

Steps to Apply Animation in CSS:

  1. Define the animation using @keyframes

  2. Apply the animation to an element using animation property

  3. Set duration, timing, and repetition

Example:

 
.box { width: 100px; height: 100px; background-color: blue; animation: moveBox 2s ease-in-out infinite; } @keyframes moveBox { from { transform: translateX(0); } to { transform: translateX(200px); } }

Explanation:

  • moveBox is the animation name

  • 2s is the duration

  • ease-in-out controls the speed

  • infinite makes the animation repeat continuously

This is how animation is applied in CSS.

Categories: web designing web development html css front end developer

Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing Expert Course

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 25 Days

Crash : 15 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 6 Months

Fastrack : 4 Months

Crash : 2 Months

Web Expert with Python

Regular : 12 Months

Fastrack : 6 Months

Crash : 3 Months

Request For Demo