css animation w3schools code example

Example 1: css animation

<style>
.my-element {
  width: 100%;
  height: 100%;
  animation: tween-color 5s infinite;
}

@keyframes tween-color {
  0% {
    background-color: red;
  }
  50% {
    background-color: green;
  }
  100% {
    background-color: red;
  }
}

html,
body {
  height: 100%;
}
<style>

<body>
	<div class="my-element"></div>
</body>

Example 2: css animation

# css animaition .................... infinite dont stop

  animation-name: example;
  animation-duration: 1s;
  animation-iteration-count: infinite;

@keyframes example {
  0%{transform: rotate(0deg)}
  50% {transform: rotate(5deg)}
  75%{transform: rotate(0deg)}
  100% {transform: rotate(50deg)}
}

Example 3: css animation

CSS animation properties template:
{
   animation-name: anima-name;
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-delay: 2s;
    animation-direction: reverse | normal | alternate | alternate-reverse ; 
  animation-timing-function: ease | ease-out | ease-in | ease-in-out | linear | cubic-bezier(x1, y1, x2, y2) (e.g. cubic-bezier(0.5, 0.2, 0.3, 1.0)); 
  animation-fill-mode:forwards | backwards | both | none;
}
@keyframes anima-name {
  from {
   background-position:right;
  }
  to {
    background-position:left;
  }
}
@keyframes anima-name {
  0% {
    background-color: red;
  }
  50% {
    background-color: green;
  }
  100% {
    background-color: red;
  }
}

Example 4: css animation

<!DOCTYPE html>
<html lang="en">
   <head>
      <title>CSS Animation</title>

      <style>
         .element {
            height: 250px;
            width: 250px;
            margin: 0 auto;
            background-color: red;
            animation-name: stretch;
            animation-duration: 1.5s;
            animation-timing-function: ease-out;
            animation-delay: 0;
            animation-direction: alternate;
            animation-iteration-count: infinite;
            animation-fill-mode: none;
            animation-play-state: running;
         }

         @keyframes stretch {
            0% {
               transform: scale(0.3);
               background-color: red;
               border-radius: 100%;
            }
            50% {
               background-color: orange;
            }
            100% {
               transform: scale(1.5);
               background-color: yellow;
            }
         }

         body,
         html {
            height: 100%;
         }

         body {
            display: flex;
            align-items: center;
            justify-content: center;
         }
      </style>
   </head>
   <body>
      <div class="element"></div>
   </body>
</html>

Example 5: Css animations

Here a codePen with cool animations:
https://codepen.io/DevLorenzo/pen/ExgpvJM

Example 6: what is the animation property in html and css

with the help of animation properties in CSS we can control 
how the animation will be played throughout.

The animation properties in CSS are -
1) animation-duration : implies the time taken by the animation to finish.Forexample- animation-duration: 6s;  
2) animation-direction : implies the direction of the animation.Forexample- the direction in which the horse rides , the car moves , the insects crawls.
3) animation-delay: implies the time after which is the animation starts.Forexample- animation-delay: 3s; means after 3seconds the animation will start.
4) animation-iteration-count: implies how many times the animation will repeat.
5) animation-timing-function: the values can be ease,ease-in, ease-out, linear, ease-in-out.
6) animation-play-state: the values can be paused, running, initial, inherit.
7) animation-name: implies the name of the animation which is assigned by us.
8) animation-fill-mode: it specifies a style for the element when the animation is not playing.The values can be none,forwards, backwards, both, initial and inherit.
9) @keyframes: this is the most important.It specifies the different values of style in different intervals of time.The animation-name is used in @keyframes declaration.

NOTE: the syntax of every single letter, numbers, punctuation mark is very important.

Tags:

Html Example