{"id":3210,"date":"2023-09-03T09:49:49","date_gmt":"2023-09-03T09:49:49","guid":{"rendered":"https:\/\/swatilathia.com\/?page_id=3210"},"modified":"2023-09-05T04:21:32","modified_gmt":"2023-09-05T04:21:32","slug":"css-animation","status":"publish","type":"page","link":"https:\/\/swatilathia.com\/?page_id=3210","title":{"rendered":"CSS Animation"},"content":{"rendered":"<body>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69dd89c98c413\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69dd89c98c413\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#What_is_Animation_in_CSS\" >What is Animation in CSS?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Animation_Properties\" >Animation Properties<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_1_animation-name_and_keyframes_from_%E2%80%93_to\" >Example 1: animation-name and keyframes (from \u2013 to)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_2_animation-name_animation-duration_and_keyframes_in\" >Example 2: animation-name, animation-duration and keyframes (in %)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_3_Color_and_Position_with_keyframes_in\" >Example 3: Color and Position with keyframes (in %)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_4_Animation_timing_function\" >Example 4: Animation timing function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_5_Animation_delay\" >Example 5: Animation delay<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_6_Animation_Iteration_Count\" >Example 6: Animation Iteration Count<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_7_Animation_Direction\" >Example 7: Animation Direction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_8_Animation_fill_mode_%E2%80%93_none\" >Example 8: Animation fill mode \u2013 none<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_9_Animation_fill_mode_%E2%80%93_forwards\" >Example 9: Animation fill mode \u2013 forwards<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_10_Animation_fill_mode_%E2%80%93_backwards\" >Example 10: Animation fill mode \u2013 backwards<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_11_Animation-play-state\" >Example 11: Animation-play-state<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/swatilathia.com\/?page_id=3210\/#Example_12_Animation_Short_Hand_Property\" >Example 12: Animation (Short Hand Property)<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_Animation_in_CSS\"><\/span>What is Animation in CSS?<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>CSS animation is a technique which is used in web development to create dynamic and visually appealing effects on a webpage without the need for complex JavaScript code or external plugins.<\/li>\n\n\n\n<li>It allows you to animate the properties of HTML elements, such as their position, size, color, and opacity, by defining keyframes and transitions using Cascading Style Sheets (CSS).<\/li>\n\n\n\n<li><strong>Keyframes<\/strong>: Keyframes are the foundation of CSS animations. They define the starting and ending points of an animation along with any intermediate stages. Keyframes are defined using the @keyframes rule and specify the percentage of the animation\u2019s progress (from 0% to 100%) at which certain styles should be applied.<\/li>\n\n\n\n<li>If you define CSS styles within the @keyframes rule, the animation will smoothly transition from its current style to the specified new style at specific points in time.<\/li>\n\n\n\n<li>Throughout the animation, it\u2019s possible to modify the CSS styles multiple times.<\/li>\n\n\n\n<li>It indicates the timing of style changes either as a percentage or by using the terms \u2018from\u2019 and \u2018to,\u2019 which are equivalent to 0% and 100%. At 0%, the animation starts, and at 100%, it concludes.<\/li>\n\n\n\n<li><strong>Syntax<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code><code>@keyframes animationname {keyframes-selector {css-styles;}}<\/code><\/code><\/pre>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Here, animationame indicates name of animation.<\/li>\n\n\n\n<li>Keyframes-selector indicates percentage of animation duration. Values may be (0 \u2013 100%) or From (same as 0) to To (same as 100).<\/li>\n\n\n\n<li>CSS-styles indicates one or more CSS style properties.<\/li>\n\n\n\n<li>To apply an animation to an element, you use following CSS properties:<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Animation_Properties\"><\/span>Animation Properties<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-name<\/strong>: It specifies the name of the keyframes animation.<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-duration:<\/strong>\u00a0It sets the duration of the animation in seconds or milliseconds. If this property is not specified, then no animation will occur as its default value if 0s (zero second).<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-timing-function:<\/strong> It\u00a0defines the acceleration and deceleration of the animation. It essentially determines how an animated property changes values as time passes. The values of this property are:<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li class=\"has-medium-font-size\"><strong>ease<\/strong>: This is the default timing function and creates a smooth, gradual acceleration and deceleration. It starts slow, speeds up in the middle, and slows down again at the end of the animation.<\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>linear<\/strong>: This option produces a constant speed animation. It changes properties at a constant rate throughout the animation.<\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>ease-in<\/strong>: It starts slow and then accelerates, creating a quick finish.<\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>ease-out<\/strong>: It starts fast and then decelerates, creating a slow finish.<\/li>\n\n\n\n<li class=\"has-medium-font-size\"><strong>ease-in-out<\/strong>: This timing function combines both easing in and easing out, creating a moderate acceleration and deceleration effect.<\/li>\n<\/ol>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-delay:<\/strong>\u00a0It specifies a delay before the animation starts.<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-iteration-count:<\/strong> It determines how many times the animation should repeat. The value can be either any number, like 1, 2, 3 or \u201cinfinite\u201d to repeat animation indefinitely.<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-direction:<\/strong>\u00a0It sets whether the animation should play forward, backward, or alternate. This property can take the following values:\n<ul class=\"wp-block-list\">\n<li><strong>normal<\/strong> (default): The animation plays forward from the start to the end and then restarts from the beginning. This is the default behavior.<\/li>\n\n\n\n<li><strong>reverse<\/strong>: The animation plays backward from the end to the start and then restarts from the end.<\/li>\n\n\n\n<li><strong>alternate<\/strong>: The animation alternates between playing forward and backward. It starts by playing forward, then plays backward, and so on.<\/li>\n\n\n\n<li><strong>alternate-reverse<\/strong>: Similar to \u201calternate,\u201d but it starts by playing backward, then plays forward, and repeats in that pattern.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-fill-mode: <\/strong>This property determines how the styles of an element are applied before and after the animation is executed. It specifies how the element should behave during the periods before and after the animation runs, which are typically referred to as the \u201canimation\u2019s fill modes.\u201d There are four possible values for the property:\n<ol class=\"wp-block-list\">\n<li><strong>none: <\/strong>This is the default value. It means that the element\u2019s styles are not affected by the animation before or after it runs. The element will immediately switch back to its original styles once the animation completes.<\/li>\n\n\n\n<li><strong>forwards:<\/strong> In this mode, the element retains the computed values of the animation\u2019s final keyframe (the keyframe with a 100% progress) after the animation finishes. This means that the element will stay in its animated state even after the animation has completed.<\/li>\n\n\n\n<li><strong>backwards:<\/strong> In this mode, the element applies the styles of the animation\u2019s initial keyframe (the keyframe with a 0% progress) before the animation starts. This ensures that the element is in the correct starting state before the animation begins.<\/li>\n\n\n\n<li><strong>both:<\/strong> This mode combines the behavior of both <strong>forwards<\/strong> and <strong>backwards.<\/strong> It applies the styles of the initial keyframe before the animation starts and retains the styles of the final keyframe after it completes.<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation-play-state<\/strong>: This property specifies whether the animation is <strong>running<\/strong> or <strong>paused<\/strong>.<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li><strong>animation: <\/strong>This is shorthand property to set all the animation properties.<\/li>\n\n\n\n<li>To understand all these properties, let us take one by one example of each property.<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us start with simple example to animate &lt;div&gt; element. The animation will last for 5 seconds, and it will gradually change the background-color of the &lt;div&gt; element from \u201cpink\u201d to \u201cpurple\u201d.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_1_animation-name_and_keyframes_from_%E2%80%93_to\"><\/span>Example 1: animation-name and keyframes (from \u2013 to)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;style&gt; \n\t\t\t#d_ex1\n\t\t\t{\n\t\t\t\twidth:200px;\n\t\t\t\theight:200px;\n\t\t\t\tbackground-color:pink;\n\t\t\t\tanimation-name:ex1;\n\t\t\t\tanimation-duration:5s;\n\t\t\t}\n\t\t\t@keyframes ex1 \n\t\t\t{\n\t\t\t\tfrom \n\t\t\t\t{\n\t\t\t\t\tbackground-color:pink;\n\t\t\t\t}\n\t\t\t\tto \n\t\t\t\t{\n\t\t\t\t\tbackground-color:purple;\n\t\t\t\t}\n\t\t\t}\n\t\t&lt;\/style&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\n                &lt;b&gt;This animation takes 5 seconds to complete&lt;\/b&gt;&lt;br&gt;\n\t\t&lt;div id='d_ex1'&gt;&lt;\/div&gt;\n\t\t&lt;B&gt;When an animation is completed, \n\t\tit goes back to its original style\/color.&lt;\/B&gt;\n\t\t&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\t\n\t\t<style> \n\t\t\t#d_ex1\n\t\t\t{\n\t\t\t\twidth:200px;\n\t\t\t\theight:200px;\n\t\t\t\tbackground-color:pink;\n\t\t\t\tanimation-name:ex1;\n\t\t\t\tanimation-duration:5s;\n\t\t\t}\n\t\t\t@keyframes ex1 \n\t\t\t{\n\t\t\t\tfrom \n\t\t\t\t{\n\t\t\t\t\tbackground-color:pink;\n\t\t\t\t}\n\t\t\t\tto \n\t\t\t\t{\n\t\t\t\t\tbackground-color:purple;\n\t\t\t\t}\n\t\t\t}\n\t\t<\/style>\n\t\n\t\n\n                <b>This animation takes 5 seconds to complete<\/b><br>\n\t\t<div id=\"d_ex1\"><\/div>\n\t\t<b>When an animation is completed, \n\t\tit goes back to its original style\/color.<\/b>\n\t\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>We can also use percentage as shown in following example.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_2_animation-name_animation-duration_and_keyframes_in\"><\/span>Example 2: animation-name, animation-duration and keyframes (in %)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;style&gt;\n\t\t\t#d_ex2\n\t\t\t{\n\t\t\t\twidth: 100px;\n\t\t\t\theight: 100px;\n\t\t\t\tbackground-color:pink;\n\t\t\t\tanimation-name:ex2;\n\t\t\t\tanimation-duration:5s;\n\t\t\t}\n\t\t\t@keyframes ex2 \n\t\t\t{\n\t\t\t\t0%   {background-color: pink;}\n\t\t\t\t25%  {background-color: orange;}\n\t\t\t\t50%  {background-color: red;}\n\t\t\t\t100% {background-color: purple;}\n\t\t\t}\n\t\t&lt;\/style&gt;\n\t&lt;\/head&gt;\n\t&lt;body&gt;\n\t\t&lt;div id='d_ex2'&gt;&lt;\/div&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\t\n\t\t<style>\n\t\t\t#d_ex2\n\t\t\t{\n\t\t\t\twidth: 100px;\n\t\t\t\theight: 100px;\n\t\t\t\tbackground-color:pink;\n\t\t\t\tanimation-name:ex2;\n\t\t\t\tanimation-duration:5s;\n\t\t\t}\n\t\t\t@keyframes ex2 \n\t\t\t{\n\t\t\t\t0%   {background-color: pink;}\n\t\t\t\t25%  {background-color: orange;}\n\t\t\t\t50%  {background-color: red;}\n\t\t\t\t100% {background-color: purple;}\n\t\t\t}\n\t\t<\/style>\n\t\n\t\n\t\t<div id=\"d_ex2\"><\/div>\n\t\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us take another example that will change both the background-color and the position of the &lt;div&gt; element when the animation is 25% complete, 50% complete, and again when the animation is 100% complete.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_3_Color_and_Position_with_keyframes_in\"><\/span>Example 3: Color and Position with keyframes (in %)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt; \n#d_ex3\n{\n  width: 100px;\n  height: 100px;\n  background-color: pink;\n  position: relative;\n  animation-name: ex3;\n  animation-duration: 4s;\n}\n\n@keyframes ex3\n{\n  0%   {background-color:pink; left:0px; top:0px;}\n  25%  {background-color:orange; left:200px; top:0px;}\n  50%  {background-color:yellow; left:200px; top:200px;}\n  75%  {background-color:purple; left:0px; top:200px;}\n  100% {background-color:red; left:0px; top:0px;}\n}\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\t&lt;div id='d_ex3'&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\r\n\r\n\r\n<style> \r\n#d_ex3\r\n{\r\n  width: 100px;\r\n  height: 100px;\r\n  background-color: pink;\r\n  position: relative;\r\n  animation-name: ex3;\r\n  animation-duration: 4s;\r\n}\r\n\r\n@keyframes ex3\r\n{\r\n  0%   {background-color:pink; left:0px; top:0px;}\r\n  25%  {background-color:orange; left:200px; top:0px;}\r\n  50%  {background-color:yellow; left:200px; top:200px;}\r\n  75%  {background-color:purple; left:0px; top:200px;}\r\n  100% {background-color:red; left:0px; top:0px;}\r\n}\r\n<\/style>\r\n\r\n\r\n\t\t<div id=\"d_ex3\"><\/div>\r\n\r\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us take another example with <strong>animation-timing-function<\/strong> property<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_4_Animation_timing_function\"><\/span>Example 4: Animation timing function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;style&gt;\n\t\t\t#d_l,#d_e,#d_ei,#d_eo,#d_eio\n\t\t\t{\n\t\t\t\twidth:100px;\n\t\t\t\theight:50px;\n\t\t\t\tbackground-color:purple;\n\t\t\t\tanimation-name:anim_time_fun;\n\t\t\t\tanimation-duration:5s;\t\n\t\t\t\tposition:relative;\n\t\t\t\tcolor:white;\n\t\t\t}\n\t\t\t@keyframes anim_time_fun\n\t\t\t{\n\t\t\t\tfrom{left:0px;}\n\t\t\t\tto{left:300px;}\n\t\t\t}\n\t\t\t#d_l{animation-timing-function:linear;}\n\t\t\t#d_e{animation-timing-function:ease;}\n\t\t\t#d_ei{animation-timing-function:ease-in;}\n\t\t\t#d_eo{animation-timing-function:ease-out;}\n\t\t\t#d_eio{animation-timing-function:ease-in-out;}\n\t\t&lt;\/style&gt;\n\t&lt;head&gt;\n\t&lt;body&gt;\n\t\t&lt;div id='d_l'&gt;I am Linear&lt;\/div&gt;\n\t\t&lt;div id='d_e'&gt;I am Ease&lt;\/div&gt;\n\t\t&lt;div id='d_ei'&gt;I am Ease-In&lt;\/div&gt;\n\t\t&lt;div id='d_eo'&gt;I am Ease-Out&lt;\/div&gt;\n\t\t&lt;div id='d_eio'&gt;I am Ease-In-Out&lt;\/div&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\r\n\r\n\t\r\n\t\t<style>\r\n\t\t\t#d_l,#d_e,#d_ei,#d_eo,#d_eio\r\n\t\t\t{\r\n\t\t\t\twidth:100px;\r\n\t\t\t\theight:50px;\r\n\t\t\t\tbackground-color:purple;\r\n\t\t\t\tanimation-name:anim_time_fun;\r\n\t\t\t\tanimation-duration:5s;\t\r\n\t\t\t\tposition:relative;\r\n\t\t\t\tcolor:white;\r\n\t\t\t}\r\n\t\t\t@keyframes anim_time_fun\r\n\t\t\t{\r\n\t\t\t\tfrom{left:0px;}\r\n\t\t\t\tto{left:300px;}\r\n\t\t\t}\r\n\t\t\t#d_l{animation-timing-function:linear;}\r\n\t\t\t#d_e{animation-timing-function:ease;}\r\n\t\t\t#d_ei{animation-timing-function:ease-in;}\r\n\t\t\t#d_eo{animation-timing-function:ease-out;}\r\n\t\t\t#d_eio{animation-timing-function:ease-in-out;}\r\n\t\t<\/style>\r\n\t\r\n\t\r\n\t\t<div id=\"d_l\">I am Linear<\/div>\r\n\t\t<div id=\"d_e\">I am Ease<\/div>\r\n\t\t<div id=\"d_ei\">I am Ease-In<\/div>\r\n\t\t<div id=\"d_eo\">I am Ease-Out<\/div>\r\n\t\t<div id=\"d_eio\">I am Ease-In-Out<\/div>\r\n\t\r\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us take another example with <strong>animation-delay<\/strong> property<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_5_Animation_delay\"><\/span>Example 5: Animation delay<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;style&gt;\n\t\t\t#d_delay\n\t\t\t{\n\t\t\t\tfont-size:100px;\n\t\t\t\tanimation-name:anim_delay;\n\t\t\t\tanimation-duration:5s;\t\n\t\t\t\tposition:relative;\n\t\t\t\tanimation-delay:2s;\n\t\t\t}\n\t\t\t@keyframes anim_delay\n\t\t\t{\n\t\t\t\tfrom{left:0px;}\n\t\t\t\tto{left:300px;}\n\t\t\t}\n\t\t\t\t\n\t\t&lt;\/style&gt;\n\t&lt;head&gt;\n\t&lt;body&gt;\n                &lt;b&gt;I will start after 2 seconds&lt;\/b&gt;\n\t\t&lt;div id='d_delay'&gt;&amp;#128675;&lt;\/div&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\t\n\t\t<style>\n\t\t\t#d_delay\n\t\t\t{\n\t\t\t\tfont-size:100px;\n\t\t\t\tanimation-name:anim_delay;\n\t\t\t\tanimation-duration:5s;\t\n\t\t\t\tposition:relative;\n\t\t\t\tanimation-delay:2s;\n\t\t\t}\n\t\t\t@keyframes anim_delay\n\t\t\t{\n\t\t\t\tfrom{left:0px;}\n\t\t\t\tto{left:300px;}\n\t\t\t}\n\t\t<\/style>\n\t\n\t\n                <b>I will start after 2 seconds<\/b>\n\t\t<div id=\"d_delay\">\ud83d\udea3<\/div>\n\t\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us check another example with <strong>animation-iteration-count<\/strong> property<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_6_Animation_Iteration_Count\"><\/span>Example 6: Animation Iteration Count<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;style&gt;\n\t\t\t#it_count\n\t\t\t{\n\t\t\t\tfont-size:100px;\n\t\t\t\tanimation-name:iter_count;\n\t\t\t\tanimation-duration:5s;\t\n\t\t\t\tposition:relative;\n\t\t\t\tanimation-iteration-count:infinite;\n\t\t\t}\n\t\t\t@keyframes iter_count\n\t\t\t{\n\t\t\t\tfrom{left:0px;}\n\t\t\t\tto{left:500px;}\n\t\t\t}\n\t\t&lt;\/style&gt;\n\t&lt;head&gt;\n\t&lt;body&gt;\n        &lt;b&gt;I am infinite animation&lt;\/b&gt;\n\t\t&lt;div id='it_count'&gt;&amp;#128675;&lt;\/div&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\r\n\r\n\t\r\n\t\t<style>\r\n\t\t\t#it_count\r\n\t\t\t{\r\n\t\t\t\tfont-size:100px;\r\n\t\t\t\tanimation-name:iter_count;\r\n\t\t\t\tanimation-duration:5s;\t\r\n\t\t\t\tposition:relative;\r\n\t\t\t\tanimation-iteration-count:infinite;\r\n\t\t\t}\r\n\t\t\t@keyframes iter_count\r\n\t\t\t{\r\n\t\t\t\tfrom{left:0px;}\r\n\t\t\t\tto{left:500px;}\r\n\t\t\t}\r\n\t\t<\/style>\r\n\t\r\n\t\r\n        <b>I am infinite animation<\/b>\r\n\t\t<div id=\"it_count\">\ud83d\udea3<\/div>\r\n\t\r\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us check another example with <strong>animation-direction<\/strong> property<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_7_Animation_Direction\"><\/span>Example 7: Animation Direction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n\t&lt;head&gt;\n\t\t&lt;style&gt;\n\t\t\t#animat_dir1\n\t\t\t{\n\t\t\t\tfont-size:80px;\n\t\t\t\tanimation-name:anim_dir1;\n\t\t\t\tanimation-duration:5s;\t\n\t\t\t\tposition:relative;\n\t\t\t\tanimation-direction:reverse;\n\t\t\t\tanimation-iteration-count:2;\n\t\t\t}\n\t\t\t@keyframes anim_dir1\n\t\t\t{\n\t\t\t\t0%{left:0px;top:0px;}\n\t\t\t\t25%{left:400px;top:0px;}\n\t\t\t\t50%{left:400px;top:400px;}\n\t\t\t\t75%{left:0px;top:400px;}\n\t\t\t\t100%{left:0px;top:0px;}\n\t\t\t}\n\t\t&lt;\/style&gt;\n\t&lt;head&gt;\n\t&lt;body&gt;\n        &lt;div id='animat_dir1'&gt;&amp;#128675;&lt;\/div&gt;\n\t&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\t\n\t\t<style>\n\t\t\t#animat_dir1\n\t\t\t{\n\t\t\t\tfont-size:80px;\n\t\t\t\tanimation-name:anim_dir1;\n\t\t\t\tanimation-duration:5s;\t\n\t\t\t\tposition:relative;\n\t\t\t\tanimation-direction:reverse;\n                                \/* normal or alternate or alternate-reverse *\/\n\t\t\t\tanimation-iteration-count:2;\n\t\t\t}\n\t\t\t@keyframes anim_dir1\n\t\t\t{\n\t\t\t\t0%{left:0px;top:0px;}\n\t\t\t\t25%{left:400px;top:0px;}\n\t\t\t\t50%{left:400px;top:400px;}\n\t\t\t\t75%{left:0px;top:400px;}\n\t\t\t\t100%{left:0px;top:0px;}\n\t\t\t}\n\t\t<\/style>\n\t\n\t\n        <div id=\"animat_dir1\">\ud83d\udea3<\/div>\n\t\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us check another example with <strong>animation-fill-mode<\/strong> property<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_8_Animation_fill_mode_%E2%80%93_none\"><\/span>Example 8: Animation fill mode \u2013 none<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n\t&lt;style&gt;\n\t\t.div_none \n\t\t{\n\t\t\twidth: 100px;\n\t\t\theight: 100px;\n\t\t\tbackground-color:skyblue;\n\t\t\tanimation-name: example_slide;\n\t\t\tanimation-duration:5s;\n\t\t\tanimation-fill-mode:none;\n\t\t}\n\t\t@keyframes example_slide \n\t\t{\n\t\t\t0% \n\t\t\t{\n\t\t\t\ttransform: translateX(0);\n\t\t\t}\n\t\t\t100% \n\t\t\t{\n\t\t\t\ttransform: translateX(200px);\n\t\t\t}\n\t\t}\n\t&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\n        &lt;b&gt;This division gets back to its original position after animation&lt;\/b&gt;\n\t&lt;div class=div_none&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\n\t<style>\n\t\t.div_none \n\t\t{\n\t\t\twidth: 100px;\n\t\t\theight: 100px;\n\t\t\tbackground-color:skyblue;\n\t\t\tanimation-name: example_slide;\n\t\t\tanimation-duration:5s;\n\t\t\tanimation-fill-mode:none;\n\t\t}\n\t\t@keyframes example_slide \n\t\t{\n\t\t\t0% \n\t\t\t{\n\t\t\t\ttransform: translateX(0);\n\t\t\t}\n\t\t\t100% \n\t\t\t{\n\t\t\t\ttransform: translateX(200px);\n\t\t\t}\n\t\t}\n\t<\/style>\n\n\n        <b>This division gets back to its original position after animation<\/b>\n\t<div class=\"div_none\"><\/div>\n\n\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_9_Animation_fill_mode_%E2%80%93_forwards\"><\/span>Example 9: Animation fill mode \u2013 forwards<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n\t&lt;style&gt;\n\t\t.div_for \n\t\t{\n\t\t\twidth: 100px;\n\t\t\theight: 100px;\n\t\t\tbackground-color:skyblue;\n\t\t\tanimation-name: example_slide1;\n\t\t\tanimation-duration:5s;\n\t\t\tanimation-fill-mode:forwards;\n\t\t}\n\t\t@keyframes example_slide1 \n\t\t{\n\t\t\t0% \n\t\t\t{\n\t\t\t\ttransform: translateX(0);\n\t\t\t}\n\t\t\t100% \n\t\t\t{\n\t\t\t\ttransform: translateX(200px);\n\t\t\t}\n\t\t}\n\t&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n        &lt;b&gt;This division retains its animated value after the animation&lt;\/b&gt;\n\t&lt;div class=div_for&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\n\t<style>\n\t\t.div_for \n\t\t{\n\t\t\twidth: 100px;\n\t\t\theight: 100px;\n\t\t\tbackground-color:skyblue;\n\t\t\tanimation-name: example_slide1;\n\t\t\tanimation-duration:5s;\n\t\t\tanimation-fill-mode:forwards;\n\t\t}\n\t\t@keyframes example_slide1 \n\t\t{\n\t\t\t0% \n\t\t\t{\n\t\t\t\ttransform: translateX(0);\n\t\t\t}\n\t\t\t100% \n\t\t\t{\n\t\t\t\ttransform: translateX(200px);\n\t\t\t}\n\t\t}\n\t<\/style>\n\n\n        <b>This division retains its animated value after the animation<\/b>\n\t<div class=\"div_for\"><\/div>\n\n\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_10_Animation_fill_mode_%E2%80%93_backwards\"><\/span>Example 10: Animation fill mode \u2013 backwards<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.d_back \n{\n  width: 100px;\n  height: 100px;\n  background-color: red;\n  animation-name: scale_anim;\n  animation-duration: 2s;\n  animation-fill-mode: backwards;\n}\n\n@keyframes scale_anim \n{\n  0% \n  {\n    transform: scale(0);\n    background-color: green;\n  }\n  100% \n  {\n    transform: scale(1);\n    background-color: blue;\n  }\n}\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=\"d_back\"&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\n<style>\n.d_back \n{\n  width: 100px;\n  height: 100px;\n  background-color: red;\n  animation-name: scale_anim;\n  animation-duration: 2s;\n  animation-fill-mode: backwards;\n}\n@keyframes scale_anim \n{\n  0% \n  {\n    transform: scale(0);\n    background-color: green;\n  }\n  100% \n  {\n    transform: scale(1);\n    background-color: blue;\n  }\n}\n<\/style>\n\n\n  <div class=\"d_back\"><\/div>\n\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>In above example, we have a div element with the class \u201cd_back.\u201d We define a CSS animation called scale_anim that scales the box from scale(0) to scale(1) and changes its background color from green to blue.<\/li>\n\n\n\n<li>With<strong><em> \u201d animation-fill-mode:backwards <\/em>\u201c<\/strong>, the following happens\n<ol class=\"wp-block-list\">\n<li>Even before the animation starts, the box is styled according to the properties defined at 0% in the keyframes (scale(0) and background-color: green).<\/li>\n\n\n\n<li>When the animation starts, it continues from this initial state and proceeds to the final state defined at 100% in the keyframes (scale(1) and background-color: blue).<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us take example of <strong>animation-play-state<\/strong> property.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_11_Animation-play-state\"><\/span>Example 11: Animation-play-state<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.d_anim1\n{\n  width: 100px;\n  height: 100px;\n  background-color: red;\n  animation:anim 5s reverse;\n}\n.d_anim1:hover\n{\n\tanimation-play-state:paused;\n}\n@keyframes anim \n{\n  0% \n  {\n    transform: scale(0);\n    background-color: green;\n  }\n  100% \n  {\n    transform: scale(1);\n    background-color: blue;\n  }\n}\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=\"d_anim1\"&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\n<style>\n.d_anim1\n{\n  width: 100px;\n  height: 100px;\n  background-color: red;\n  animation:anim 5s reverse;\n}\n.d_anim1:hover\n{\n\tanimation-play-state:paused;\n}\n@keyframes anim \n{\n  0% \n  {\n    transform: scale(0);\n    background-color: green;\n  }\n  100% \n  {\n    transform: scale(1);\n    background-color: blue;\n  }\n}\n<\/style>\n\n\n  <div class=\"d_anim1\"><\/div>\n\n\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us check final property \u2013 <strong>animation<\/strong> (short hand property) with example<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_12_Animation_Short_Hand_Property\"><\/span>Example 12: Animation (Short Hand Property)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.d_anim \n{\n  width: 100px;\n  height: 100px;\n  background-color: red;\n  animation:anim 5s 3s infinite reverse;\n}\n\n@keyframes anim \n{\n  0% \n  {\n    transform: scale(0);\n    background-color: green;\n  }\n  100% \n  {\n    transform: scale(1);\n    background-color: blue;\n  }\n}\n&lt;\/style&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=\"d_anim\"&gt;&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Output<\/strong><\/p>\n\n\n\n\n\n\n<style>\n.d_anim \n{\n  width: 100px;\n  height: 100px;\n  background-color: red;\n  animation:anim 5s 3s infinite reverse; \n}\n\n@keyframes anim \n{\n  0% \n  {\n    transform: scale(0);\n    background-color: green;\n  }\n  100% \n  {\n    transform: scale(1);\n    background-color: blue;\n  }\n}\n<\/style>\n\n\n  <div class=\"d_anim\"><\/div>\n\n\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">In above example, we have combined animation-name, animation-duration, animation-delay, animation-iteration-count and animation-direction properties in one <strong>animation<\/strong> property.<\/li>\n<\/ul>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>What is Animation in CSS? Animation Properties Example 1: animation-name and keyframes (from \u2013 to) Output This animation takes 5 seconds to complete When an animation is completed, it goes back to its original style\/color. Example 2: animation-name, animation-duration and keyframes (in %) Output Example 3: Color and Position with keyframes (in %) Output Example [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":678,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"om_disable_all_campaigns":false,"footnotes":""},"class_list":["post-3210","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/3210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3210"}],"version-history":[{"count":37,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/3210\/revisions"}],"predecessor-version":[{"id":3292,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/3210\/revisions\/3292"}],"up":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/678"}],"wp:attachment":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}