opacity - HTML CSS CSS Animatable Property

HTML CSS examples for CSS Animatable Property:opacity

Introduction

In the following code the opacity (i.e. transparency) of the blue DIV box is animating from its initial value "0" to "1", and back to the initial value "0" again up to infinite times.

-webkit- prefix is for Chrome, Safari, Opera.

-moz- prefix is for Firefox.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS3 opacity Property Animation</title>
  <style type="text/css">
.container{<!-- w ww. jav a2  s  .c om-->
  width: 300px;
  height: 200px;
  position: relative;
  background: #db75d6;
  border: 5px solid #a0299a;
}
.animated {
    opacity: 0;
  width: 200px;
  padding: 75px 0;
  margin: 50px;
  font: bold 50px sans-serif;
  background: #6f5ece;
  outline: 5px solid #4936b4;
  text-align: center;
    -webkit-animation: test 4s infinite; 
    animation: test 4s infinite;
}

@-webkit-keyframes test {
    50% {opacity: 1;}
}

@keyframes test {
    50% {opacity: 1;}
}
</style>
 </head>
 <body>

  <p> </p>
  <div class="container">
   <div class="animated">
    Box
   </div>
  </div>
 </body>
</html>

Related Tutorials