ใช้คุณสมบัติ animation-duration เพื่อกำหนดว่าแอนิเมชันควรใช้เวลานานเท่าไรในการทำหนึ่งรอบ (cycle)
ตัวอย่างโค้ด
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 150px;
height: 200px;
position: relative;
background: red;
animation-name: myanim;
animation-duration: 2s;
}
@keyframes myanim {
from { left: 0px; background-color: green; }
to { left: 200px; background-color: blue; }
}
</style>
</head>
<body>
<div></div>
</body>
</html>
หมายเหตุ: บทความนี้มีเนื้อหาเหมือน ID 1004062760 (ซ้ำ) animation-duration: 2s ทำให้แอนิเมชันจาก from ไป to ใช้เวลา 2 วินาที ต้องมี animation-name อ้างอิง @keyframes