{"id":4954,"date":"2020-06-10T14:29:00","date_gmt":"2020-06-10T14:29:00","guid":{"rendered":"https:\/\/azoora.com\/blog\/?p=4954"},"modified":"2020-11-22T12:35:06","modified_gmt":"2020-11-22T12:35:06","slug":"css-animation-for-beginners","status":"publish","type":"post","link":"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/","title":{"rendered":"Tutorial &#8211; CSS Animation for Beginners"},"content":{"rendered":"\n<p>The human brain is hardwired to pay attention to moving objects. Because of this natural reflex to notice movement, adding animation to your website or app is a powerful way to draw user&#8217;s attention to important areas of your product and add interest to your interface.<\/p>\n\n\n\n<p>When done well, animations can add valuable interaction and feedback, as well as enhance the emotional experience, bring delight, and add personality to your interface. In fact,&nbsp;<em>to animate<\/em>&nbsp;means&nbsp;<em>to bring to life.<\/em><\/p>\n\n\n\n<p>In this post we\u2019re going to walk through the basics of&nbsp;<abbr title=\"Cascading\nStyle Sheets\">CSS<\/abbr>&nbsp;animation. You can&nbsp;<a href=\"http:\/\/codepen.io\/collection\/nbEZgX\/\">follow along and view the CSS code<\/a>&nbsp;for the example animations in this post.<\/p>\n\n\n\n<h2 id=\"the-building-blocks-of-animations\">The Building Blocks of Animations<\/h2>\n\n\n\n<p>CSS animations are made up of two basic building blocks.<\/p>\n\n\n\n<ol><li><strong>Keyframes<\/strong>&nbsp;&#8211; define the stages and styles of the animation.<\/li><li><strong>Animation Properties<\/strong>&nbsp;&#8211; assign the @keyframes to a specific CSS element and define&nbsp;<em>how<\/em>&nbsp;it is animated.<\/li><\/ol>\n\n\n\n<p>Let\u2019s look at each individually.<\/p>\n\n\n\n<h2 id=\"building-block-1-keyframes\">Building Block #1: Keyframes<\/h2>\n\n\n\n<p>Keyframes are the foundation of&nbsp;<abbr title=\"Cascading Style Sheets\">CSS<\/abbr>&nbsp;animations. They define what the animation looks like at each stage of the animation timeline. Each&nbsp;<code>@keyframes<\/code>&nbsp;is composed of:<\/p>\n\n\n\n<ul><li><strong>Name of the animation:<\/strong>&nbsp;A name that describes the animation, for example,&nbsp;<code>bounceIn<\/code>.<\/li><li><strong>Stages of the animation:<\/strong>&nbsp;Each stage of the animation is represented as a percentage.&nbsp;<code>0%<\/code>&nbsp;represents the beginning state of the animation.&nbsp;<code>100%<\/code>&nbsp;represents the ending state of the animation. Multiple intermediate states can be added in between.<\/li><li><strong>CSS Properties:<\/strong>&nbsp;The CSS properties defined for each stage of the animation timeline.<\/li><\/ul>\n\n\n\n<p>Let\u2019s take a look at a simple&nbsp;<code>@keyframes<\/code>&nbsp;I\u2019ve named \u201cbounceIn\u201d. This&nbsp;<code>@keyframes<\/code>&nbsp;has three stages. At the first stage&nbsp;<code>(0%)<\/code>, the element is at opacity 0 and scaled down to 10 percent of its default size, using CSS transform scale. At the second stage&nbsp;<code>(60%)<\/code>&nbsp;the element fades in to full opacity and grows to 120 percent of its default size. At the final stage&nbsp;<code>(100%)<\/code>, it scales down slightly and returns to its default size.<\/p>\n\n\n\n<p>The&nbsp;<code>@keyframes<\/code>&nbsp;are added to your main CSS file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@keyframes bounceIn {\n  0% {\n    transform: scale(0.1);\n    opacity: 0;\n  }\n  60% {\n    transform: scale(1.2);\n    opacity: 1;\n  }\n  100% {\n    transform: scale(1);\n  }\n}\n<\/code><\/pre>\n\n\n\n<p>(If you\u2019re unfamiliar with CSS Transforms, you\u2019ll want to&nbsp;<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/transform\">brush up on your knowledge.<\/a>&nbsp;Combining CSS transforms in the animations is really where the magic happens.)<\/p>\n\n\n\n<h2 id=\"building-block-2-animation-properties\">Building Block #2: Animation Properties<\/h2>\n\n\n\n<p>Once the&nbsp;<code>@keyframes<\/code>&nbsp;are defined, the animation properties must be added in order for your animation to function.<\/p>\n\n\n\n<p>Animation properties do two things:<\/p>\n\n\n\n<ol><li>They assign the&nbsp;<code>@keyframes<\/code>&nbsp;to the elements that you want to animate.<\/li><li>They define&nbsp;<em>how<\/em>&nbsp;it is animated.<\/li><\/ol>\n\n\n\n<p>The animation properties are added to the CSS selectors (or elements) that you want to animate. You must add the following two animation properties for the animation to take effect:<\/p>\n\n\n\n<ul><li><code>animation-name<\/code>: The name of the animation, defined in the&nbsp;<code>@keyframes<\/code>.<\/li><li><code>animation-duration<\/code>: The duration of the animation, in seconds (e.g., 5s) or milliseconds (e.g., 200ms).<\/li><\/ul>\n\n\n\n<p>Continuing with the above&nbsp;<code>bounceIn<\/code>&nbsp;example, we\u2019ll add&nbsp;<code>animation-name<\/code>&nbsp;and&nbsp;<code>animation-duration<\/code>&nbsp;to the div that we want to animate.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  animation-duration: 2s;\n  animation-name: bounceIn;\n}<\/code><\/pre>\n\n\n\n<p>Shorthand syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  animation: bounceIn 2s;\n}<\/code><\/pre>\n\n\n\n<p>By adding both the @keyframes and the animation properties, we have a simple animation!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4955\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/attachment\/animation-bouncein\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-bounceIn.gif\" data-orig-size=\"499,358\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"animation-bounceIn\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-bounceIn-300x215.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-bounceIn.gif\" loading=\"lazy\" width=\"499\" height=\"358\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-bounceIn.gif\" alt=\"\" class=\"wp-image-4955\"\/><\/figure>\n\n\n\n<h2 id=\"animation-property-shorthand\">Animation Property Shorthand<\/h2>\n\n\n\n<p>Each animation property can be defined individually, but for cleaner and faster code, it\u2019s recommended that you use the animation shorthand. All the animation properties are added to the same&nbsp;<code>animation:<\/code>&nbsp;property in the following order:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation: [animation-name] [animation-duration] [animation-timing-function]\n[animation-delay] [animation-iteration-count] [animation-direction]\n[animation-fill-mode] [animation-play-state];<\/code><\/pre>\n\n\n\n<p>Just remember for the animation to function correctly, you need to follow the proper shorthand order AND specify at least the first two values.<\/p>\n\n\n\n<h2 id=\"note-about-prefixes\">Note About Prefixes<\/h2>\n\n\n\n<p>As of late 2014, many Webkit based browsers&nbsp;<a href=\"http:\/\/caniuse.com\/#feat=css-animation\">still use<\/a>&nbsp;the -webkit-prefixed version of both animations, keyframes, and transitions. Until they adopt the standard version, you\u2019ll want to include both unprefixed and Webkit versions in your code. (For simplicity, I\u2019ll only be using the unprefixed versions in my examples.)<\/p>\n\n\n\n<p>Keyframes and animations with WebKit prefixes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  -webkit-animation-duration: 2s;\n  animation-duration: 2s;\n  -webkit-animation-name: bounceIn;\n  animation-name: bounceIn;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@-webkit-keyframes bounceIn { \/* styles *\/ }\n@keyframes bounceIn { \/* styles *\/ }<\/code><\/pre>\n\n\n\n<p>To make your life easier, consider using&nbsp;<a href=\"http:\/\/bourbon.io\/\">Bourbon<\/a>, a Sass mixin library which contains up-to-date vendor prefixes for all modern browsers. Here\u2019s how simple it is to generate vendor-prefixed animations and keyframes using Bourbon:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>div {\n  @include animation(bounceIn 2s);\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@include keyframes(bouncein) { \/* styles *\/}<\/code><\/pre>\n\n\n\n<h2 id=\"additional-animation-properties\">Additional Animation Properties<\/h2>\n\n\n\n<p>In addition to the required&nbsp;<strong>animation-name<\/strong>&nbsp;and&nbsp;<strong>animation-duration<\/strong>&nbsp;properties, you can further customize and create complex animations using the following properties:<\/p>\n\n\n\n<ul><li><code>animation-timing-function<\/code><\/li><li><code>animation-delay<\/code><\/li><li><code>animation-iteration-count<\/code><\/li><li><code>animation-direction<\/code><\/li><li><code>animation-fill-mode<\/code><\/li><li><code>animation-play-state<\/code><\/li><\/ul>\n\n\n\n<p>Let\u2019s look at each of them individually.<\/p>\n\n\n\n<h2 id=\"animation-timing-function\">Animation-timing-function<\/h2>\n\n\n\n<p>The&nbsp;<code>animation-timing-function:<\/code>&nbsp;defines the speed curve or pace of the animation. You can specify the timing with the following predefined timing options:&nbsp;<code>ease<\/code>,&nbsp;<code>linear<\/code>,&nbsp;<code>ease-in<\/code>,&nbsp;<code>ease-out<\/code>,&nbsp;<code>ease-in-out<\/code>,&nbsp;<code>initial<\/code>,&nbsp;<code>inherit<\/code>. (Or for more advanced timing options, you can creating custom timing functions using&nbsp;<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/timing-function\">cubic-bezier curve<\/a>.)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4956\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/attachment\/animation-timing\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-timing.gif\" data-orig-size=\"431,315\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"animation-timing\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-timing-300x219.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-timing.gif\" loading=\"lazy\" width=\"431\" height=\"315\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-timing.gif\" alt=\"\" class=\"wp-image-4956\"\/><\/figure>\n\n\n\n<p>The default value, if no other value is assigned, is&nbsp;<code>ease<\/code>, which starts out slow, speeds up, then slows down. You can read a description of each timing function&nbsp;<a href=\"http:\/\/www.w3schools.com\/cssref\/css3_pr_animation-timing-function.asp\">here<\/a>.<\/p>\n\n\n\n<p>CSS syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation-timing-function: ease-in-out;<\/code><\/pre>\n\n\n\n<p>Animation shorthand syntax (recommended):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation: [animation-name] [animation-duration] [animation-timing-function];\nanimation: bounceIn 2s ease-in-out;<\/code><\/pre>\n\n\n\n<h2 id=\"animation-delay\">Animation-Delay<\/h2>\n\n\n\n<p>The&nbsp;<code>animation-delay:<\/code>&nbsp;allows you to specify when the animation (or pieces of the animation) will start. A positive value (such as 2s) will start the animation 2 seconds after it is triggered. The element will remain unanimated until that time. A negative value (such as -2s) will start the animation at once, but starts 2 seconds into the animation.<\/p>\n\n\n\n<p>The value is defined in seconds (s) or milliseconds (mil).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4957\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/attachment\/animation-delay\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-delay.gif\" data-orig-size=\"539,428\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"animation-delay\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-delay-300x238.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-delay.gif\" loading=\"lazy\" width=\"539\" height=\"428\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-delay.gif\" alt=\"\" class=\"wp-image-4957\"\/><\/figure>\n\n\n\n<p>CSS syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation-delay: 5s;<\/code><\/pre>\n\n\n\n<p>Animation shorthand syntax (recommended):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation: [animation-name] [animation-duration] [animation-timing-function]\n[animation-delay];\nanimation:  bounceIn 2s ease-in-out 3s;<\/code><\/pre>\n\n\n\n<h2 id=\"animation-iteration-count\">Animation-iteration-count<\/h2>\n\n\n\n<p>The&nbsp;<code>animation-iteration-count:<\/code>&nbsp;specifies the number of times that the animation will play. The possible values are:<\/p>\n\n\n\n<p><code>#<\/code>&#8211; a specific number of iterations (default is&nbsp;<code>1<\/code>)<\/p>\n\n\n\n<p><code>infinite<\/code>&nbsp;&#8211; the animation repeats forever<\/p>\n\n\n\n<p><code>initial<\/code>&nbsp;&#8211; sets the iteration count to the default value<\/p>\n\n\n\n<p><code>inherit<\/code>&nbsp;&#8211; inherits the value from the parent<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4958\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/attachment\/animation-iteration\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-iteration.gif\" data-orig-size=\"499,358\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"animation-iteration\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-iteration-300x215.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-iteration.gif\" loading=\"lazy\" width=\"499\" height=\"358\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-iteration.gif\" alt=\"\" class=\"wp-image-4958\"\/><\/figure>\n\n\n\n<p>CSS syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation-iteration-count: 2;<\/code><\/pre>\n\n\n\n<p>Animation shorthand syntax (recommended):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation: [animation-name] [animation-duration] [animation-timing-function]\n[animation-delay] [animation-iteration-count];\nanimation:  bounceIn 2s ease-in-out 3s 2;<\/code><\/pre>\n\n\n\n<h2 id=\"animation-direction\">Animation-direction<\/h2>\n\n\n\n<p>The&nbsp;<code>animation-direction:<\/code>&nbsp;property specifies whether the animation should play forward, reverse, or in alternate cycles.<\/p>\n\n\n\n<p>The possible values are:<\/p>\n\n\n\n<p><code>normal<\/code>&nbsp;(default) &#8211; The animation plays forward. On each cycle the animation resets to the beginning state (0%) and plays forward again (to 100%).<\/p>\n\n\n\n<p><code>reverse<\/code>&nbsp;&#8211; The animation plays backwards. On each cycle the animation resets to the end state (100%) and plays backwards (to 0%).<\/p>\n\n\n\n<p><code>alternate<\/code>&nbsp;&#8211; The animation reverses direction every cycle. On each odd cycle, the animation plays forward (0% to 100%). On each even cycle, the animation plays backwards (100% to 0%).<\/p>\n\n\n\n<p><code>alternate-reverse<\/code>&nbsp;&#8211; The animation reverses direction every cycle. On each odd cycle, the animation plays in reverse (100% to 0%). On each even cycle, the animation plays forward (0% or 100%).<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4959\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/attachment\/animation-direction\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-direction.gif\" data-orig-size=\"706,429\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"animation-direction\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-direction-300x182.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-direction.gif\" loading=\"lazy\" width=\"706\" height=\"429\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-direction.gif\" alt=\"\" class=\"wp-image-4959\"\/><\/figure>\n\n\n\n<p>CSS syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation-direction: alternate;<\/code><\/pre>\n\n\n\n<p>Animation shorthand syntax (recommended):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation: [animation-name] [animation-duration] [animation-timing-function]\n[animation-delay] [animation-iteration-count] [animation-direction];\nanimation:  bounceIn 2s ease-in-out 3s 3 alternate;<\/code><\/pre>\n\n\n\n<h2 id=\"animation-fill-mode\">Animation-fill-mode<\/h2>\n\n\n\n<p>The&nbsp;<code>animation-fill-mode:<\/code>&nbsp;specifies if the animation styles are visible before or after the animation plays. This property is a little confusing, but once understood it is very useful.<\/p>\n\n\n\n<p>By default, the animation will not effect the styles of the element before the animation begins (if there is an animation-delay) or after the animation is finished. The&nbsp;<code>animation-fill-mode<\/code>&nbsp;property can override this behavior with the following possible values:<\/p>\n\n\n\n<p><code>backwards<\/code>&nbsp;&#8211; Before the animation (during the animation delay), the styles of the initial keyframe (0%) are applied to the element.<\/p>\n\n\n\n<p><code>forwards<\/code>&nbsp;&#8211; After the animation is finished, the styles defined in the final keyframe (100%) are retained by the element.<\/p>\n\n\n\n<p><code>both<\/code>&nbsp;&#8211; The animation will follow the rules for both forwards and backwards, extending the animation properties before and after the animation.<\/p>\n\n\n\n<p><code>normal<\/code>&nbsp;(default) &#8211; The animation does not apply any styles to the element, before or after the animation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4960\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/attachment\/animation-fill\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-fill.gif\" data-orig-size=\"785,462\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"animation-fill\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-fill-300x177.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-fill.gif\" loading=\"lazy\" width=\"785\" height=\"462\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-fill.gif\" alt=\"\" class=\"wp-image-4960\"\/><\/figure>\n\n\n\n<p>CSS syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation-fill-mode: forwards;<\/code><\/pre>\n\n\n\n<p>Animation shorthand syntax (recommended):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>animation: [animation-name] [animation-duration] [animation-timing-function]\n[animation-delay] [animation-iteration-count] [animation-direction]\n[animation-fill-mode];\nanimation:  bounceIn 2s ease-in-out 3s 3 forwards;<\/code><\/pre>\n\n\n\n<h2 id=\"animation-play-state\">Animation-play-state<\/h2>\n\n\n\n<p>The&nbsp;<code>animation-play-state:<\/code>&nbsp;specifies whether the animation is playing or paused. Resuming a paused animation starts the animation where it was left off.<\/p>\n\n\n\n<p>The possible values are:<\/p>\n\n\n\n<p><code>playing<\/code>&nbsp;&#8211; The animation is currently running<\/p>\n\n\n\n<p><code>paused<\/code>&nbsp;&#8211; The animation is currently paused<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-attachment-id=\"4961\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/css-animation-for-beginners\/attachment\/animation-play\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-play.gif\" data-orig-size=\"499,462\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"animation-play\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-play-300x278.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-play.gif\" loading=\"lazy\" width=\"499\" height=\"462\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/animation-play.gif\" alt=\"\" class=\"wp-image-4961\"\/><\/figure>\n\n\n\n<p>Example :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.div:hover {\n  animation-play-state: paused;\n}<\/code><\/pre>\n\n\n\n<h2 id=\"multiple-animations\">Multiple Animations<\/h2>\n\n\n\n<p>To add multiple animations to a selector, you simply separate the values with a comma. Here\u2019s an example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.div {\n  animation: slideIn 2s, rotate 1.75s;\n}<\/code><\/pre>\n\n\n\n<h2 id=\"go-forth-and-animate\">Go Forth and Animate<\/h2>\n\n\n\n<p>That\u2019s it! With those basic properties, the possible animations you can create are endless. The best way learn is to jump in and start animating.<\/p>\n\n\n\n<p>Here are a couple of resources to get you started:<\/p>\n\n\n\n<p><strong><a href=\"https:\/\/thoughtbot.com\/upcase\/design\">Upcase for Designers<\/a><\/strong>&nbsp;\u2013 an online learning community with courses on front-end design and development techniques.<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/codepen.io\/\">CodePen<\/a><\/strong>&nbsp;&#8211; a CSS playground where you can edit your code and immediately see your results.<\/p>\n\n\n\n<p><strong><a href=\"http:\/\/daneden.github.io\/animate.css\/\">Animate.css<\/a><\/strong>&nbsp;&#8211; a library with dozens of fun animations to get you started and use on your projects.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The human brain is hardwired to pay attention to moving objects. Because of this natural reflex to notice movement, adding animation to your website or app is a powerful way to draw user&#8217;s attention to important areas of your product and add interest to your interface. When done well, animations can add valuable interaction and [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":4962,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[4,145,77,62],"tags":[93,25,56,94,146,136,116,73,110],"jetpack_featured_media_url":"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/08\/CSS-Animations.png","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p7FQPL-1hU","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/4954"}],"collection":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/comments?post=4954"}],"version-history":[{"count":2,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/4954\/revisions"}],"predecessor-version":[{"id":5849,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/4954\/revisions\/5849"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media\/4962"}],"wp:attachment":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media?parent=4954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/categories?post=4954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/tags?post=4954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}