❐CSS❐

❐wD Learn

CSS

CSS Introduction

CSS Selectors

CSS Color

CSS Background

CSS Border

CSS Margin

CSS Padding

CSS Box Model

CSS Text

CSS Font

CSS Link

CSS List

CSS Overflow

CSS Display

CSS Combinators

CSS Pseudo-classes

CSS Navigation Bar

CSS Hover

CSS Z-index

CSS Media Queries

CSS Shadow

CSS 2D Transform

CSS Animations

CSS Button

CSS FlexBox

CSS Grid

CSS Pagination

CSS Animations CSS Animations help to animate elements from one frame to another.

Controlling various CSS properties helps in changing the animation style and time without having the need to use JavaScript for the same.

The most basic way to do so is by using “from” and “to”.

Example



@keyframes demo {
from {
background-color: red;
}
to {
background-color: blue;
}
}
1. Animation Name To identify the animation we assign it with the name. In the above example the name was demo.

So, we will add the attribute animation name in the div element.

Syntax



Syntax:
div { animation-name: demo; }
2. Key Frames Keyframes define at what % of the animation, which stylesheet rules should be used. The value of keyframes varies from 0% to 100%.

To add keyframes use the % operator with the value inside the keyframes. More keyframes mean smoother animation.

Example 3. Looping Animations By default, the animation runs only one time on the website

But you can choose to loop the animation by using the “animation-iteration-count” property.

Syntax



Syntax:
{ animation-iteration-count: value; }
4. Animation Durations It is the key property to start the animations.By default, the animation duration is 0 sec, which means the animation won’t start.

So, to start the animation we will assign the value to the animation duration.

Syntax



Syntax:
animation-duration: value(in sec);
5. Other Properties

Animation Delay

Delays the start of animation on the website.

Adding a negative value to delay will make the animation run even before the website is loaded.

Example



{ animation-delay: -2s; }

Animation Direction

This property defines the order of the animation.

Whether it should be played forward, reverse, or alternatively. The values it takes are:

Syntax



{ animation-direction: value; }

Animation Direction

This property defines the order of the animation.

Whether it should be played forward, reverse, or alternatively. The values it takes are:

Syntax



{ animation-direction: value; }

Animation Timing Function

It defines the speed curve for the animation.

This property adds ease to our animation and can have the following values: ease, linear, ease-in, ease-out, and ease-in-out.

Syntax



animation-timing-function: value;

Animation Fill Mode

This property defines the style of the element when the animation is either stopped or about to start.

The value it takes is none (default state), forwards (value set by the last keyframe), backwards (value of the first keyframe), or both.

Syntax



animation-fill-mode: value;