CSS Animations allow you to smoothly transition between different styles of an element over a specific duration. You can animate properties like color, size, position, and more, making your web page feel dynamic and interactive.
/* Keyframe Syntax */ @keyframes move { 0% { transform: translateX(0); background-color: #007BFF; } 50% { transform: translateX(100px); background-color: #FF6347; } 100% { transform: translateX(0); background-color: #007BFF; } } /* Apply animation */ .animated-box { animation: move 2s ease-in-out infinite; }
@keyframes
β Defines the keyframes for an animation. Specifies what happens at different stages (percentage-wise) during the animation.animation
β A shorthand property to apply an animation to an element. It includes parameters for animation name, duration, timing function, iteration count, etc.animation-name
β The name of the animation (which corresponds to the keyframes). E.g., move
.animation-duration
β Defines how long the animation should take to complete one cycle.animation-timing-function
β Defines the speed curve of the animation. E.g., ease-in-out
for a smooth transition.animation-iteration-count
β Specifies the number of times the animation should run. Use infinite
for endless loops.When using animations, ensure they donβt overwhelm users, especially on smaller screens. You can adjust the duration or animation effects for mobile devices using media queries for a better user experience.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!