Introduction
CSS is the language used to add style to HTML elements. CSS or Cascading Style Sheets are text files saved with the extension “.css” containing style rules. Traditionally we needed JavaScript and animation software like Flash to do an animation that works in any environment. These days, CSS makes it easier, cheaper and faster with just a few lines of coding. Yeah, it’s no longer a nightmare to code world-class animations.
We will be discussing the basics of animation by code using CSS.
CSS Animations
Now let’s see a few salient features of Animation using CSS. Let us list them based on their priority.
- Animations add additional value to any webpage
- CSS3 animations are created frame by frame.
- @keyframes is the heart for css3 animation code
- The keyframe is mutually interchangeable
- It can be used to animate a design for a particular time duration.
Now that we know the benefits of CSS animation, let's move on and learn a simple CSS Animation.
A keyframe defines the style that will be applied for that moment within the animation.
The animation engine will smoothly interpolate the style between the keyframes.
Specify when the style change occurs in percentages or with the keywords "from" and "to", which is the same as 0% and 100%. 0% is the beginning of the animation, 100% is when the animation is complete.
Syntax
@keyframes animationname {keyframes-selector {css-styles;}}
animationname is required. Defines the name of the animation.
keyframes-selector is required. Percentage of the animation duration.
The value is between 0 to 100%.
css-styles are also required. One or more legal CSS style properties may be applied.
CSS transforms property using a few 2D transformation methods.
- translate()
- rotate()
- scale()
- skew()
translate() is used to move an object from the current position. The boxObj class where you applied that particular div will be moved to right 50px, and top 50px from current position;
rotate() is used to rotate an element. Two types to rotate depends on the value. This value is mentioned in deg.. one is clockwise using positive values. The other uses negative values that rotate it counterclockwise.
scale() This method increases or decreases the overall size of an object. We use two types of scale().
- scaleX() is increases or decreases the width of an element.
- scaleY() is increases or decreases the height of an element.
skew() This method skews a particular element along the X and Y-axis by the given angles. Here we use a scale() and do a simple animation.
- @keyframes bounceObj{
- 0%{
- transform: scale(0.2);
- opacity: 0;
- }
- 50%{
- transform: scale(1.2);
- opacity: 1;
- }
- 100%{
- transform: scale(1);
- }
- }
Let’s move to the next step by doing a basic animation using CSS in which we are using keyframes to transform or transition an object.

Ravishankar NPosted Nov 19, 2019, 9:41 PM
Nice article
Sourav Kumar DasPosted Nov 14, 2019, 10:38 PM
Nice Article Sir.