w3resource
HTML exercises

CSS Properties: How to play the animation two times?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>How to play the animation two times</title>
</head>
<body>
<div class="animation">
<div class="w3r">
w3resource Tutorial
</div>
</div>
<style type="text/css">
.w3r {
color: white;
float: left;
margin-right: 2%;
font-size: 20px
}
.animation {
background-color: #CC3333;
height: 50px;
width: 100%;
overflow: hidden;
}
div {
width: 100px;
height: 100px;
background: #33FFFF;
position: relative;
-webkit-animation: move 5s infinite; /* Chrome, Safari, Opera */
-webkit-animation-iteration-count: 5s; /* Chrome, Safari, Opera */
animation: move 5s infinite;
animation-iteration-count: 2;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes move {
    from {top: 0px;}
    to {top: 200px;}
}

@keyframes move {
    from {top: 0px;}
    to {top: 200px;}
}
</style>
</body>
</html>

Live Demo:

See the Pen animation-iteration-count-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes No

Go to Exercise page

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming