×

CSS @keyframes rule

CSS @keyframes rule

It describes the rule of animation that depicts the properties of CSS for the components at every state along with the timeline.

We may make the properties of complex animation with the use of the @keyframe. The animation can be made with the varying styles of CSS that are repeated endlessly or the time’s finite number. A general animation may contain two keyframes, although a complex animation contains various keyframes.

Syntax:

@keyframes animation-name {keyframes-selector {css-styles;}}  

To use the keyframes, we must create the @keyframe rule with the property animation-name to match the animation along with their keyframe declaration.

This property of CSS accepts the three values, which are discussed in detail, as given below:

Property Values

animation-name: This value is a required value, and it represents the animation name.

keyframes-selector: This value describes the percentage with an animation when any keyframe occurs. It has values that lie among 0%-100%, from (similarly as 0%), to (similarly as 100%). The percentage o keyframe can be defined in order because this percentage will be controlled in that order in which they occur.

css-styles:  This property value represents one or above than one property of CSS style.

If any keyframe rules do not define the end and start animation states, then any browser will apply the actual component’s styles. The properties can be ignored that will not be animated inside the keyframe rules.

Timing function of keyframes

To control the rule of animation, we may apply the values discussed as follows:

linear: It specifies the rate of the transition perceptual from start edge to end edge.

ease: It stipulates that animation will start gradually, and after a period of time, the speed will increase, and the speed of before end will slow down again.

ease-in: This function is the same as ease function, although an animation will end quickly.

ease-out: This function is also the same as the ease function, although an animation will start fast.

Let’s understand the @keyframe rule of CSS, along with the following examples.

Example:1

<!DOCTYPE html> 
<html> 
<head> 
<style>  
div 
{ 
width:200px; 
height:200px; 
animation:demo 5s ease-in infinite, trans 5s ease-in-out infinite; 
border-radius:40px; 
} 
@keyframes demo 
{ 
0% {background:orange;} 
50% {background:lime; width:100px; height:100px;} 
100% {background:blue; width:300px; height:300px;} 
} 
@keyframes trans 
{ 
0% {transform:translate(0px) scale(1.4) rotate(80deg);} 
50% {transform:translate(250px) scale(1.2) rotate(40deg);} 
100% {transform:translate(350px) scale(1) rotate(0deg);} 
} 
</style> 
</head> 
<body> 
<div></div> 
<p> The element back off to its real State, after the finalization of an Animation </p> 
</body> 
</html> 

Output:

CSS @keyframes rule

Example:2

<!DOCTYPE html>  
<html>  
<head>  
<style>   
h1
{  
color: black;  
text-align: center;  
}  
div
{  
position: relative;  
animation: exp 7s infinite;  
}  
@keyframes exp
{  
0%
{  
top: 500px;   
width: 0px; 
font-size:10px; 
transform: translate(0px) scale(1.4) rotate(80deg); 
}  
25%
{  
top: 400px;   
background: lime;   
font-size:20px; 
width: 50px;  
transform: translate(100px) scale(1.3) rotate(60deg); 
}  
50%
{  
top: 300px;   
background: tomato; 
font-size:30px; 
width: 150px;  
transform: translate(200px) scale(1.2) rotate(40deg); 
}  
75%
{  
top: 200px;   
background: violet;   
width: 250px;  
font-size:40px; 
transform: translate(300px) scale(1.1) rotate(20deg); 
}  
100%
{  
top: 100px;   
background: blue; 
font-size:50px; 
width: 500px;            
transform: translate(400px) scale(1) rotate(0deg); 
}  
}  
</style>  
</head>  
<body>  
<div>  
<h1> Tutorial and Example </h1>  
</div>  
</body>  
</html>  

Output:

CSS @keyframes rule

Key Points:

There are some key points about the rule are discussed below:

  • We may apply from keyword rather than the use of 0%.
  • We may refer to the keyword rather than the use of 100%.
  • Even when we use from and to keywords, the values among them will be declared within 0%.
  • To a valid animation, the starting time and ending time should be declared.
  • These declarations will get avoided that concerns the !important.

Related Topics

CSS Zoom

CSS Zoom: Zoom property in CSS extents the content. This property controls the content’s level of magnification. Rather than the use of this CSS property, we may also apply the...

3 minutes read.

CSS Background-clip

CSS Background-clip: The background-clip property describes the background’s painting area. It limits an area where the image or color of the background appears by using any clipping box. Everything will...

2 minutes read.

CSS Clip

CSS Clip The Clip property in CSS describes the element’s visible area. It applies over the elements which are absolutely positioned (position: absolute ;). Generally, it is used when an image...

2 minutes read.

CSS Visibility

Visibility in CSS: This visibility property in CSS is employed to describe whether the components are visible or not. Note: An invisible component also grabs the space over the page. If...

2 minutes read.

CSS Font-Size

A Cascading Style Sheet (CSS) is a simple design scripting language intended to simplify the process of making web pages more visually appealing with the kind of high-level formatting. Cascading...

3 minutes read.

CSS Line Height

CSS Line Height: This property in CSS can be used to describe the line box’s minimal height inside the element. It sets-up the distinction among two lines in our content. It...

3 minutes read.

CSS Functions

CSS functions are used for different CSS properties. Every front-end developer should have knowledge of all CSS functions. It makes the coding easier. FunctionsExplanationattr().It returns the value of an attribute of...

5 minutes read.

CSS Units

CSS Units In CSS, there are so many units available to show the length’s measurement. A single unit of CSS is applied to examine the size of the property, which the...

5 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 minutes read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

5 minutes read.

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

CSS Padding

CSS Padding: The padding property in CSS is addressed to describe the space among the element border and the element content.This property is quite different from the margin property of...

2 minutes read.

CSS Form

You can create attractive HTML form by using CSS. Style input Fields The Input Field width properties are used to determine the width of the input field. Let us see an example of CSS style...

2 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.

CSS z-index Property

CSS z-index: CSS z-index permits us to represent any visual hierarchy over a 3D plane that is the z-axis. This index can be applied to describe the positioned element’s stacking...

2 minutes read.

CSS Variables

CSS Variables These variables of CSS are applied to add the custom property values to our various web-pages. The custom properties are often called as CSS variables or cascading variables. Various...

4 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

CSS Background

CSS Background The properties of CSS background are applied to describe the effects of background on the element. Here are five properties of background that affects various elements of HTML: Background-colorBackground-imageBackground-repeatBackground-attachment Background-position Background-color The color of the background...

7 minutes read.