CSS animations

animation

2025-06-04

Written by: tdtc

Properties

/* @keyframes duration | easing-function | delay |
iteration-count | direction | fill-mode | play-state | name */
animation: 3s ease-in 1s 2 reverse both paused slide-in;

basic

/* @keyframes duration | easing-function | delay | name */
animation: 3s linear 1s slide-in;

for example:

animation: myanimation 20s linear infinite;

transform function

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>KeyFrames</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
  	<div class="marquee">
		<p>Hello CSS</p>
	</div>

  </body>

</html>

Translation (moving)

CSS Keyframes

Keyframe using percentages

        @keyframes scroll-left {
            0% {
                transform: translateX(100%);
            }
            100% {
                transform: translateX(-100%);
            }
        }

Keyframe using from-to keywords

@keyframes my-scroll {
  from {
    transform: translateX(0%);
  }

  to {
    transform: translateX(100%);
  }
}
.marquee {
	height: 50px;
	overflow: hidden;
	position: relative;
	background: #fefefe;
	color: #333;
	border: 1px solid #4a4a4a;
}

.marquee p {
/* animation properties */
animation-name: my-scroll;
animation-duration: 5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
	position: absolute;
	width: 100%;
	height: 100%;
	margin: 0;
	line-height: 50px;
	text-align: center;
}

@keyframes my-scroll {
  from {
    transform: translateX(0%);
  }

  to {
    transform: translateX(100%);
  }
}

Ref